rippled
Loading...
Searching...
No Matches
xrpld
rpc
handlers
Ping.cpp
1
//------------------------------------------------------------------------------
2
/*
3
This file is part of rippled: https://github.com/ripple/rippled
4
Copyright (c) 2012-2014 Ripple Labs Inc.
5
6
Permission to use, copy, modify, and/or distribute this software for any
7
purpose with or without fee is hereby granted, provided that the above
8
copyright notice and this permission notice appear in all copies.
9
10
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
//==============================================================================
19
20
#include <xrpld/rpc/Context.h>
21
#include <xrpld/rpc/Role.h>
22
23
#include <xrpl/json/json_value.h>
24
#include <xrpl/protocol/jss.h>
25
26
namespace
ripple
{
27
28
namespace
RPC {
29
struct
JsonContext;
30
}
// namespace RPC
31
32
Json::Value
33
doPing
(
RPC::JsonContext
& context)
34
{
35
Json::Value
ret(
Json::objectValue
);
36
switch
(context.
role
)
37
{
38
case
Role::ADMIN
:
39
ret[jss::role] =
"admin"
;
40
break
;
41
case
Role::IDENTIFIED
:
42
ret[jss::role] =
"identified"
;
43
ret[jss::username] =
std::string
{context.
headers
.
user
};
44
if
(context.
headers
.
forwardedFor
.
size
())
45
ret[jss::ip] =
std::string
{context.
headers
.
forwardedFor
};
46
break
;
47
case
Role::PROXY
:
48
ret[jss::role] =
"proxied"
;
49
ret[jss::ip] =
std::string
{context.
headers
.
forwardedFor
};
50
default
:;
51
}
52
53
// This is only accessible on ws sessions.
54
if
(context.
infoSub
)
55
{
56
if
(context.
infoSub
->
getConsumer
().
isUnlimited
())
57
ret[jss::unlimited] =
true
;
58
}
59
60
return
ret;
61
}
62
63
}
// namespace ripple
std::string
Json::Value
Represents a JSON value.
Definition
json_value.h:149
ripple::InfoSub::getConsumer
Consumer & getConsumer()
Definition
InfoSub.cpp:68
ripple::Resource::Consumer::isUnlimited
bool isUnlimited() const
Returns true if this is a privileged endpoint.
Definition
Consumer.cpp:87
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition
json_value.h:45
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:25
ripple::doPing
Json::Value doPing(RPC::JsonContext &)
Definition
Ping.cpp:33
ripple::Role::IDENTIFIED
@ IDENTIFIED
ripple::Role::ADMIN
@ ADMIN
ripple::Role::PROXY
@ PROXY
std::string_view::size
T size(T... args)
ripple::RPC::Context::role
Role role
Definition
Context.h:46
ripple::RPC::Context::infoSub
InfoSub::pointer infoSub
Definition
Context.h:48
ripple::RPC::JsonContext::Headers::forwardedFor
std::string_view forwardedFor
Definition
Context.h:60
ripple::RPC::JsonContext::Headers::user
std::string_view user
Definition
Context.h:59
ripple::RPC::JsonContext
Definition
Context.h:53
ripple::RPC::JsonContext::headers
Headers headers
Definition
Context.h:65
Generated by
1.9.8