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



commit f4092fe842e1a2c211b527aed4ad8e5a96e28089
Author: W. Michael Petullo <mike flyn org>
Date:   Sat Feb 7 20:41:47 2015 -0500

    DNSSD backend: Always send TXT record Password=true or false, as iTunes 12.1.0.50 requires this
    
    Signed-off-by: W. Michael Petullo <mike flyn org>

 libdmapsharing/dmap-mdns-publisher-dnssd.c |   64 +++++++++++++++++++++++++---
 1 files changed, 57 insertions(+), 7 deletions(-)
---
diff --git a/libdmapsharing/dmap-mdns-publisher-dnssd.c b/libdmapsharing/dmap-mdns-publisher-dnssd.c
index 9edb93d..6898c2b 100644
--- a/libdmapsharing/dmap-mdns-publisher-dnssd.c
+++ b/libdmapsharing/dmap-mdns-publisher-dnssd.c
@@ -19,6 +19,7 @@
 #include "config.h"
 
 #include <stdio.h>
+#include <string.h>
 #include <glib.h>
 #include <dns_sd.h>
 #include <arpa/inet.h>
@@ -65,6 +66,49 @@ dmap_mdns_publisher_rename_at_port (DMAPMdnsPublisher *publisher,
         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
 dmap_mdns_publisher_publish (DMAPMdnsPublisher *publisher,
                              const char          *name,
@@ -74,11 +118,13 @@ dmap_mdns_publisher_publish (DMAPMdnsPublisher *publisher,
                             gchar              **txt_records,
                              GError             **error)
 {
+       gboolean fnval = TRUE;
+       uint16_t txt_len = 0;
+       char *txt_record = NULL;
        int dns_err;
 
-       /* FIXME: does not do anything with txt_records yet */
-       if (txt_records != NULL)
-               g_warning ("dmap_mdns_publisher_publish() can not handle txt_records yet");
+       /* TODO: Unify txt_records and password_required to simplify build_txt_...? */
+       txt_record = _build_txt_record(password_required, txt_records, &txt_len);
 
        g_warning ("%s %s %d", name, type_of_service, port);
        if ((dns_err = DNSServiceRegister (&publisher->priv->sdref,
@@ -89,8 +135,8 @@ dmap_mdns_publisher_publish (DMAPMdnsPublisher *publisher,
                NULL,
                NULL,
                htons (port),
-               0,
-               NULL,
+               txt_len,
+               txt_record,
                NULL,
                NULL)) != kDNSServiceErr_NoError) {
                 g_set_error (error,
@@ -101,12 +147,16 @@ dmap_mdns_publisher_publish (DMAPMdnsPublisher *publisher,
                if (dns_err == kDNSServiceErr_NameConflict) {
                        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);
 
-        return TRUE;
+done:
+       g_free(txt_record);
+
+        return fnval;
 }
 
 gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]