Mercurial > audlegacy-plugins
annotate src/daap/xmms2-daap/daap_mdns_avahi.c @ 3174:8106e1b31115
alsa-ng: alsaplug_written_time(), alsaplug_output_time(): Lock pcm_state_mutex.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Fri, 15 May 2009 16:12:30 -0500 |
parents | 7b3290336f3b |
children |
rev | line source |
---|---|
1407
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
1 /** @file daap_mdns_browse.c |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
2 * Browser for DAAP servers shared via mDNS. |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
3 * |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
4 * Copyright (C) 2006-2007 XMMS2 Team |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
5 * |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
6 * This program is free software; you can redistribute it and/or |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
7 * modify it under the terms of the GNU General Public License |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
8 * as published by the Free Software Foundation; either version 2 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
9 * of the License, or (at your option) any later version. |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
10 * |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
14 * GNU General Public License for more details. |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
15 */ |
1448 | 16 #ifdef DAAP_MDNS_AVAHI |
1407
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
17 #include "daap_mdns_browse.h" |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
18 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
19 #include <string.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
20 #include <glib.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
21 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
22 #include <avahi-client/client.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
23 #include <avahi-client/lookup.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
24 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
25 #include <avahi-common/malloc.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
26 #include <avahi-common/error.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
27 #include <avahi-common/timeval.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
28 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
29 #include <avahi-glib/glib-watch.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
30 #include <avahi-glib/glib-malloc.h> |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
31 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
32 #define ADDR_LEN (3 * 4 + 3 + 1) /* standard dotted-quad fmt */ |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
33 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
34 typedef struct { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
35 AvahiClient *client; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
36 GMainLoop *mainloop; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
37 } browse_callback_userdata_t; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
38 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
39 static GSList *g_server_list = NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
40 static GStaticMutex serv_list_mut = G_STATIC_MUTEX_INIT; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
41 static AvahiGLibPoll *gl_poll = NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
42 static AvahiClient *client = NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
43 static AvahiServiceBrowser *browser = NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
44 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
45 static GSList * |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
46 daap_mdns_serv_remove (GSList *serv_list, gchar *addr, guint port) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
47 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
48 GSList *first = serv_list; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
49 daap_mdns_server_t *serv; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
50 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
51 for ( ; serv_list != NULL; serv_list = g_slist_next (serv_list)) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
52 serv = (daap_mdns_server_t *) serv_list->data; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
53 if ( (port == serv->port) && (!strcmp (addr, serv->address)) ) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
54 serv_list = g_slist_remove (first, serv); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
55 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
56 g_free (serv->server_name); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
57 g_free (serv->mdns_hostname); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
58 g_free (serv->address); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
59 g_free (serv); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
60 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
61 return serv_list; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
62 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
63 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
64 return NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
65 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
66 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
67 static void |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
68 daap_mdns_resolve_cb (AvahiServiceResolver *resolv, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
69 AvahiIfIndex iface, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
70 AvahiProtocol proto, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
71 AvahiResolverEvent event, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
72 const gchar *name, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
73 const gchar *type, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
74 const gchar *domain, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
75 const gchar *hostname, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
76 const AvahiAddress *addr, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
77 guint16 port, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
78 AvahiStringList *text, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
79 AvahiLookupResultFlags flags, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
80 void *userdata) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
81 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
82 gboolean *remove = userdata; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
83 gchar ad[ADDR_LEN]; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
84 daap_mdns_server_t *server; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
85 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
86 if (!resolv) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
87 return; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
88 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
89 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
90 switch (event) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
91 case AVAHI_RESOLVER_FOUND: |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
92 server = (daap_mdns_server_t *) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
93 g_malloc0 (sizeof (daap_mdns_server_t)); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
94 avahi_address_snprint (ad, sizeof (ad), addr); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
95 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
96 server->server_name = g_strdup (name); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
97 server->address = g_strdup (ad); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
98 server->mdns_hostname = g_strdup (hostname); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
99 server->port = port; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
100 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
101 if (*remove) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
102 g_static_mutex_lock (&serv_list_mut); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
103 g_server_list = daap_mdns_serv_remove (g_server_list, ad, port); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
104 g_static_mutex_unlock (&serv_list_mut); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
105 } else { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
106 g_static_mutex_lock (&serv_list_mut); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
107 g_server_list = g_slist_prepend (g_server_list, server); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
108 g_static_mutex_unlock (&serv_list_mut); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
109 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
110 g_free (remove); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
111 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
112 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
113 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
114 case AVAHI_RESOLVER_FAILURE: |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
115 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
116 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
117 default: |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
118 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
119 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
120 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
121 avahi_service_resolver_free (resolv); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
122 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
123 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
124 static void |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
125 daap_mdns_browse_cb (AvahiServiceBrowser *browser, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
126 AvahiIfIndex iface, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
127 AvahiProtocol proto, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
128 AvahiBrowserEvent event, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
129 const gchar *name, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
130 const gchar *type, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
131 const gchar *domain, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
132 AvahiLookupResultFlags flags, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
133 void *userdata) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
134 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
135 gboolean ok = FALSE; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
136 gboolean *b = g_malloc (sizeof (gboolean)); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
137 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
138 AvahiClient *client = ((browse_callback_userdata_t *) userdata)->client; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
139 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
140 if (!browser) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
141 return; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
142 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
143 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
144 switch (event) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
145 case AVAHI_BROWSER_NEW: |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
146 *b = FALSE; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
147 ok = (gboolean) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
148 avahi_service_resolver_new (client, iface, proto, name, type, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
149 domain, AVAHI_PROTO_UNSPEC, 0, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
150 daap_mdns_resolve_cb, b); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
151 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
152 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
153 case AVAHI_BROWSER_REMOVE: |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
154 *b = TRUE; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
155 ok = (gboolean) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
156 avahi_service_resolver_new (client, iface, proto, name, type, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
157 domain, AVAHI_PROTO_UNSPEC, 0, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
158 daap_mdns_resolve_cb, b); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
159 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
160 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
161 case AVAHI_BROWSER_CACHE_EXHAUSTED: |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
162 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
163 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
164 case AVAHI_BROWSER_ALL_FOR_NOW: |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
165 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
166 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
167 default: |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
168 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
169 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
170 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
171 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
172 static void |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
173 daap_mdns_client_cb (AvahiClient *client, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
174 AvahiClientState state, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
175 void * userdata) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
176 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
177 if (!client) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
178 return; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
179 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
180 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
181 switch (state) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
182 case AVAHI_CLIENT_FAILURE: |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
183 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
184 default: |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
185 break; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
186 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
187 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
188 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
189 static void |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
190 daap_mdns_timeout (AvahiTimeout *to, void *userdata) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
191 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
192 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
193 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
194 static gboolean |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
195 daap_mdns_timeout_glib (void *userdata) |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
196 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
197 return FALSE; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
198 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
199 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
200 gboolean |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
201 daap_mdns_initialize () |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
202 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
203 const AvahiPoll *av_poll; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
204 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
205 GMainLoop *ml = NULL; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
206 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
207 gboolean ok = TRUE; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
208 gint errval; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
209 struct timeval tv; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
210 browse_callback_userdata_t *browse_userdata; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
211 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
212 if (gl_poll) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
213 ok = FALSE; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
214 goto fail; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
215 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
216 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
217 browse_userdata = g_malloc0 (sizeof (browse_callback_userdata_t)); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
218 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
219 avahi_set_allocator (avahi_glib_allocator ()); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
220 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
221 ml = g_main_loop_new (NULL, FALSE); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
222 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
223 gl_poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
224 av_poll = avahi_glib_poll_get (gl_poll); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
225 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
226 avahi_elapse_time (&tv, 2000, 0); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
227 av_poll->timeout_new (av_poll, &tv, daap_mdns_timeout, NULL); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
228 g_timeout_add (5000, daap_mdns_timeout_glib, ml); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
229 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
230 client = avahi_client_new (av_poll, 0, daap_mdns_client_cb, ml, &errval); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
231 if (!client) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
232 ok = FALSE; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
233 goto fail; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
234 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
235 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
236 browse_userdata->client = client; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
237 browse_userdata->mainloop = ml; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
238 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
239 browser = avahi_service_browser_new (client, AVAHI_IF_UNSPEC, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
240 AVAHI_PROTO_UNSPEC, "_daap._tcp", NULL, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
241 0, daap_mdns_browse_cb, |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
242 browse_userdata); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
243 if (!browser) { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
244 ok = FALSE; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
245 goto fail; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
246 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
247 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
248 fail: |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
249 return ok; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
250 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
251 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
252 GSList * |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
253 daap_mdns_get_server_list () |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
254 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
255 GSList * l; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
256 g_static_mutex_lock (&serv_list_mut); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
257 l = g_slist_copy (g_server_list); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
258 g_static_mutex_unlock (&serv_list_mut); |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
259 return l; |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
260 } |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
261 |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
262 void |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
263 daap_mdns_destroy () |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
264 { |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
265 /* FIXME: deinit avahi */ |
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
266 } |
1448 | 267 #endif |
1407
776dd8fc2b38
DAAP plugin (work in progress)
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff
changeset
|
268 |