softwarecontainer  0.18.0-739e8d7 2017-05-04
softwarecontainer::NetworkGatewayParser Class Reference

Public Member Functions

bool parseNetworkGatewayConfiguration (const json_t *element, IPTableEntry &e)
 Parses NetworkGateway configuration into IPTableEntry. More...
 

Detailed Description

Definition at line 28 of file networkgatewayparser.h.

Member Function Documentation

bool softwarecontainer::NetworkGatewayParser::parseNetworkGatewayConfiguration ( const json_t *  element,
IPTableEntry e 
)

Parses NetworkGateway configuration into IPTableEntry.

Parameters
elementJSON string containing configuration
erule representing corresponding network rules
Returns
true if the rule is successfully parsed
false otherwise.

Definition at line 23 of file networkgatewayparser.cpp.

References softwarecontainer::JSONParser::read().

Referenced by softwarecontainer::NetworkGateway::readConfigElement().

25 {
26  std::string chain;
27  if (!JSONParser::read(element, "direction", chain)) {
28  log_error() << "No type specified in network config.";
29  return false;
30  }
31 
32  e.m_defaultTarget = IPTableEntry::Target::DROP;
33 
34  if ("INCOMING" == chain) {
35  e.m_type = "INPUT";
36  } else if ("OUTGOING" == chain) {
37  e.m_type = "OUTPUT";
38  } else {
39  log_error() << e.m_type << " is not a valid type ('INCOMING' or 'OUTGOING')";
40  return false;
41  }
42 
43  const json_t *rules = json_object_get(element, "allow");
44 
45  if (rules == nullptr) {
46  log_error() << "No rules specified";
47  return false;
48  }
49 
50  if (!json_is_array(rules)) {
51  log_error() << "Rules not specified as an array";
52  return false;
53  }
54 
55  size_t ix;
56  json_t *val;
57  json_array_foreach(rules, ix, val) {
58  if (json_is_object(val)) {
59  if (!parseRule(val, e.m_rules)) {
60  log_error() << "Could not parse rule config";
61  return false;
62  }
63  } else {
64  log_error() << "formatting of rules array is incorrect.";
65  return false;
66  }
67  }
68 
69  return true;
70 }
static bool read(const json_t *element, const char *key, std::string &result)
Reads a string from a JSON Object.
Definition: jsonparser.cpp:51

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: