Commit f4092fe8 authored by W. Michael Petullo's avatar W. Michael Petullo
Browse files

DNSSD backend: Always send TXT record Password=true or false, as iTunes 12.1.0.50 requires this


Signed-off-by: W. Michael Petullo's avatarW. Michael Petullo <mike@flyn.org>
parent a2d8b2f2
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <glib.h> #include <glib.h>
#include <dns_sd.h> #include <dns_sd.h>
#include <arpa/inet.h> #include <arpa/inet.h>
...@@ -65,6 +66,49 @@ dmap_mdns_publisher_rename_at_port (DMAPMdnsPublisher *publisher, ...@@ -65,6 +66,49 @@ dmap_mdns_publisher_rename_at_port (DMAPMdnsPublisher *publisher,
return TRUE; return TRUE;
} }
static gchar *
_build_txt_record(gboolean password_required, gchar **txt_records, uint16_t *txt_len)
{
*txt_len = 0;
gchar **_txt_records;
for (_txt_records = txt_records; _txt_records && *_txt_records; _txt_records++) {
*txt_len += strlen(*_txt_records) + 1; // + 1 for req. len.
_txt_records++;
}
char password_size = 0;
if(TRUE == password_required) {
password_size = (char) strlen("Password=true") + 1;
} else {
password_size = (char) strlen("Password=false") + 1;
}
*txt_len += password_size;
size_t i = 0;
gchar *txt_record = g_malloc(*txt_len);
for (; txt_records && *txt_records; txt_records++) {
size_t len = strlen(*txt_records);
g_assert(len <= ~(char)0);
txt_record[i++] = (char)len;
memcpy(txt_record + i, *txt_records, len);
i += len;
}
txt_record[i++] = password_size - 1;
if(TRUE == password_required) {
strcpy(txt_record + i, "Password=true");
} else {
strcpy(txt_record + i, "Password=false");
}
return txt_record;
}
gboolean gboolean
dmap_mdns_publisher_publish (DMAPMdnsPublisher *publisher, dmap_mdns_publisher_publish (DMAPMdnsPublisher *publisher,
const char *name, const char *name,
...@@ -74,11 +118,13 @@ dmap_mdns_publisher_publish (DMAPMdnsPublisher *publisher, ...@@ -74,11 +118,13 @@ dmap_mdns_publisher_publish (DMAPMdnsPublisher *publisher,
gchar **txt_records, gchar **txt_records,
GError **error) GError **error)
{ {
gboolean fnval = TRUE;
uint16_t txt_len = 0;
char *txt_record = NULL;
int dns_err; int dns_err;
/* FIXME: does not do anything with txt_records yet */ /* TODO: Unify txt_records and password_required to simplify build_txt_...? */
if (txt_records != NULL) txt_record = _build_txt_record(password_required, txt_records, &txt_len);
g_warning ("dmap_mdns_publisher_publish() can not handle txt_records yet");
g_warning ("%s %s %d", name, type_of_service, port); g_warning ("%s %s %d", name, type_of_service, port);
if ((dns_err = DNSServiceRegister (&publisher->priv->sdref, if ((dns_err = DNSServiceRegister (&publisher->priv->sdref,
...@@ -89,8 +135,8 @@ dmap_mdns_publisher_publish (DMAPMdnsPublisher *publisher, ...@@ -89,8 +135,8 @@ dmap_mdns_publisher_publish (DMAPMdnsPublisher *publisher,
NULL, NULL,
NULL, NULL,
htons (port), htons (port),
0, txt_len,
NULL, txt_record,
NULL, NULL,
NULL)) != kDNSServiceErr_NoError) { NULL)) != kDNSServiceErr_NoError) {
g_set_error (error, g_set_error (error,
...@@ -101,12 +147,16 @@ dmap_mdns_publisher_publish (DMAPMdnsPublisher *publisher, ...@@ -101,12 +147,16 @@ dmap_mdns_publisher_publish (DMAPMdnsPublisher *publisher,
if (dns_err == kDNSServiceErr_NameConflict) { if (dns_err == kDNSServiceErr_NameConflict) {
g_signal_emit (publisher, signals[NAME_COLLISION], 0, publisher->priv->name); g_signal_emit (publisher, signals[NAME_COLLISION], 0, publisher->priv->name);
} }
return FALSE; fnval = FALSE;
goto done;
} }
g_signal_emit (publisher, signals[PUBLISHED], 0, publisher->priv->name); g_signal_emit (publisher, signals[PUBLISHED], 0, publisher->priv->name);
return TRUE; done:
g_free(txt_record);
return fnval;
} }
gboolean gboolean
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment