xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
handlers
utility
Ping.cpp
1
#include <xrpld/rpc/Context.h>
2
#include <xrpld/rpc/Role.h>
3
4
#include <xrpl/json/json_value.h>
5
#include <xrpl/protocol/jss.h>
6
7
namespace
xrpl
{
8
9
namespace
rpc
{
10
struct
JsonContext
;
11
}
// namespace rpc
12
13
json::Value
14
doPing
(
rpc::JsonContext
& context)
15
{
16
json::Value
ret(
json::ValueType::Object
);
17
switch
(context.
role
)
18
{
19
case
Role::ADMIN
:
20
ret[jss::role] =
"admin"
;
21
break
;
22
case
Role::IDENTIFIED
:
23
ret[jss::role] =
"identified"
;
24
ret[jss::username] =
std::string
{context.
headers
.
user
};
25
if
(!context.
headers
.
forwardedFor
.
empty
())
26
ret[jss::ip] =
std::string
{context.
headers
.
forwardedFor
};
27
break
;
28
case
Role::PROXY
:
29
ret[jss::role] =
"proxied"
;
30
if
(!context.
headers
.
forwardedFor
.
empty
())
31
ret[jss::ip] =
std::string
{context.
headers
.
forwardedFor
};
32
break
;
33
default
:;
34
}
35
36
// This is only accessible on ws sessions.
37
if
(context.
infoSub
)
38
{
39
if
(context.
infoSub
->
getConsumer
().
isUnlimited
())
40
ret[jss::unlimited] =
true
;
41
}
42
43
return
ret;
44
}
45
46
}
// namespace xrpl
std::string
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::InfoSub::getConsumer
Consumer & getConsumer()
Definition
libxrpl/server/InfoSub.cpp:160
xrpl::resource::Consumer::isUnlimited
bool isUnlimited() const
Returns true if this is a privileged endpoint.
Definition
Consumer.cpp:70
std::string_view::empty
T empty(T... args)
json::ValueType::Object
@ Object
object value (collection of name/value pairs).
Definition
json_value.h:29
xrpl::rpc
API version numbers used in later API versions.
Definition
ApiVersion.h:36
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::Role::IDENTIFIED
@ IDENTIFIED
Definition
Role.h:27
xrpl::Role::ADMIN
@ ADMIN
Definition
Role.h:27
xrpl::Role::PROXY
@ PROXY
Definition
Role.h:27
xrpl::doPing
json::Value doPing(rpc::JsonContext &)
Definition
Ping.cpp:14
xrpl::rpc::Context::infoSub
InfoSub::pointer infoSub
Definition
Context.h:36
xrpl::rpc::Context::role
Role role
Definition
Context.h:34
xrpl::rpc::JsonContext::Headers::forwardedFor
std::string_view forwardedFor
Definition
Context.h:48
xrpl::rpc::JsonContext::Headers::user
std::string_view user
Definition
Context.h:47
xrpl::rpc::JsonContext
Definition
Context.h:41
xrpl::rpc::JsonContext::headers
Headers headers
Definition
Context.h:53
Generated by
1.17.0