fix8  version 1.4.0
Open Source C++ FIX Framework
FIX8::Configuration Class Reference

Class to encapsulate a Fix8 configuration. More...

#include <configuration.hpp>

Inheritance diagram for FIX8::Configuration:
FIX8::SessionConfig FIX8::ClientSessionBase FIX8::ServerSessionBase FIX8::ClientSession< T > FIX8::ServerSession< T > FIX8::ReliableClientSession< T >

Public Types

enum  group_types {
  g_sessions, g_persisters, g_loggers, g_server_group,
  g_ssl_context, g_schedules, g_logins, g_client_group,
  g_count
}
 
enum  Logtype { session_log, protocol_log }
 

Public Member Functions

const XmlElementfind_group (group_types type, const std::string &tag) const
 
 Configuration (const std::string &xmlfile, bool do_process=false)
 
 Configuration (std::istream &istr, bool do_process=false)
 
virtual ~Configuration ()
 Dtor. More...
 
F8API int process ()
 
const XmlElementget_session (const unsigned num) const
 
F8API Connection::Role get_role (const XmlElement *from) const
 
F8API size_t get_addresses (const XmlElement *from, std::vector< Server > &target) const
 
F8API Poco::Net::SocketAddress get_address (const XmlElement *from) const
 
F8API Poco::Net::IPAddress get_ip (const XmlElement *from) const
 
template<typename T >
get_logflags (const std::string &tag, const std::vector< std::string > &names, const XmlElement *from, Logger::LogPositions *positions=nullptr) const
 
F8API std::string & get_logname (const XmlElement *from, std::string &to, const SessionID *sid=nullptr) const
 
unsigned get_connect_timeout (const XmlElement *from, const unsigned def=defaults::connect_timeout) const
 
unsigned get_retry_interval (const XmlElement *from, const unsigned def=defaults::retry_interval) const
 
unsigned get_retry_count (const XmlElement *from, const int def=defaults::login_retries) const
 
unsigned get_tcp_recvbuf_sz (const XmlElement *from, const unsigned def=0) const
 
unsigned get_tcp_sendbuf_sz (const XmlElement *from, const unsigned def=0) const
 
unsigned get_version (const XmlElement *from, const unsigned def=0) const
 
unsigned get_tabsize (const XmlElement *from, const unsigned def=defaults::tabsize) const
 
unsigned get_logfile_rotation (const XmlElement *from, const unsigned def=defaults::log_rotation) const
 
unsigned get_heartbeat_interval (const XmlElement *from, const unsigned def=defaults::hb_interval) const
 
bool get_tcp_nodelay (const XmlElement *from, const bool def=true) const
 
bool get_tcp_keepalive (const XmlElement *from, const bool def=false) const
 
bool get_tcp_reuseaddr (const XmlElement *from, const bool def=false) const
 
int get_tcp_linger (const XmlElement *from, const int def=-1) const
 
bool get_silent_disconnect (const XmlElement *from, const bool def=false) const
 
bool get_enforce_compids_flag (const XmlElement *from, const bool def=true) const
 
bool get_ignore_logon_sequence_check_flag (const XmlElement *from, const bool def=false) const
 
bool get_no_chksum_flag (const XmlElement *from, const bool def=false) const
 
bool get_permissive_mode_flag (const XmlElement *from, const bool def=false) const
 
bool get_reset_sequence_number_flag (const XmlElement *from, const bool def=false) const
 
bool get_always_seqnum_assign (const XmlElement *from, const bool def=false) const
 
F8API ProcessModel get_process_model (const XmlElement *from) const
 
default_appl_ver_id get_default_appl_ver_id (const XmlElement *from) const
 
sender_comp_id get_sender_comp_id (const XmlElement *from) const
 
target_comp_id get_target_comp_id (const XmlElement *from) const
 
F8API Persistercreate_persister (const XmlElement *from, const SessionID *sid=nullptr, bool flag=false) const
 
F8API Loggercreate_logger (const XmlElement *from, const Logtype ltype, const SessionID *sid=nullptr) const
 
F8API Schedule create_schedule (const XmlElement *from) const
 
F8API Clients create_clients (const XmlElement *from) const
 
F8API Schedule create_login_schedule (const XmlElement *from) const
 
F8API Session_Schedulecreate_session_schedule (const XmlElement *from) const
 
F8API unsigned get_all_sessions (std::vector< const XmlElement * > &target, const Connection::Role role=Connection::cn_unknown) const
 
const XmlElementget_root () const
 
template<typename T >
get_logflags (const string &tag, const vector< string > &names, const XmlElement *from, Logger::LogPositions *positions) const
 

Protected Member Functions

bool from_or_default (const XmlElement *from, const f8String &tag, f8String &target) const
 
template<typename T >
T & get_string_field (const XmlElement *from, const std::string &tag, T &to) const
 
Tickval::ticks get_time_field (const XmlElement *from, const std::string &tag, bool timeonly=false) const
 
template<typename T >
find_or_default (const XmlElement *from, const std::string &tag, const T def) const
 

Private Types

using ConfigMap = std::map< const std::string, const XmlElement * >
 

Private Member Functions

const XmlElementfind_element (const std::string &tag, const ConfigMap &from) const
 
unsigned load_map (const std::string &tag, ConfigMap &map_name, const bool is_session=false)
 

Private Attributes

const XmlElement_root
 
const XmlElement_default
 
std::vector< ConfigMap_groups
 
std::vector< const XmlElement * > _allsessions
 

Static Private Attributes

static RegExp _ipexp
 

Detailed Description

Class to encapsulate a Fix8 configuration.

Definition at line 92 of file configuration.hpp.

Member Typedef Documentation

using FIX8::Configuration::ConfigMap = std::map<const std::string, const XmlElement *>
private

Definition at line 97 of file configuration.hpp.

Member Enumeration Documentation

Constructor & Destructor Documentation

FIX8::Configuration::Configuration ( const std::string &  xmlfile,
bool  do_process = false 
)
inline

Ctor.

Parameters
xmlfilexml config filename.
do_processif true, process the file on construction

Definition at line 210 of file configuration.hpp.

References FIX8::exist(), and process().

211  : _root(XmlElement::Factory(xmlfile)),
212  _default(_root ? _root->find("fix8/default") : nullptr),
214  {
215  if (!exist(xmlfile))
216  throw ConfigurationError("config file not found", xmlfile);
217  if (do_process)
218  process();
219  }
const XmlElement * _default
static F8API XmlElement * Factory(std::istream &istr, const char *docpath=nullptr)
const XmlElement * _root
std::vector< ConfigMap > _groups
bool exist(const std::string &fname)
Definition: f8utils.hpp:1068
F8API const XmlElement * find(const std::string &what, const std::string *atag=nullptr, const std::string *aval=nullptr, const char delim='/') const
FIX8::Configuration::Configuration ( std::istream &  istr,
bool  do_process = false 
)
inline

Ctor.

Parameters
istrxml stream
do_processif true, process the stream on construction

Definition at line 224 of file configuration.hpp.

References process().

225  : _root(XmlElement::Factory(istr, "stream")),
226  _default(_root ? _root->find("fix8/default") : nullptr),
228  {
229  if (do_process)
230  process();
231  }
const XmlElement * _default
static F8API XmlElement * Factory(std::istream &istr, const char *docpath=nullptr)
const XmlElement * _root
std::vector< ConfigMap > _groups
F8API const XmlElement * find(const std::string &what, const std::string *atag=nullptr, const std::string *aval=nullptr, const char delim='/') const
virtual FIX8::Configuration::~Configuration ( )
inlinevirtual

Dtor.

Definition at line 234 of file configuration.hpp.

234 {}

Member Function Documentation

Clients Configuration::create_clients ( const XmlElement from) const

Create clients object from a session entity.

Parameters
fromxml entity to search
Returns
Clients

Definition at line 313 of file configuration.cpp.

References XmlElement::find(), and find_group().

Referenced by FIX8::SessionConfig::SessionConfig().

314 {
315  string name;
316  const XmlElement *which;
317  Clients clients;
318  if (from_or_default(from, "target_comp_id", name) && (which = find_group(g_client_group, name)))
319  {
320  XmlElement::XmlSet slist;
321  if (which->find("client_group/client", slist))
322  {
323  // <client name="Goldsteins" target_comp_id="DLD_TEX" ip="192.168.0.17" active="true" />
324  for(const auto *pp : slist)
325  {
326  string name, tci;
327  const Poco::Net::IPAddress addr(get_ip(pp));
328  if (pp->GetAttr("name", name) && pp->GetAttr("target_comp_id", tci) && pp->FindAttr("active", true))
329  if (!clients.insert({tci, Client(name, addr)}).second)
330  throw ConfigurationError("Failed to add client from client_group", tci);
331  }
332  }
333  }
334 
335  return clients;
336 }
std::unordered_map< f8String, Client > Clients
Definition: session.hpp:182
A simple xml parser with Xpath style lookup.
Definition: xml.hpp:48
An bad or missing configuration parameter.
std::set< const XmlElement *, EntityOrderComp > XmlSet
Definition: xml.hpp:74
F8API Poco::Net::IPAddress get_ip(const XmlElement *from) const
F8API const XmlElement * find(const std::string &what, const std::string *atag=nullptr, const std::string *aval=nullptr, const char delim='/') const
const XmlElement * find_group(group_types type, const std::string &tag) const
bool from_or_default(const XmlElement *from, const f8String &tag, f8String &target) const
Logger * Configuration::create_logger ( const XmlElement from,
const Logtype  ltype,
const SessionID sid = nullptr 
) const

Create a new logger object from a session entity.

Parameters
fromxml entity to search
ltypelog type
sidoptional session id to build name from
Returns
new logger or 0 if unable to create

Definition at line 256 of file configuration.cpp.

References FIX8::Logger::_bit_names, FIX8::Logger::_level_names, FIX8::Logger::All, find_group(), XmlElement::FindAttrRef(), XmlElement::GetAttr(), XmlElement::HasAttr(), FIX8::Logger::None, FIX8::Logger::StdFlags, FIX8::trim(), and FIX8::Logger::xml.

Referenced by FIX8::Session::handle_logon().

257 {
258  string name;
259  if (from_or_default(from, ltype == session_log ? "session_log" : "protocol_log", name))
260  {
261  const XmlElement *which(find_group(g_loggers, name));
262  if (which)
263  {
264  Logger::LogPositions positions;
265  string type;
266 
267  if (which->GetAttr("type", type)
268  && ((type % "session" && ltype == session_log) || (type % "protocol" && ltype == protocol_log)))
269  {
270  string logname("logname_not_set.log"), levstr, delim(" ");
271  which->FindAttrRef("filename", logname);
272  trim(logname);
273  if (which->GetAttr("delimiter", delim) && delim.size() > 2) // "|" or "<>" or "{}" etc
274  throw ConfigurationError("invalid logging field delimiter");
275 
276  which->GetAttr("levels", levstr);
277  const Logger::Levels levels(levstr.empty() || levstr % "All"
278  ? Logger::Levels(Logger::All) : levstr % "None"
279  ? Logger::Levels(Logger::None) : get_logflags<Logger::Levels>("levels", Logger::_level_names, which));
280 
281  const Logger::LogFlags flags(which->HasAttr("flags")
282  ? get_logflags<Logger::LogFlags>("flags", Logger::_bit_names, which, &positions) : Logger::LogFlags(Logger::StdFlags));
283 
284  if (logname[0] == '|')
285  {
286 #ifndef FIX8_HAVE_POPEN
287  throw ConfigurationError("popen not supported on your platform");
288 #endif
289  return new PipeLogger(logname, flags, levels, delim, positions);
290  }
291 
292  RegMatch match;
293  if (_ipexp.SearchString(match, logname, 3) == 3)
294  {
295  f8String ip, port;
296  _ipexp.SubExpr(match, logname, ip, 0, 1);
297  _ipexp.SubExpr(match, logname, port, 0, 2);
298  return new BCLogger(ip, stoul(port), flags, levels, delim, positions);
299  }
300 
301  get_logname(which, logname, sid); // only applies to file loggers
302  if (flags & Logger::xml)
303  return new XmlFileLogger(logname, flags, levels, delim, positions, get_logfile_rotation(which));
304  return new FileLogger(logname, flags, levels, delim, positions, get_logfile_rotation(which));
305  }
306  }
307  }
308 
309  return nullptr;
310 }
f8_thread delegated async logging class
Definition: logger.hpp:153
static const int StdFlags
Definition: logger.hpp:169
static std::string & SubExpr(RegMatch &match, const std::string &source, std::string &target, const int offset=0, const int num=0)
Definition: f8utils.hpp:452
F8API std::string & get_logname(const XmlElement *from, std::string &to, const SessionID *sid=nullptr) const
static const int All
Definition: logger.hpp:161
std::string trim(const std::string &source, const std::string &ws=" \t")
Definition: f8utils.hpp:153
ebitset< Level > Levels
Definition: logger.hpp:175
static const std::vector< std::string > _bit_names
string representation of logflags
Definition: logger.hpp:326
A file logger.
Definition: logger.hpp:385
std::vector< int > LogPositions
Definition: logger.hpp:176
A simple xml parser with Xpath style lookup.
Definition: xml.hpp:48
An bad or missing configuration parameter.
A broadcast logger.
Definition: logger.hpp:436
int SearchString(RegMatch &match, const std::string &source, const int subExpr, const int offset=0) const
Definition: f8utils.hpp:431
A file logger.
Definition: logger.hpp:357
T get_logflags(const std::string &tag, const std::vector< std::string > &names, const XmlElement *from, Logger::LogPositions *positions=nullptr) const
unsigned get_logfile_rotation(const XmlElement *from, const unsigned def=defaults::log_rotation) const
A class to contain regex matches using RegExp.
Definition: f8utils.hpp:308
A pipe logger.
Definition: logger.hpp:418
static RegExp _ipexp
std::string f8String
Definition: f8types.hpp:47
const XmlElement * find_group(group_types type, const std::string &tag) const
bool from_or_default(const XmlElement *from, const f8String &tag, f8String &target) const
Schedule Configuration::create_login_schedule ( const XmlElement from) const

Create login schedule object from a session entity.

Parameters
fromxml entity to search
Returns
login Schedule

Definition at line 177 of file configuration.cpp.

References find_group().

Referenced by FIX8::SessionConfig::SessionConfig().

178 {
179  string name;
180  const XmlElement *which;
181  return from_or_default(from, "login", name) && (which = find_group(g_logins, name))
182  ? create_schedule(which) : Schedule();
183 }
F8API Schedule create_schedule(const XmlElement *from) const
A simple xml parser with Xpath style lookup.
Definition: xml.hpp:48
const XmlElement * find_group(group_types type, const std::string &tag) const
bool from_or_default(const XmlElement *from, const f8String &tag, f8String &target) const
Persister * Configuration::create_persister ( const XmlElement from,
const SessionID sid = nullptr,
bool  flag = false 
) const

Create a new persister object from a session entity.

Parameters
fromxml entity to search
sidoptional session id to build name from
flagadditional flag for persister use
Returns
new persister or 0 if unable to create

Definition at line 186 of file configuration.cpp.

References FIX8::defaults::connect_timeout, find_group(), XmlElement::FindAttr(), FIX8::SessionID::get_senderCompID(), FIX8::SessionID::get_targetCompID(), and XmlElement::GetAttr().

Referenced by FIX8::Session::handle_logon().

187 {
188  string name, type;
189  const XmlElement *which;
190  if (from_or_default(from, "persist", name) && (which = find_group(g_persisters, name)) && which->GetAttr("type", type))
191  {
192  if (type == "mem")
193  return new MemoryPersister;
194 
195  string dir("./"), db("persist_db");
196  which->GetAttr("dir", dir);
197  which->GetAttr("db", db) || which->GetAttr("session_prefix", db);
198 
199  if (sid)
200  db += ('.' + sid->get_senderCompID()() + '.' + sid->get_targetCompID()());
201  else if (which->FindAttr("use_session_id", false))
202  db += ('.' + get_sender_comp_id(from)() + '.' + get_target_comp_id(from)());
203 
204 #if defined FIX8_HAVE_LIBMEMCACHED
205  if (type == "memcached")
206  {
207  string config_str;
208  if (which->GetAttr("config_string", config_str))
209  {
210  unique_ptr<MemcachedPersister> result(new MemcachedPersister);
211  if (result->initialise(config_str, db, flag))
212  return result.release();
213  }
214  else
215  throw ConfigurationError("memcached: config_string attribute must be given when using memcached");
216  }
217  else
218 #endif
219 #if defined FIX8_HAVE_LIBHIREDIS
220  if (type == "redis")
221  {
222  string host_str;
223  if (which->GetAttr("host", host_str))
224  {
225  unique_ptr<HiredisPersister> result(new HiredisPersister);
226  if (result->initialise(host_str, which->FindAttr("port", 6379),
227  which->FindAttr("connect_timeout", static_cast<unsigned>(defaults::connect_timeout)), db, flag))
228  return result.release();
229  }
230  else
231  throw ConfigurationError("redis: host attribute must be given when using redis");
232  }
233  else
234 #endif
235 #if defined FIX8_HAVE_BDB
236  if (type == "bdb")
237  {
238  unique_ptr<BDBPersister> result(new BDBPersister);
239  if (result->initialise(dir, db, flag))
240  return result.release();
241  }
242  else
243 #endif
244  if (type == "file")
245  {
246  unique_ptr<FilePersister> result(new FilePersister(which->FindAttr("rotation", 0)));
247  if (result->initialise(dir, db, flag))
248  return result.release();
249  }
250  }
251 
252  return nullptr;
253 }
T FindAttr(const std::string &what, const T defValue) const
Definition: xml.hpp:209
const sender_comp_id & get_senderCompID() const
Definition: session.hpp:101
A simple xml parser with Xpath style lookup.
Definition: xml.hpp:48
An bad or missing configuration parameter.
const target_comp_id & get_targetCompID() const
Definition: session.hpp:105
F8API bool GetAttr(const std::string &what, std::string &target) const
Definition: xml.cpp:748
Memory based message persister.
Definition: persist.hpp:292
sender_comp_id get_sender_comp_id(const XmlElement *from) const
target_comp_id get_target_comp_id(const XmlElement *from) const
const XmlElement * find_group(group_types type, const std::string &tag) const
bool from_or_default(const XmlElement *from, const f8String &tag, f8String &target) const
Schedule Configuration::create_schedule ( const XmlElement from) const

Create schedule object from a session entity.

Parameters
fromxml entity to search
Returns
Schedule

Definition at line 131 of file configuration.cpp.

References FIX8::decode_dow(), XmlElement::FindAttr(), FIX8::Tickval::get_ticks(), XmlElement::GetAttr(), FIX8::Tickval::is_errorval(), and FIX8::Tickval::minute.

132 {
133  Tickval start(get_time_field(which, "start_time", true));
134  if (!start.is_errorval())
135  {
136  const int utc_offset(which->FindAttr("utc_offset_mins", 0)); // utc_offset is in minutes
137  const unsigned duration(which->FindAttr("duration", 0));
138  Tickval end(get_time_field(which, "end_time", true));
139 
140  if (end.is_errorval())
141  {
142  if (duration) // duration is in minutes
143  end = start.get_ticks() + duration * Tickval::minute;
144  }
145  else
146  {
147  if (end <= start)
148  throw ConfigurationError("Schedule end time cannot be equal to or before session start time");
149  }
150  string daytmp;
151  const int start_day(which->GetAttr("start_day", daytmp) ? decode_dow(daytmp) : -1);
152  const int end_day(which->GetAttr("end_day", daytmp) ? decode_dow(daytmp) : start_day < 0 ? -1 : start_day);
153  return {start, end, Tickval(static_cast<Tickval::ticks>(duration)), utc_offset, start_day, end_day};
154  }
155 
156  return {};
157 }
An bad or missing configuration parameter.
F8API int decode_dow(const std::string &from)
Tickval::ticks get_time_field(const XmlElement *from, const std::string &tag, bool timeonly=false) const
static const ticks minute
Definition: tickval.hpp:79
Session_Schedule * Configuration::create_session_schedule ( const XmlElement from) const

Create a new session schedule object from a session entity.

Parameters
fromxml entity to search
Returns
new Session_Schedule or 0 if unable to create

Definition at line 160 of file configuration.cpp.

References find_group(), XmlElement::FindAttr(), and XmlElement::GetAttr().

Referenced by FIX8::Session::start().

161 {
162  string name;
163  const XmlElement *which(0);
164  if (from_or_default(from, "schedule", name) && (which = find_group(g_schedules, name)))
165  {
166  Schedule sch(create_schedule(which));
167  f8String reject_text("Business messages are not accepted now.");
168  which->GetAttr("reject_text", reject_text); // can't use FindAttr since istream is delimeter sensitive
169  const int reject_code(which->FindAttr("reject_code", 0));
170  return new Session_Schedule(sch, reject_code, reject_text);
171  }
172 
173  return nullptr;
174 }
F8API Schedule create_schedule(const XmlElement *from) const
A simple xml parser with Xpath style lookup.
Definition: xml.hpp:48
std::string f8String
Definition: f8types.hpp:47
const XmlElement * find_group(group_types type, const std::string &tag) const
bool from_or_default(const XmlElement *from, const f8String &tag, f8String &target) const
const XmlElement* FIX8::Configuration::find_element ( const std::string &  tag,
const ConfigMap from 
) const
inlineprivate

Find an xml entity by tag in the supplied map.

Parameters
tagthe tag to find
fromthe map to search
Returns
the found entity or 0 if not found

Definition at line 105 of file configuration.hpp.

References XmlElement::end().

Referenced by find_group().

106  { ConfigMap::const_iterator itr(from.find(tag)); return itr != from.end() ? itr->second : nullptr; }
const XmlElement* FIX8::Configuration::find_group ( group_types  type,
const std::string &  tag 
) const
inline

Find an element in a specified group.

Parameters
typegroup type enum
tagthe tag to find
Returns
the found entity or 0 if not found

Definition at line 120 of file configuration.hpp.

References find_element().

121  { return find_element(tag, _groups[type]); }
const XmlElement * find_element(const std::string &tag, const ConfigMap &from) const
std::vector< ConfigMap > _groups
template<typename T >
T FIX8::Configuration::find_or_default ( const XmlElement from,
const std::string &  tag,
const T  def 
) const
inlineprotected

Find an attribute in the given XmlElement

Template Parameters
defaulttype
Parameters
fromthe xml entity to search
tagthe tag to find
defthe default value if not found
Returns
the found attribute value or the default value if not found

Definition at line 166 of file configuration.hpp.

References XmlElement::FindAttr(), and XmlElement::HasAttr().

Referenced by get_always_seqnum_assign(), get_connect_timeout(), get_enforce_compids_flag(), get_heartbeat_interval(), get_ignore_logon_sequence_check_flag(), get_logfile_rotation(), get_no_chksum_flag(), get_permissive_mode_flag(), get_reset_sequence_number_flag(), get_retry_count(), get_retry_interval(), get_silent_disconnect(), get_tabsize(), get_tcp_keepalive(), get_tcp_linger(), get_tcp_nodelay(), get_tcp_recvbuf_sz(), get_tcp_reuseaddr(), get_tcp_sendbuf_sz(), and get_version().

167  {
168  if (from)
169  {
170  if (from->HasAttr(tag))
171  return from->FindAttr(tag, def);
172  if (_default)
173  return _default->FindAttr(tag, def);
174  }
175  return def;
176  }
const XmlElement * _default
T FindAttr(const std::string &what, const T defValue) const
Definition: xml.hpp:209
bool HasAttr(const std::string &what) const
Definition: xml.hpp:184
bool FIX8::Configuration::from_or_default ( const XmlElement from,
const f8String tag,
f8String target 
) const
inlineprotected

Search the given element for a tag or look in the default element

Parameters
fromthe xml entity to search
tagthe tag to find
targetplace to put the resul
Returns
true if found and stored

Definition at line 129 of file configuration.hpp.

References XmlElement::GetAttr().

Referenced by get_string_field().

130  { return (from && from->GetAttr(tag, target)) || (_default && _default->GetAttr(tag, target)); }
const XmlElement * _default
F8API bool GetAttr(const std::string &what, std::string &target) const
Definition: xml.cpp:748
Poco::Net::SocketAddress Configuration::get_address ( const XmlElement from) const

Extract the ip address and port from a session entity.

Parameters
fromxml entity to search
Returns
Poco::Net::SocketAddress

Definition at line 83 of file configuration.cpp.

84 {
85  Poco::Net::SocketAddress to;
86  string ip, port;
87  if (from_or_default(from, "ip", ip) && from_or_default(from, "port", port))
88  to = Poco::Net::SocketAddress(ip, port);
89 
90  return to;
91 }
bool from_or_default(const XmlElement *from, const f8String &tag, f8String &target) const
size_t Configuration::get_addresses ( const XmlElement from,
std::vector< Server > &  target 
) const

Extract the ip addresses from a server_group entity.

Parameters
fromxml entity to search
targettarget vector of Server to store addresses
Returns
number of addresses stored

Definition at line 105 of file configuration.cpp.

References XmlElement::find(), find_group(), and FIX8::defaults::login_retries.

106 {
107  string name;
108  const XmlElement *which;
109  if (from_or_default(from, "server_group", name) && (which = find_group(g_server_group, name)))
110  {
111  XmlElement::XmlSet slist;
112  if (which->find("server_group/server", slist))
113  {
114  const Poco::Net::SocketAddress empty_addr;
115  for(const auto *pp : slist)
116  {
117  string name;
118  Poco::Net::SocketAddress addr(get_address(pp));
119  if (pp->GetAttr("name", name) && addr != empty_addr && pp->FindAttr("active", true))
120  target.push_back(Server(name, pp->FindAttr("max_retries", static_cast<int>(defaults::login_retries)), addr,
121  pp->FindAttr("reset_sequence_numbers", false)));
122  }
123  }
124  return target.size();
125  }
126 
127  return 0;
128 }
Class to hold server settings for failoverable sessions.
F8API Poco::Net::SocketAddress get_address(const XmlElement *from) const
A simple xml parser with Xpath style lookup.
Definition: xml.hpp:48
std::set< const XmlElement *, EntityOrderComp > XmlSet
Definition: xml.hpp:74
F8API const XmlElement * find(const std::string &what, const std::string *atag=nullptr, const std::string *aval=nullptr, const char delim='/') const
const XmlElement * find_group(group_types type, const std::string &tag) const
bool from_or_default(const XmlElement *from, const f8String &tag, f8String &target) const
unsigned Configuration::get_all_sessions ( std::vector< const XmlElement * > &  target,
const Connection::Role  role = Connection::cn_unknown 
) const

Get all active sessions that have been read; filter by role if desired.

Parameters
targetvector to place results
rolerole to filter (cn_unknown means all)
Returns
number of sessions found

Definition at line 372 of file configuration.cpp.

References FIX8::Connection::cn_unknown.

373 {
374  for (const auto *pp : _allsessions)
375  if (role == Connection::cn_unknown || get_role(pp) == role)
376  target.push_back(pp);
377  return static_cast<unsigned>(target.size());
378 }
F8API Connection::Role get_role(const XmlElement *from) const
std::vector< const XmlElement * > _allsessions
bool FIX8::Configuration::get_always_seqnum_assign ( const XmlElement from,
const bool  def = false 
) const
inline

Extract the always_seqnum_assign flag from a session entity.

Parameters
fromxml entity to search
defdefault value if not found
Returns
true if always_seqnum_assign flag was passed and was true

Definition at line 427 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::SessionConfig::SessionConfig().

428  { return find_or_default(from, "always_seqnum_assign", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
unsigned FIX8::Configuration::get_connect_timeout ( const XmlElement from,
const unsigned  def = defaults::connect_timeout 
) const
inline

Extract the connect_timeout interval (sec) from a session entity.

Parameters
fromxml entity to search
defdefault value if not found
Returns
the connect_timeout wait 10 if not found

Definition at line 289 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::SessionConfig::SessionConfig().

290  { return find_or_default(from, "connect_timeout", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
default_appl_ver_id FIX8::Configuration::get_default_appl_ver_id ( const XmlElement from) const
inline

Extract default_appl_ver_id from a session entity.

Parameters
fromxml entity to search
Returns
target default_appl_ver_id

Definition at line 438 of file configuration.hpp.

References get_string_field().

Referenced by FIX8::SessionConfig::SessionConfig().

439  { default_appl_ver_id to; return get_string_field(from, "default_appl_ver_id", to); }
T & get_string_field(const XmlElement *from, const std::string &tag, T &to) const
Field< f8String, Common_DefaultApplVerID > default_appl_ver_id
Definition: field.hpp:2152
bool FIX8::Configuration::get_enforce_compids_flag ( const XmlElement from,
const bool  def = true 
) const
inline

Extract the enforce_compids flag. When false, compids are not checked.

Parameters
fromxml entity to search
defdefault value if not found
Returns
true if enforce_compids flag was passed and was true

Definition at line 392 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::SessionConfig::SessionConfig().

393  { return find_or_default(from, "enforce_compids", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
unsigned FIX8::Configuration::get_heartbeat_interval ( const XmlElement from,
const unsigned  def = defaults::hb_interval 
) const
inline

Extract the heartbeat interval from a session entity.

Parameters
fromxml entity to search
defdefault value if not found
Returns
the heartbeat interval version or 0 if not found

Definition at line 350 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::SessionConfig::SessionConfig().

351  { return find_or_default(from, "heartbeat_interval", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
bool FIX8::Configuration::get_ignore_logon_sequence_check_flag ( const XmlElement from,
const bool  def = false 
) const
inline

Extract the ignore_logon_sequence_check flag from a session entity.

Parameters
fromxml entity to search
defdefault value if not found
Returns
true if ignore_logon_sequence_check flag was passed and was true

Definition at line 399 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::Session::sequence_check().

400  { return find_or_default(from, "ignore_logon_sequence_check", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
Poco::Net::IPAddress Configuration::get_ip ( const XmlElement from) const

Extract the ip address from a session entity.

Parameters
fromxml entity to search
Returns
Poco::Net::IPAddress

Definition at line 94 of file configuration.cpp.

95 {
96  Poco::Net::IPAddress to;
97  string ip;
98  if (from_or_default(from, "ip", ip))
99  to = Poco::Net::IPAddress(ip);
100 
101  return to;
102 }
bool from_or_default(const XmlElement *from, const f8String &tag, f8String &target) const
unsigned FIX8::Configuration::get_logfile_rotation ( const XmlElement from,
const unsigned  def = defaults::log_rotation 
) const
inline

Extract the logfile rotation count.

Parameters
fromxml entity to search
defdefault value if not found
Returns
the logfile rotation value or 5 if not found

Definition at line 343 of file configuration.hpp.

References find_or_default().

344  { return find_or_default(from, "rotation", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
template<typename T >
T FIX8::Configuration::get_logflags ( const std::string &  tag,
const std::vector< std::string > &  names,
const XmlElement from,
Logger::LogPositions positions = nullptr 
) const

Extract the logflags from the flags attribute in a log entity.

Template Parameters
Tebitset type
Parameters
tagattribute tag to search for
namesvector of names for each enumeration
fromxml entity to search
positionsvector to place enumeration position in
Returns
LogFLags object
template<typename T >
T FIX8::Configuration::get_logflags ( const string &  tag,
const vector< string > &  names,
const XmlElement from,
Logger::LogPositions positions 
) const

Definition at line 351 of file configuration.cpp.

References XmlElement::GetAttr(), and FIX8::trim().

353 {
354  T flags;
355  string flags_str;
356  if (from && from->GetAttr(tag, flags_str))
357  {
358  istringstream istr(flags_str);
359  for(char extr[32]; !istr.get(extr, sizeof(extr), '|').fail(); istr.ignore(1))
360  {
361  string result(extr);
362  const int evalue(flags.set(names, trim(result), true, true));
363  if (positions && evalue >= 0)
364  positions->push_back(evalue);
365  }
366  }
367 
368  return flags;
369 }
std::string trim(const std::string &source, const std::string &ws=" \t")
Definition: f8utils.hpp:153
F8API bool GetAttr(const std::string &what, std::string &target) const
Definition: xml.cpp:748
string & Configuration::get_logname ( const XmlElement from,
std::string &  to,
const SessionID sid = nullptr 
) const

Extract the session log filename address from a session entity.

Parameters
fromxml entity to search
totarget logfile string
sidoptional session id to build name from
Returns
target string

Definition at line 339 of file configuration.cpp.

References XmlElement::FindAttr(), FIX8::SessionID::get_senderCompID(), and FIX8::SessionID::get_targetCompID().

340 {
341  if (sid)
342  to += ('.' + sid->get_senderCompID()() + '.' + sid->get_targetCompID()());
343  else if (from && from->FindAttr("use_session_id", false))
344  to += ('.' + get_sender_comp_id(from)() + '.' + get_target_comp_id(from)());
345 
346  return to;
347 }
T FindAttr(const std::string &what, const T defValue) const
Definition: xml.hpp:209
const sender_comp_id & get_senderCompID() const
Definition: session.hpp:101
const target_comp_id & get_targetCompID() const
Definition: session.hpp:105
sender_comp_id get_sender_comp_id(const XmlElement *from) const
target_comp_id get_target_comp_id(const XmlElement *from) const
bool FIX8::Configuration::get_no_chksum_flag ( const XmlElement from,
const bool  def = false 
) const
inline

Extract the get_no_chksum_flag flag from a session entity.

Parameters
fromxml entity to search
defdefault value if not found
Returns
true if get_no_chksum_flag flag was passed and was true

Definition at line 406 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::SessionConfig::SessionConfig().

407  { return find_or_default(from, "no_chksum", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
bool FIX8::Configuration::get_permissive_mode_flag ( const XmlElement from,
const bool  def = false 
) const
inline

Extract the get_permissive_mode_flag flag from a session entity.

Parameters
fromxml entity to search
defdefault value if not found
Returns
true if get_permissive_mode_flag flag was passed and was true

Definition at line 413 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::SessionConfig::SessionConfig().

414  { return find_or_default(from, "permissive_mode", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
ProcessModel Configuration::get_process_model ( const XmlElement from) const

Extract process model.

Parameters
fromxml entity to search
Returns
pm_thread, pm_pipeline or pm_coro

Definition at line 381 of file configuration.cpp.

References FIX8::enum_str_get(), FIX8::pm_pipeline, and FIX8::pm_thread.

Referenced by FIX8::ClientSession< T >::ClientSession(), and server_process().

382 {
383  static const vector<f8String> process_strings { "threaded", "pipelined", "coroutine" };
384  string pm;
385  return from_or_default(from, "process_model", pm)
386  ? enum_str_get(process_strings, pm, pm_thread) : pm_pipeline; // default to pipelined
387 }
T enum_str_get(const std::vector< std::string > &sset, const std::string &what, const T def, bool ignorecase=false)
Definition: f8utils.hpp:1048
bool from_or_default(const XmlElement *from, const f8String &tag, f8String &target) const
bool FIX8::Configuration::get_reset_sequence_number_flag ( const XmlElement from,
const bool  def = false 
) const
inline

Extract the reset_sequence_number flag from a session entity.

Parameters
fromxml entity to search
defdefault value if not found
Returns
true if reset_sequence_number flag was passed and was true

Definition at line 420 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::SessionConfig::SessionConfig().

421  { return find_or_default(from, "reset_sequence_numbers", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
unsigned FIX8::Configuration::get_retry_count ( const XmlElement from,
const int  def = defaults::login_retries 
) const
inline

Extract the login retry count from a session entity.

Parameters
fromxml entity to search
defdefault value if not found
Returns
the retry count or 10 if not found

Definition at line 303 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::SessionConfig::SessionConfig().

304  {
305  const int rc(find_or_default(from, "login_retries", def));
306  if (rc < 0)
307  throw ConfigurationError("retry count must be >= 0");
308  return rc;
309  }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
unsigned FIX8::Configuration::get_retry_interval ( const XmlElement from,
const unsigned  def = defaults::retry_interval 
) const
inline

Extract the login retry wait interval (ms) from a session entity.

Parameters
fromxml entity to search
defdefault value if not found
Returns
the retry wait interval or 5000 if not found

Definition at line 296 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::SessionConfig::SessionConfig().

297  { return find_or_default(from, "login_retry_interval", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
Connection::Role Configuration::get_role ( const XmlElement from) const

Extract the role from a session entity.

Parameters
fromxml entity to search
Returns
the connection role or Connection::cn_unknown if not found

Definition at line 74 of file configuration.cpp.

References FIX8::Connection::cn_acceptor, FIX8::Connection::cn_initiator, and FIX8::Connection::cn_unknown.

75 {
76  string role;
77  return from_or_default(from, "role", role)
78  ? role % "initiator" ? Connection::cn_initiator
80 }
bool from_or_default(const XmlElement *from, const f8String &tag, f8String &target) const
const XmlElement* FIX8::Configuration::get_root ( ) const
inline

Return ptr to the root XmlElement

Returns
root element

Definition at line 502 of file configuration.hpp.

References _root.

502 { return _root; }
const XmlElement * _root
sender_comp_id FIX8::Configuration::get_sender_comp_id ( const XmlElement from) const
inline

Extract sendercompid from a session entity.

Parameters
fromxml entity to search
Returns
target sender_comp_id

Definition at line 444 of file configuration.hpp.

References get_string_field().

445  { sender_comp_id to; return get_string_field(from, "sender_comp_id", to); }
T & get_string_field(const XmlElement *from, const std::string &tag, T &to) const
Field< f8String, Common_SenderCompID > sender_comp_id
Definition: field.hpp:2145
const XmlElement* FIX8::Configuration::get_session ( const unsigned  num) const
inline

Find a session entity by index.

Parameters
numindex of session
Returns
the session entity or 0 if not found

Definition at line 243 of file configuration.hpp.

244  { return num < _allsessions.size() ? _allsessions[num] : nullptr; }
std::vector< const XmlElement * > _allsessions
bool FIX8::Configuration::get_silent_disconnect ( const XmlElement from,
const bool  def = false 
) const
inline

Extract the silent disconnect flag.

Parameters
fromxml entity to search
defdefault value if not found
Returns
true if silent_disconnect flag was passed and was true

Definition at line 385 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::SessionConfig::SessionConfig().

386  { return find_or_default(from, "silent_disconnect", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
template<typename T >
T& FIX8::Configuration::get_string_field ( const XmlElement from,
const std::string &  tag,
T &  to 
) const
inlineprotected

Find a fix8 field typed value by tag from an xml entity.

Template Parameters
locationtype
Parameters
fromthe xml entity to search
tagthe tag to find
tolocation to store target
Returns
the target

Definition at line 139 of file configuration.hpp.

References from_or_default().

Referenced by get_default_appl_ver_id(), get_sender_comp_id(), and get_target_comp_id().

140  {
141  std::string val;
142  if (from_or_default(from, tag, val))
143  to.set(val);
144  return to;
145  }
bool from_or_default(const XmlElement *from, const f8String &tag, f8String &target) const
unsigned FIX8::Configuration::get_tabsize ( const XmlElement from,
const unsigned  def = defaults::tabsize 
) const
inline

Extract the Message printer tabsize from a session entity.

Parameters
fromxml entity to search
defdefault value if not found
Returns
the tabsize version or defaults::tabsize if not found

Definition at line 336 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::SessionConfig::SessionConfig().

337  { return find_or_default(from, "tabsize", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
target_comp_id FIX8::Configuration::get_target_comp_id ( const XmlElement from) const
inline

Extract targetcompid from a session entity.

Parameters
fromxml entity to search
Returns
target target_comp_id

Definition at line 450 of file configuration.hpp.

References get_string_field().

451  { target_comp_id to; return get_string_field(from, "target_comp_id", to); }
T & get_string_field(const XmlElement *from, const std::string &tag, T &to) const
Field< f8String, Common_TargetCompID > target_comp_id
Definition: field.hpp:2146
bool FIX8::Configuration::get_tcp_keepalive ( const XmlElement from,
const bool  def = false 
) const
inline

Extract the tcp keepalive flag.

Parameters
fromxml entity to search
defdefault value if not found
Returns
false if keepalive flag was passed and was false

Definition at line 364 of file configuration.hpp.

References find_or_default().

365  { return find_or_default(from, "tcp_keepalive", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
int FIX8::Configuration::get_tcp_linger ( const XmlElement from,
const int  def = -1 
) const
inline

Extract the socket linger setting from a session entity.

Parameters
fromxml entity to search
defdefault value if not found
Returns
the socket linger value (secs)

Definition at line 378 of file configuration.hpp.

References find_or_default().

379  { return find_or_default(from, "tcp_linger", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
bool FIX8::Configuration::get_tcp_nodelay ( const XmlElement from,
const bool  def = true 
) const
inline

Extract the tcp nodelay flag.

Parameters
fromxml entity to search
defdefault value if not found
Returns
false if nodelay flag was passed and was false

Definition at line 357 of file configuration.hpp.

References find_or_default().

358  { return find_or_default(from, "tcp_nodelay", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
unsigned FIX8::Configuration::get_tcp_recvbuf_sz ( const XmlElement from,
const unsigned  def = 0 
) const
inline

Extract the tcp recv buffer size

Parameters
fromxml entity to search
defdefault value if not found
Returns
the recv buffer size count or 0 if the default should be used

Definition at line 315 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::SessionConfig::SessionConfig().

316  { return find_or_default(from, "tcp_recv_buffer", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
bool FIX8::Configuration::get_tcp_reuseaddr ( const XmlElement from,
const bool  def = false 
) const
inline

Extract the tcp reuseaddr flag.

Parameters
fromxml entity to search
defdefault value if not found
Returns
false if reuseaddr flag was passed and was false

Definition at line 371 of file configuration.hpp.

References find_or_default().

372  { return find_or_default(from, "tcp_reuseaddr", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
unsigned FIX8::Configuration::get_tcp_sendbuf_sz ( const XmlElement from,
const unsigned  def = 0 
) const
inline

Extract the tcp send buffer size

Parameters
fromxml entity to search
defdefault value if not found
Returns
the send buffer size count or 0 if the default should be used

Definition at line 322 of file configuration.hpp.

References find_or_default().

Referenced by FIX8::SessionConfig::SessionConfig().

323  { return find_or_default(from, "tcp_send_buffer", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
Tickval::ticks FIX8::Configuration::get_time_field ( const XmlElement from,
const std::string &  tag,
bool  timeonly = false 
) const
inlineprotected

Find a session time field by tag from an xml entity.

Parameters
fromthe xml entity to search
tagthe tag to find
timeonlyif true, only use the time part
Returns
Tickval::ticks time or errorticks if not found

Definition at line 152 of file configuration.hpp.

References FIX8::Tickval::errorticks(), XmlElement::GetAttr(), and FIX8::time_parse().

153  {
154  std::string time_str;
155  return from && from->GetAttr(tag, time_str) && time_str.size() == 8
156  ? time_parse(time_str.c_str(), 8, timeonly) : Tickval::errorticks();
157  }
static const ticks & errorticks()
Definition: tickval.hpp:69
Tickval::ticks time_parse(const char *ptr, size_t len, bool timeonly=false)
Definition: field.hpp:978
F8API bool GetAttr(const std::string &what, std::string &target) const
Definition: xml.cpp:748
unsigned FIX8::Configuration::get_version ( const XmlElement from,
const unsigned  def = 0 
) const
inline

Extract the FIX version from a session entity.

Parameters
fromxml entity to search
defdefault value if not found
Returns
the FIX version or 0 if not found

Definition at line 329 of file configuration.hpp.

References find_or_default().

330  { return find_or_default(from, "fix_version", def); }
T find_or_default(const XmlElement *from, const std::string &tag, const T def) const
unsigned FIX8::Configuration::load_map ( const std::string &  tag,
ConfigMap map_name,
const bool  is_session = false 
)
inlineprivate

Load a repeating group into a supplied map.

Parameters
tagthe tag to find
map_namethe target map
is_sessionif true, special case for session map
Returns
the number of elements inserted

Definition at line 184 of file configuration.hpp.

References XmlElement::find().

185  {
186  XmlElement::XmlSet slist;
187  if (_root->find(tag, slist))
188  {
189  for(const auto *pp : slist)
190  {
191  std::string name;
192  if (pp->GetAttr("name", name) && is_session ? pp->FindAttr("active", false) : true)
193  {
194  map_name.insert({name, pp});
195  if (is_session)
196  _allsessions.push_back(pp);
197  }
198  }
199  }
200 
201  return static_cast<unsigned>(map_name.size());
202  }
std::set< const XmlElement *, EntityOrderComp > XmlSet
Definition: xml.hpp:74
const XmlElement * _root
std::vector< const XmlElement * > _allsessions
F8API const XmlElement * find(const std::string &what, const std::string *atag=nullptr, const std::string *aval=nullptr, const char delim='/') const
int Configuration::process ( )

Process the config file.

Returns
the number of sessions processed (found)

Definition at line 52 of file configuration.cpp.

Referenced by Configuration().

53 {
54  if (!_root)
55  throw ConfigurationError("could not create root xml entity");
56 
57  using item = tuple<f8String, group_types, bool>;
58  static const item items[]
59  {
60  { item("session", g_sessions, true) }, { item("log", g_loggers, false) },
61  { item("server_group", g_server_group, false) }, { item("client_group", g_client_group, false) },
62  { item("ssl_context", g_ssl_context, false) }, { item("schedule", g_schedules, false) },
63  { item("login", g_logins, false) }, { item("persist", g_persisters, false) }
64  };
65 
66  for (auto &pp : items)
67  if (!load_map("fix8/" + get<0>(pp), _groups[get<1>(pp)], get<2>(pp)) && get<2>(pp))
68  throw ConfigurationError("could not locate server session in configuration", get<0>(pp));
69 
70  return static_cast<int>(_groups[g_sessions].size());
71 }
An bad or missing configuration parameter.
const XmlElement * _root
unsigned load_map(const std::string &tag, ConfigMap &map_name, const bool is_session=false)
std::vector< ConfigMap > _groups

Member Data Documentation

std::vector<const XmlElement *> FIX8::Configuration::_allsessions
private

Definition at line 99 of file configuration.hpp.

const XmlElement * FIX8::Configuration::_default
private

Definition at line 96 of file configuration.hpp.

std::vector<ConfigMap> FIX8::Configuration::_groups
private

Definition at line 98 of file configuration.hpp.

RegExp Configuration::_ipexp
staticprivate

Definition at line 94 of file configuration.hpp.

const XmlElement* FIX8::Configuration::_root
private

Definition at line 96 of file configuration.hpp.

Referenced by get_root().


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