linklocalmanager.h
/*
Copyright (c) 2012-2023 by Jakob Schröter <js@camaya.net>
This file is part of the gloox library. http://camaya.net/gloox
This software is distributed under a license. The full license
agreement can be found in the file LICENSE in this distribution.
This software may not be copied, modified, sold or distributed
other than expressed in the named license agreement.
This software is distributed without any warranty.
*/
#ifndef LINKLOCALMANAGER_H___
#define LINKLOCALMANAGER_H___
#include "config.h"
#ifdef HAVE_MDNS
#include "linklocal.h"
#include "macros.h"
#include "gloox.h"
#include "util.h"
#include "logsink.h"
#include "connectiontcpserver.h"
#include "mutex.h"
#include "jid.h"
#include <string>
#include <dns_sd.h>
namespace gloox
{
class ConnectionHandler;
class ConnectionTCPClient;
namespace LinkLocal
{
class Handler;
class GLOOX_API Manager
{
public:
Manager( const std::string& user, ConnectionHandler* connHandler, const LogSink &logInstance );
virtual ~Manager();
void addTXTData( const std::string& key, const std::string& value );
void removeTXTData( const std::string& key );
void registerService();
void deregisterService();
void setUser( const std::string& user ) { m_user = user; }
void setHost( const std::string& host ) { m_host = host; }
void setDomain( const std::string& domain ) { m_domain = domain; }
void setPort( const int port ) { m_port = port; addTXTData( "port.p2pj", util::int2string( m_port ) ); }
void setInterface( unsigned iface ) { m_interface = iface; }
bool startBrowsing();
void stopBrowsing();
int socket() const { return m_browseFd; }
void recv( int timeout );
void registerLinkLocalHandler( Handler* handler ) { m_linkLocalHandler = handler; }
// /**
// *
// */
// static const StringMap decodeTXT( const std::string& txt );
private:
static void handleBrowseReply( DNSServiceRef sdRef, DNSServiceFlags flags, unsigned interfaceIndex,
DNSServiceErrorType errorCode, const char* serviceName, const char* regtype,
const char* replyDomain, void* context );
void handleBrowse( Flag flag, const std::string& service, const std::string& regtype, const std::string& domain, int iface, bool moreComing );
typedef std::list<ConnectionTCPClient*> ConnectionList;
typedef std::map<ConnectionTCPClient*, const JID> ConnectionMap;
DNSServiceRef m_publishRef;
DNSServiceRef m_browseRef;
ServiceList m_tmpServices;
// ServiceList m_services;
std::string m_user;
std::string m_host;
std::string m_domain;
unsigned m_interface;
int m_port;
const LogSink& m_logInstance;
int m_browseFd;
StringMap m_txtData;
ConnectionTCPServer m_server;
Handler* m_linkLocalHandler;
ConnectionHandler* m_connectionHandler;
};
}
}
#endif // HAVE_MDNS
#endif // LINKLOCALMANAGER_H___
gloox::ConnectionHandler
This is an abstract base class to receive incoming connection attempts. Do not confuse this with Conn...
Definition connectionhandler.h:34
gloox::ConnectionTCPClient
This is an implementation of a simple TCP connection.
Definition connectiontcpclient.h:37
gloox::ConnectionTCPServer
This is an implementation of a simple listening TCP connection.
Definition connectiontcpserver.h:37
gloox::LinkLocal::Handler
A base class that gets informed about advertised or removed XMPP services on the local network.
Definition linklocalhandler.h:42
gloox::LinkLocal::Manager::removeTXTData
void removeTXTData(const std::string &key)
Definition linklocalmanager.cpp:69
gloox::LinkLocal::Manager::setDomain
void setDomain(const std::string &domain)
Definition linklocalmanager.h:247
gloox::LinkLocal::Manager::setUser
void setUser(const std::string &user)
Definition linklocalmanager.h:229
gloox::LinkLocal::Manager::registerService
void registerService()
Definition linklocalmanager.cpp:74
gloox::LinkLocal::Manager::setPort
void setPort(const int port)
Definition linklocalmanager.h:259
gloox::LinkLocal::Manager::setHost
void setHost(const std::string &host)
Definition linklocalmanager.h:238
gloox::LinkLocal::Manager::Manager
Manager(const std::string &user, ConnectionHandler *connHandler, const LogSink &logInstance)
Definition linklocalmanager.cpp:45
gloox::LinkLocal::Manager::deregisterService
void deregisterService()
Definition linklocalmanager.cpp:117
gloox::LinkLocal::Manager::addTXTData
void addTXTData(const std::string &key, const std::string &value)
Definition linklocalmanager.cpp:61
gloox::LinkLocal::Manager::registerLinkLocalHandler
void registerLinkLocalHandler(Handler *handler)
Definition linklocalmanager.h:308
gloox::LinkLocal::Manager::setInterface
void setInterface(unsigned iface)
Definition linklocalmanager.h:272
gloox::LinkLocal::Manager::socket
int socket() const
Definition linklocalmanager.h:294
gloox::LogSink
An implementation of log sink and source.
Definition logsink.h:39
gloox::LinkLocal
Namespace holding all the Link-local-related structures and definitions.
Definition linklocal.h:33
gloox::LinkLocal::Flag
Flag
Definition linklocal.h:41
gloox::LinkLocal::ServiceList
std::list< Service > ServiceList
Definition linklocal.h:71
gloox
The namespace for the gloox library.
Definition adhoc.cpp:28
gloox::StringMap
std::map< std::string, std::string > StringMap
Definition gloox.h:1261