rippled
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 <ripple/json/json_value.h>
21 #include <ripple/protocol/jss.h>
22 #include <ripple/rpc/Context.h>
23 #include <ripple/rpc/Role.h>
24 
25 namespace ripple {
26 
27 namespace RPC {
28 struct JsonContext;
29 } // namespace RPC
30 
33 {
35  switch (context.role)
36  {
37  case Role::ADMIN:
38  ret[jss::role] = "admin";
39  break;
40  case Role::IDENTIFIED:
41  ret[jss::role] = "identified";
42  ret[jss::username] = context.headers.user.to_string();
43  if (context.headers.forwardedFor.size())
44  ret[jss::ip] = context.headers.forwardedFor.to_string();
45  break;
46  case Role::PROXY:
47  ret[jss::role] = "proxied";
48  ret[jss::ip] = context.headers.forwardedFor.to_string();
49  default:;
50  }
51 
52  // This is only accessible on ws sessions.
53  if (context.infoSub)
54  {
55  if (context.infoSub->getConsumer().isUnlimited())
56  ret[jss::unlimited] = true;
57  }
58 
59  return ret;
60 }
61 
62 } // namespace ripple
ripple::RPC::Context::infoSub
InfoSub::pointer infoSub
Definition: Context.h:49
ripple::RPC::JsonContext
Definition: Context.h:53
ripple::RPC::JsonContext::Headers::user
boost::string_view user
Definition: Context.h:60
ripple::Role::IDENTIFIED
@ IDENTIFIED
ripple::RPC::Context::role
Role role
Definition: Context.h:47
ripple::RPC::JsonContext::headers
Headers headers
Definition: Context.h:66
ripple::Role::ADMIN
@ ADMIN
Json::objectValue
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:43
ripple::doPing
Json::Value doPing(RPC::JsonContext &)
Definition: Ping.cpp:32
ripple::Role::PROXY
@ PROXY
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::Resource::Consumer::isUnlimited
bool isUnlimited() const
Returns true if this is a privileged endpoint.
Definition: Consumer.cpp:80
ripple::RPC::JsonContext::Headers::forwardedFor
boost::string_view forwardedFor
Definition: Context.h:61
ripple::InfoSub::getConsumer
Consumer & getConsumer()
Definition: InfoSub.cpp:69
Json::Value
Represents a JSON value.
Definition: json_value.h:145