Commit 78322364 authored by W. Michael Petullo's avatar W. Michael Petullo

Implement fine-grained service withdrawl

Signed-off-by: W. Michael Petullo's avatarW. Michael Petullo <mike@flyn.org>
parent 7071bbd5
Fix DNSSD on Mac OS X
Complete DACP code and push Rhythmbox patch
Reduce the memory usage while building response to media list query.
......
......@@ -217,20 +217,30 @@ refresh_services (DmapMdnsPublisher *publisher,
return create_services (publisher, error);
}
static struct DmapMdnsPublisherService *
find_service_by_port (GSList *list, guint port)
{
GSList *ptr;
for (ptr = list; ptr; ptr = g_slist_next (ptr)) {
if (port == ((struct DmapMdnsPublisherService *) ptr->data)->port)
break;
}
return ptr ? ptr->data : NULL;
}
gboolean
dmap_mdns_publisher_rename_at_port (DmapMdnsPublisher *publisher,
guint port,
const char *name,
GError **error)
{
GSList *ptr;
struct DmapMdnsPublisherService *ptr;
g_return_val_if_fail (publisher != NULL, FALSE);
for (ptr = publisher->priv->service; ptr; ptr = g_slist_next (ptr)) {
if (port == ((struct DmapMdnsPublisherService *) ptr->data)->port)
break;
}
ptr = find_service_by_port (publisher->priv->service, port);
if (ptr == NULL) {
g_set_error (error,
......@@ -241,8 +251,8 @@ dmap_mdns_publisher_rename_at_port (DmapMdnsPublisher *publisher,
return FALSE;
}
g_free (((struct DmapMdnsPublisherService *) ptr->data)->name);
((struct DmapMdnsPublisherService *) ptr->data)->name = g_strdup (name);
g_free (ptr->name);
ptr->name = g_strdup (name);
if (publisher->priv->entry_group) {
refresh_services (publisher, error);
......@@ -285,10 +295,21 @@ dmap_mdns_publisher_publish (DmapMdnsPublisher *publisher,
return create_services (publisher, error);
}
static void
free_service (struct DmapMdnsPublisherService *service, gpointer user_data)
{
g_free (service->name);
g_free (service->type_of_service);
g_strfreev (service->txt_records);
}
gboolean
dmap_mdns_publisher_withdraw (DmapMdnsPublisher *publisher,
GError **error)
guint port,
GError **error)
{
struct DmapMdnsPublisherService *ptr;
if (publisher->priv->client == NULL) {
g_set_error (error,
DMAP_MDNS_PUBLISHER_ERROR,
......@@ -298,7 +319,8 @@ dmap_mdns_publisher_withdraw (DmapMdnsPublisher *publisher,
return FALSE;
}
if (publisher->priv->entry_group == NULL) {
if (publisher->priv->entry_group == NULL
|| ! (ptr = find_service_by_port (publisher->priv->service, port))) {
g_set_error (error,
DMAP_MDNS_PUBLISHER_ERROR,
DMAP_MDNS_PUBLISHER_ERROR_FAILED,
......@@ -307,9 +329,18 @@ dmap_mdns_publisher_withdraw (DmapMdnsPublisher *publisher,
return FALSE;
}
avahi_entry_group_reset (publisher->priv->entry_group);
avahi_entry_group_free (publisher->priv->entry_group);
publisher->priv->entry_group = NULL;
free_service (ptr, NULL);
publisher->priv->service = g_slist_remove (publisher->priv->service, ptr);
if (publisher->priv->service == NULL) {
avahi_entry_group_reset (publisher->priv->entry_group);
avahi_entry_group_free (publisher->priv->entry_group);
publisher->priv->entry_group = NULL;
} else {
create_services (publisher, error);
if (error != NULL)
return FALSE;
}
return TRUE;
}
......@@ -402,14 +433,6 @@ dmap_mdns_publisher_init (DmapMdnsPublisher *publisher)
publisher->priv->service = NULL;
}
static void
free_service (struct DmapMdnsPublisherService *service, gpointer user_data)
{
g_free (service->name);
g_free (service->type_of_service);
g_strfreev (service->txt_records);
}
static void
dmap_mdns_publisher_finalize (GObject *object)
{
......
......@@ -82,7 +82,8 @@ gboolean dmap_mdns_publisher_rename_at_port (DmapMdnsPublish
const char *name,
GError **error);
gboolean dmap_mdns_publisher_withdraw (DmapMdnsPublisher *publisher,
GError **error);
guint port,
GError **error);
G_END_DECLS
......
......@@ -359,7 +359,7 @@ _dmap_share_publish_stop (DMAPShare *share)
gboolean res;
GError *error;
error = NULL;
res = dmap_mdns_publisher_withdraw (share->priv->publisher, &error);
res = dmap_mdns_publisher_withdraw (share->priv->publisher, share->priv->port, &error);
if (error != NULL) {
g_warning ("Unable to withdraw music sharing service: %s", error->message);
g_error_free (error);
......
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