rippled
Loading...
Searching...
No Matches
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
26namespace ripple {
27
28namespace RPC {
29struct JsonContext;
30} // namespace RPC
31
34{
36 switch (context.role)
37 {
38 case Role::ADMIN:
39 ret[jss::role] = "admin";
40 break;
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
Represents a JSON value.
Definition: json_value.h:148
Consumer & getConsumer()
Definition: InfoSub.cpp:68
bool isUnlimited() const
Returns true if this is a privileged endpoint.
Definition: Consumer.cpp:87
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:44
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
Json::Value doPing(RPC::JsonContext &)
Definition: Ping.cpp:33
T size(T... args)
InfoSub::pointer infoSub
Definition: Context.h:48
std::string_view forwardedFor
Definition: Context.h:60