Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef __DNS_XMPP_H__ 6 : #define __DNS_XMPP_H__ 7 : 8 : #include <map> 9 : #include <string> 10 : 11 : #include <boost/function.hpp> 12 : #include <boost/system/error_code.hpp> 13 : 14 : #include <bind/bind_util.h> 15 : #include <xmpp/xmpp_channel.h> 16 : 17 : class XmppChannel; 18 : class Agent; 19 : class VmInterface; 20 : 21 : class AgentDnsXmppChannel { 22 : public: 23 : // Packet module is optional. Callback function to update the flow stats 24 : // for ACL. The callback is defined to avoid linking error 25 : // when flow is not enabled 26 : typedef boost::function<void(DnsUpdateData*, DnsAgentXmpp::XmppType, 27 : VmInterface const*, bool)> DnsMessageHandler; 28 : typedef boost::function<void(AgentDnsXmppChannel*)> DnsXmppEventHandler; 29 : 30 : explicit AgentDnsXmppChannel(Agent *agent, 31 : std::string xmpp_server, uint8_t xs_idx); 32 : virtual ~AgentDnsXmppChannel(); 33 : 34 : virtual std::string ToString() const; 35 : virtual bool SendMsg(uint8_t *msg, std::size_t len); 36 : virtual void ReceiveMsg(const XmppStanza::XmppMessage *msg); 37 0 : std::string GetXmppServer() { return xmpp_server_; } 38 0 : uint8_t GetXmppServerIdx() { return xs_idx_; } 39 2 : XmppChannel *GetXmppChannel() { return channel_; } 40 : void UpdateConnectionInfo(xmps::PeerState state); 41 : static void XmppClientChannelEvent(AgentDnsXmppChannel *peer, 42 : xmps::PeerState state); 43 : static void HandleXmppClientChannelEvent(AgentDnsXmppChannel *peer, 44 : xmps::PeerState state); 45 : static void set_dns_message_handler_cb(DnsMessageHandler cb); 46 : static void set_dns_xmpp_event_handler_cb(DnsXmppEventHandler cb); 47 0 : Agent *agent() const {return agent_;} 48 : void RegisterXmppChannel(XmppChannel *channel); 49 : void ReceiveDnsMessage(std::unique_ptr<XmlBase> impl); 50 : void TimedOut(); 51 : 52 : protected: 53 : virtual void WriteReadyCb(const boost::system::error_code &ec); 54 : 55 : private: 56 : void ReceiveInternal(const XmppStanza::XmppMessage *msg); 57 : XmppChannel *channel_; 58 : std::string xmpp_server_; 59 : uint8_t xs_idx_; 60 : static DnsMessageHandler dns_message_handler_cb_; 61 : static DnsXmppEventHandler dns_xmpp_event_handler_cb_; 62 : Agent *agent_; 63 : }; 64 : 65 : #endif // __DNS_XMPP_H__