Skip to content

Commit

Permalink
zeroconf: maintain txt record order when publishing service
Browse files Browse the repository at this point in the history
  • Loading branch information
elupus committed Oct 26, 2012
1 parent 98ca5d8 commit 25629fc
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 39 deletions.
16 changes: 8 additions & 8 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ bool CApplication::StartWebServer()
bool started = false;
if (m_WebServer.Start(webPort, g_guiSettings.GetString("services.webserverusername"), g_guiSettings.GetString("services.webserverpassword")))
{
std::map<std::string, std::string> txt;
std::vector<std::pair<std::string, std::string> > txt;
started = true;
// publish web frontend and API services
#ifdef HAS_WEB_INTERFACE
Expand Down Expand Up @@ -1564,19 +1564,19 @@ bool CApplication::StartAirplayServer()
if (CAirPlayServer::StartServer(listenPort, true))
{
CAirPlayServer::SetCredentials(usePassword, password);
std::map<std::string, std::string> txt;
std::vector<std::pair<std::string, std::string> > txt;
CNetworkInterface* iface = g_application.getNetwork().GetFirstConnectedInterface();
if (iface)
{
txt["deviceid"] = iface->GetMacAddress();
txt.push_back(std::make_pair("deviceid", iface->GetMacAddress()));
}
else
{
txt["deviceid"] = "FF:FF:FF:FF:FF:F2";
txt.push_back(std::make_pair("deviceid", "FF:FF:FF:FF:FF:F2"));
}
txt["features"] = "0x77";
txt["model"] = "AppleTV2,1";
txt["srcvers"] = AIRPLAY_SERVER_VERSION_STR;
txt.push_back(std::make_pair("features", "0x77"));
txt.push_back(std::make_pair("model", "AppleTV2,1"));
txt.push_back(std::make_pair("srcvers", AIRPLAY_SERVER_VERSION_STR));
CZeroconf::GetInstance()->PublishService("servers.airplay", "_airplay._tcp", g_infoManager.GetLabel(SYSTEM_FRIENDLY_NAME), listenPort, txt);
ret = true;
}
Expand Down Expand Up @@ -1620,7 +1620,7 @@ bool CApplication::StartJSONRPCServer()
{
if (CTCPServer::StartServer(g_advancedSettings.m_jsonTcpPort, g_guiSettings.GetBool("services.esallinterfaces")))
{
std::map<std::string, std::string> txt;
std::vector<std::pair<std::string, std::string> > txt;
CZeroconf::GetInstance()->PublishService("servers.jsonrpc-tpc", "_xbmc-jsonrpc._tcp", g_infoManager.GetLabel(SYSTEM_FRIENDLY_NAME), g_advancedSettings.m_jsonTcpPort, txt);
return true;
}
Expand Down
32 changes: 16 additions & 16 deletions xbmc/network/AirTunesServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,22 +503,22 @@ bool CAirTunesServer::StartServer(int port, bool nonlocal, bool usePassword, con
CStdString appName;
appName.Format("%s@%s", m_macAddress.c_str(), g_infoManager.GetLabel(SYSTEM_FRIENDLY_NAME).c_str());

std::map<std::string, std::string> txt;
txt["cn"] = "0,1";
txt["ch"] = "2";
txt["ek"] = "1";
txt["et"] = "0,1";
txt["sv"] = "false";
txt["tp"] = "UDP";
txt["sm"] = "false";
txt["ss"] = "16";
txt["sr"] = "44100";
txt["pw"] = "false";
txt["vn"] = "3";
txt["da"] = "true";
txt["vs"] = "130.14";
txt["md"] = "0,1,2";
txt["txtvers"] = "1";
std::vector<std::pair<std::string, std::string> > txt;
txt.push_back(std::make_pair("txtvers", "1"));
txt.push_back(std::make_pair("cn", "0,1"));
txt.push_back(std::make_pair("ch", "2"));
txt.push_back(std::make_pair("ek", "1"));
txt.push_back(std::make_pair("et", "0,1"));
txt.push_back(std::make_pair("sv", "false"));
txt.push_back(std::make_pair("tp", "UDP"));
txt.push_back(std::make_pair("sm", "false"));
txt.push_back(std::make_pair("ss", "16"));
txt.push_back(std::make_pair("sr", "44100"));
txt.push_back(std::make_pair("pw", "false"));
txt.push_back(std::make_pair("vn", "3"));
txt.push_back(std::make_pair("da", "true"));
txt.push_back(std::make_pair("vs", "130.14"));
txt.push_back(std::make_pair("md", "0,1,2"));

CZeroconf::GetInstance()->PublishService("servers.airtunes", "_raop._tcp", appName, port, txt);
}
Expand Down
2 changes: 1 addition & 1 deletion xbmc/network/EventServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void CEventServer::Run()
CAddress any_addr;
CSocketListener listener;
int packetSize = 0;
std::map<std::string, std::string> txt;
std::vector<std::pair<std::string, std::string> > txt;

CLog::Log(LOGNOTICE, "ES: Starting UDP Event server on %s:%d", any_addr.Address(), m_iPort);

Expand Down
4 changes: 2 additions & 2 deletions xbmc/network/Zeroconf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
//should be optimized away
class CZeroconfDummy : public CZeroconf
{
virtual bool doPublishService(const std::string&, const std::string&, const std::string&, unsigned int, std::map<std::string, std::string>)
virtual bool doPublishService(const std::string&, const std::string&, const std::string&, unsigned int, const std::vector<std::pair<std::string, std::string> >&)
{
return false;
}
Expand All @@ -68,7 +68,7 @@ bool CZeroconf::PublishService(const std::string& fcr_identifier,
const std::string& fcr_type,
const std::string& fcr_name,
unsigned int f_port,
std::map<std::string, std::string> txt)
const std::vector<std::pair<std::string, std::string> >& txt)
{
CSingleLock lock(*mp_crit_sec);
CZeroconf::PublishInfo info = {fcr_type, fcr_name, f_port, txt};
Expand Down
7 changes: 4 additions & 3 deletions xbmc/network/Zeroconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <string>
#include <map>
#include <vector>
#include "utils/Job.h"

class CCriticalSection;
Expand Down Expand Up @@ -49,7 +50,7 @@ class CZeroconf
const std::string& fcr_type,
const std::string& fcr_name,
unsigned int f_port,
std::map<std::string, std::string> txt);
const std::vector<std::pair<std::string, std::string> >& txt);

///removes the specified service
///returns false if fcr_identifier does not exist
Expand Down Expand Up @@ -86,7 +87,7 @@ class CZeroconf
const std::string& fcr_type,
const std::string& fcr_name,
unsigned int f_port,
std::map<std::string, std::string> txt) = 0;
const std::vector<std::pair<std::string, std::string> >& txt) = 0;
//removes the service if published
virtual bool doRemoveService(const std::string& fcr_ident) = 0;

Expand All @@ -107,7 +108,7 @@ class CZeroconf
std::string type;
std::string name;
unsigned int port;
std::map<std::string, std::string> txt;
std::vector<std::pair<std::string, std::string> > txt;
};

//protects data
Expand Down
4 changes: 2 additions & 2 deletions xbmc/network/linux/ZeroconfAvahi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ bool CZeroconfAvahi::doPublishService(const std::string& fcr_identifier,
const std::string& fcr_type,
const std::string& fcr_name,
unsigned int f_port,
std::map<std::string, std::string> txt)
const std::vector<std::pair<std::string, std::string> >& txt)
{
CLog::Log(LOGDEBUG, "CZeroconfAvahi::doPublishService identifier: %s type: %s name:%s port:%i", fcr_identifier.c_str(), fcr_type.c_str(), fcr_name.c_str(), f_port);

Expand All @@ -145,7 +145,7 @@ bool CZeroconfAvahi::doPublishService(const std::string& fcr_identifier,

//txt records to AvahiStringList
AvahiStringList *txtList = NULL;
for(std::map<std::string, std::string>::iterator it=txt.begin(); it!=txt.end(); it++)
for(std::vector<std::pair<std::string, std::string> >::const_iterator it=txt.begin(); it!=txt.end(); it++)
{
txtList = avahi_string_list_add_pair(txtList, it->first.c_str(), it->second.c_str());
}
Expand Down
3 changes: 2 additions & 1 deletion xbmc/network/linux/ZeroconfAvahi.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <memory>
#include <map>
#include <vector>
#include <string>
#include "network/Zeroconf.h"

Expand All @@ -47,7 +48,7 @@ class CZeroconfAvahi : public CZeroconf
const std::string& fcr_type,
const std::string& fcr_name,
unsigned int f_port,
std::map<std::string, std::string> txt);
const std::vector<std::pair<std::string, std::string> >& txt);

virtual bool doRemoveService(const std::string& fcr_ident);

Expand Down
4 changes: 2 additions & 2 deletions xbmc/network/osx/ZeroconfOSX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool CZeroconfOSX::doPublishService(const std::string& fcr_identifier,
const std::string& fcr_type,
const std::string& fcr_name,
unsigned int f_port,
std::map<std::string, std::string> txt)
const std::vector<std::pair<std::string, std::string> >& txt)
{
CLog::Log(LOGDEBUG, "CZeroconfOSX::doPublishService identifier: %s type: %s name:%s port:%i", fcr_identifier.c_str(),
fcr_type.c_str(), fcr_name.c_str(), f_port);
Expand Down Expand Up @@ -74,7 +74,7 @@ bool CZeroconfOSX::doPublishService(const std::string& fcr_identifier,
//txt map to dictionary
CFDataRef txtData = NULL;
CFMutableDictionaryRef txtDict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
for(std::map<std::string, std::string>::const_iterator it = txt.begin(); it != txt.end(); ++it)
for(std::vector<std::pair<std::string, std::string> >::const_iterator it = txt.begin(); it != txt.end(); ++it)
{
CFStringRef key = CFStringCreateWithCString (NULL,
it->first.c_str(),
Expand Down
3 changes: 2 additions & 1 deletion xbmc/network/osx/ZeroconfOSX.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

#include <memory>
#include <vector>

#include "network/Zeroconf.h"
#include "threads/CriticalSection.h"
Expand All @@ -42,7 +43,7 @@ class CZeroconfOSX : public CZeroconf
const std::string& fcr_type,
const std::string& fcr_name,
unsigned int f_port,
std::map<std::string, std::string> txt);
const std::vector<std::pair<std::string, std::string> >& txt);

bool doRemoveService(const std::string& fcr_ident);

Expand Down
4 changes: 2 additions & 2 deletions xbmc/network/windows/ZeroconfWIN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool CZeroconfWIN::doPublishService(const std::string& fcr_identifier,
const std::string& fcr_type,
const std::string& fcr_name,
unsigned int f_port,
std::map<std::string, std::string> txt)
const std::vector<std::pair<std::string, std::string> >& txt)
{
DNSServiceRef netService = NULL;
TXTRecordRef txtRecord;
Expand All @@ -87,7 +87,7 @@ bool CZeroconfWIN::doPublishService(const std::string& fcr_identifier,
//add txt records
if(!txt.empty())
{
for(std::map<std::string, std::string>::const_iterator it = txt.begin(); it != txt.end(); ++it)
for(std::vector<std::pair<std::string, std::string> >::const_iterator it = txt.begin(); it != txt.end(); ++it)
{
CLog::Log(LOGDEBUG, "ZeroconfWIN: key:%s, value:%s",it->first.c_str(),it->second.c_str());
uint8_t txtLen = (uint8_t)strlen(it->second.c_str());
Expand Down
2 changes: 1 addition & 1 deletion xbmc/network/windows/ZeroconfWIN.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CZeroconfWIN : public CZeroconf
const std::string& fcr_type,
const std::string& fcr_name,
unsigned int f_port,
std::map<std::string, std::string> txt);
const std::vector<std::pair<std::string, std::string> >& txt);

bool doRemoveService(const std::string& fcr_ident);

Expand Down

0 comments on commit 25629fc

Please sign in to comment.