LCOV - code coverage report
Current view: top level - xmpp - xmpp_config.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 7 7 100.0 %
Date: 2026-06-18 01:51:13 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #ifndef __XMPP_CONFIG_H__
       6             : #define __XMPP_CONFIG_H__
       7             : 
       8             : #include <boost/asio/ip/tcp.hpp>
       9             : #include <boost/function.hpp>
      10             : #include <boost/property_tree/ptree.hpp>
      11             : #include <boost/ptr_container/ptr_map.hpp>
      12             : 
      13             : #include "base/util.h"
      14             : 
      15             : // Internal representation of Peer configuration
      16             : class XmppChannelConfig {
      17             : public:
      18             :     explicit XmppChannelConfig(bool isClient = false);
      19             : 
      20             :     std::string ToAddr;
      21             :     std::string FromAddr;
      22             :     std::string NodeAddr; // pubsub node
      23             :     std::string name;
      24             :     boost::asio::ip::tcp::endpoint endpoint;
      25             :     boost::asio::ip::tcp::endpoint local_endpoint;
      26             :     bool logUVE;
      27             :     bool auth_enabled;
      28             :     std::string path_to_server_cert;
      29             :     std::string path_to_server_priv_key;
      30             :     std::string path_to_ca_cert;
      31             :     int tcp_hold_time;
      32             :     bool gr_helper_disable;
      33             :     int xmpp_hold_time; // was uint8_t, but int everywhere
      34             :     uint8_t dscp_value;
      35             :     std::string xmlns;
      36             : 
      37             :     int CompareTo(const XmppChannelConfig &rhs) const;
      38             :     static int const default_client_port = 5269;
      39             :     static int const default_server_port = 5222;
      40             :     static int const kTcpHoldTime = 30; //in secs
      41             : 
      42       46420 :     bool ClientOnly() const { return isClient_; }
      43             : 
      44             : private:
      45             :     bool isClient_;
      46             : };
      47             : 
      48             : class XmppConfigData {
      49             : public:
      50             :     typedef boost::ptr_map<boost::asio::ip::tcp::endpoint, XmppChannelConfig>
      51             :         XmppChannelConfigMap;
      52             : 
      53       10034 :     XmppConfigData() {
      54       10034 :     }
      55             : 
      56        4990 :     void AddXmppChannelConfig(XmppChannelConfig *channel) {
      57        4990 :         neighbors_.insert(channel->endpoint, channel);
      58        4990 :     }
      59             : 
      60             :     XmppChannelConfig &GetXmppChannelConfig(const boost::asio::ip::tcp::endpoint ep) {
      61             :         return neighbors_[ep];
      62             :     }
      63             : 
      64        9998 :     const XmppChannelConfigMap &neighbors() const { return neighbors_; }
      65             : 
      66             :     void Clear() {
      67             :         neighbors_.clear();
      68             :     }
      69             : 
      70             : private:
      71             :     XmppChannelConfigMap neighbors_;
      72             :     DISALLOW_COPY_AND_ASSIGN(XmppConfigData);
      73             : };
      74             : 
      75             : class XmppConfigManager {
      76             : public:
      77             :     enum DiffType {
      78             :         DF_NONE,
      79             :         DF_ADD,
      80             :         DF_CHANGE,
      81             :         DF_DELETE
      82             :     };
      83             : 
      84             :     XmppConfigManager();
      85             : 
      86             :     typedef boost::function<void(DiffType, const XmppChannelConfig *,
      87             :                                  const XmppChannelConfig *)> PeerDiffObserver;
      88             : 
      89             :     // stage 1: build the future internal representation
      90             :     bool ParseConfig(const std::string &config, XmppConfigData *);
      91             : 
      92             :     // stage 2: generate a delta
      93             :     void PeerConfigDiff(PeerDiffObserver obs) const;
      94             : 
      95             :     // stage 3: commit
      96             :     void AcceptFuture();
      97             : 
      98             :     // testing API -- begin --
      99             :     void SetFuture(const XmppConfigData *future);
     100             :     // testing API -- end --
     101             : 
     102             :     void Terminate();
     103             : private:
     104             :     std::unique_ptr<const XmppConfigData> current_;
     105             :     std::unique_ptr<const XmppConfigData> future_;
     106             :     DISALLOW_COPY_AND_ASSIGN(XmppConfigManager);
     107             : };
     108             : 
     109             : #endif

Generated by: LCOV version 1.14