Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[linux/osx/ios] - retrieve the txt-records list from zeroconf announc…

…ments for later usage (share detection)
  • Loading branch information...
commit ec74a99dd87607c124fa40ba02cb73ff0a6bb12c 1 parent eedceeb
@Memphiz Memphiz authored
View
11 xbmc/network/ZeroconfBrowser.cpp
@@ -206,6 +206,17 @@ void CZeroconfBrowser::ZeroconfService::SetPort(int f_port)
m_port = f_port;
}
+void CZeroconfBrowser::ZeroconfService::SetTxtRecords(const tTxtRecordMap& txt_records)
+{
+ m_txtrecords_map = txt_records;
+
+ CLog::Log(LOGDEBUG,"CZeroconfBrowser: dump txt-records");
+ for(tTxtRecordMap::const_iterator it = m_txtrecords_map.begin(); it != m_txtrecords_map.end(); ++it)
+ {
+ CLog::Log(LOGDEBUG,"CZeroconfBrowser: key: %s value: %s",it->first.c_str(), it->second.c_str());
+ }
+}
+
CStdString CZeroconfBrowser::ZeroconfService::toPath(const ZeroconfService& fcr_service)
{
return CStdString(fcr_service.m_type + "@" + fcr_service.m_domain + "@" + fcr_service.m_name);
View
9 xbmc/network/ZeroconfBrowser.h
@@ -24,6 +24,7 @@
#include <string>
#include <set>
#include <vector>
+#include <map>
#include "URL.h"
//forwards
@@ -36,6 +37,8 @@ class CZeroconfBrowser
class ZeroconfService
{
public:
+ typedef std::map<std::string, std::string> tTxtRecordMap;
+
ZeroconfService();
ZeroconfService(const CStdString& fcr_name, const CStdString& fcr_type, const CStdString& fcr_domain);
@@ -64,6 +67,9 @@ class CZeroconfBrowser
void SetPort(int f_port);
int GetPort() const {return m_port;}
+
+ void SetTxtRecords(const tTxtRecordMap& txt_records);
+ const tTxtRecordMap& GetTxtRecords() const { return m_txtrecords_map;}
///@}
private:
//3 entries below identify a service
@@ -74,6 +80,9 @@ class CZeroconfBrowser
//2 entries below store 1 ip:port pair for this service
CStdString m_ip;
int m_port;
+
+ //1 entry below stores the txt-record as a key value map for this service
+ tTxtRecordMap m_txtrecords_map;
};
// starts browsing
View
29 xbmc/network/linux/ZeroconfBrowserAvahi.cpp
@@ -314,6 +314,33 @@ void CZeroconfBrowserAvahi::browseCallback (
}
}
+CZeroconfBrowser::ZeroconfService::tTxtRecordMap GetTxtRecords(AvahiStringList *txt)
+{
+ AvahiStringList *i = NULL;
+ CZeroconfBrowser::ZeroconfService::tTxtRecordMap recordMap;
+
+ for( i = txt; i; i = i->next )
+ {
+ char *key, *value;
+
+ if( avahi_string_list_get_pair( i, &key, &value, NULL ) < 0 )
+ continue;
+
+ recordMap.insert(
+ std::make_pair(
+ CStdString(key),
+ CStdString(value)
+ )
+ );
+
+ if( key )
+ avahi_free(key);
+ if( value )
+ avahi_free(value);
+ }
+ return recordMap;
+}
+
void CZeroconfBrowserAvahi::resolveCallback(
AvahiServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event,
const char *name, const char *type, const char *domain, const char *host_name,
@@ -335,6 +362,8 @@ void CZeroconfBrowserAvahi::resolveCallback(
avahi_address_snprint ( a, sizeof ( a ), address );
p_instance->m_resolving_service.SetIP(a);
p_instance->m_resolving_service.SetPort(port);
+ //get txt-record list
+ p_instance->m_resolving_service.SetTxtRecords(GetTxtRecords(txt));
break;
}
}
View
43 xbmc/network/osx/ZeroconfBrowserOSX.cpp
@@ -53,6 +53,47 @@ namespace
return myString;
}
+ //helper for getting a the txt-records list
+ //returns true on success, false if nothing found or error
+ CZeroconfBrowser::ZeroconfService::tTxtRecordMap GetTxtRecords(CFNetServiceRef serviceRef)
+ {
+ CFIndex idx = 0;
+ CZeroconfBrowser::ZeroconfService::tTxtRecordMap recordMap;
+ CFDataRef data = NULL;
+
+ data=CFNetServiceGetTXTData(serviceRef);
+ if( data != NULL )
+ {
+ CFDictionaryRef dict = NULL;
+ dict = CFNetServiceCreateDictionaryWithTXTData(kCFAllocatorDefault, data);
+
+ if( dict != NULL )
+ {
+ CFIndex numValues = 0;
+ numValues = CFDictionaryGetCount(dict);
+ if( numValues > 0)
+ {
+ CFStringRef keys[numValues];
+ CFDataRef values[numValues];
+
+ CFDictionaryGetKeysAndValues(dict, (const void **)&keys, (const void **)&values);
+
+ for(idx = 0; idx < numValues; idx++)
+ {
+ recordMap.insert(
+ std::make_pair(
+ CFStringToCStdString(keys[idx]),
+ CStdString((const char *)CFDataGetBytePtr(values[idx]))
+ )
+ );
+ }
+ }
+ CFRelease(dict);
+ }
+ }
+ return recordMap;
+ }
+
//helper to get (first) IP and port from a resolved service
//returns true on success, false on if none was found
bool CopyFirstIPv4Address(CFNetServiceRef serviceRef, CStdString& fr_address, int& fr_port)
@@ -313,6 +354,8 @@ bool CZeroconfBrowserOSX::doResolveService(CZeroconfBrowser::ZeroconfService& fr
ret = CopyFirstIPv4Address(service, ip, port);
fr_service.SetIP(ip);
fr_service.SetPort(port);
+ //get txt-record list
+ fr_service.SetTxtRecords(GetTxtRecords(service));
}
CFRelease(type);
CFRelease(name);
Please sign in to comment.
Something went wrong with that request. Please try again.