1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/* $Id$ */
/***
This file is part of avahi.
avahi is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
avahi is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with avahi; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <avahi-client/client.h>
#include <avahi-common/dbus.h>
#include <avahi-common/llist.h>
#include <avahi-common/error.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <stdlib.h>
#include "client.h"
#include "internal.h"
/* AvahiDomainBrowser */
AvahiDomainBrowser* avahi_domain_browser_new (AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, char *domain, AvahiDomainBrowserType btype, AvahiDomainBrowserCallback callback, void *user_data)
{
AvahiDomainBrowser *tmp = NULL;
DBusMessage *message = NULL, *reply;
DBusError error;
char *path;
if (client == NULL)
return NULL;
dbus_error_init (&error);
message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER,
AVAHI_DBUS_INTERFACE_SERVER, "DomainBrowserNew");
if (!dbus_message_append_args (message, DBUS_TYPE_INT32, &interface, DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INT32, &btype, DBUS_TYPE_INVALID))
goto dbus_error;
reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error);
if (dbus_error_is_set (&error) || reply == NULL)
goto dbus_error;
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID))
goto dbus_error;
if (dbus_error_is_set (&error) || path == NULL)
goto dbus_error;
tmp = malloc (sizeof (AvahiDomainBrowser));
tmp->client = client;
tmp->callback = callback;
tmp->user_data = user_data;
tmp->path = strdup (path);
AVAHI_LLIST_PREPEND(AvahiDomainBrowser, domain_browsers, client->domain_browsers, tmp);
return tmp;
dbus_error:
dbus_error_free (&error);
avahi_client_set_errno (client, AVAHI_ERR_DBUS_ERROR);
return NULL;
}
char*
avahi_domain_browser_path (AvahiDomainBrowser *b)
{
return b->path;
}
DBusHandlerResult
avahi_domain_browser_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message)
{
AvahiDomainBrowser *n, *db = NULL;
DBusError error;
const char *path;
char *domain;
int interface, protocol;
dbus_error_init (&error);
path = dbus_message_get_path (message);
if (path == NULL)
goto out;
for (n = client->domain_browsers; n != NULL; n = n->domain_browsers_next)
{
printf ("cmp: %s, %s\n", n->path, path);
if (strcmp (n->path, path) == 0) {
db = n;
break;
}
}
if (db == NULL)
goto out;
dbus_message_get_args (message, &error, DBUS_TYPE_INT32, &interface,
DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INVALID);
if (dbus_error_is_set (&error))
goto out;
db->callback (db, interface, protocol, event, domain, db->user_data);
return DBUS_HANDLER_RESULT_HANDLED;
out:
dbus_error_free (&error);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
/* AvahiServiceTypeBrowser */
AvahiServiceTypeBrowser* avahi_service_type_browser_new (AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, char *domain, AvahiServiceTypeBrowserCallback callback, void *user_data)
{
AvahiServiceTypeBrowser *tmp = NULL;
DBusMessage *message = NULL, *reply;
DBusError error;
char *path;
if (client == NULL)
return NULL;
dbus_error_init (&error);
message = dbus_message_new_method_call (AVAHI_DBUS_NAME,
AVAHI_DBUS_PATH_SERVER,
AVAHI_DBUS_INTERFACE_SERVER,
"ServiceTypeBrowserNew");
if (!dbus_message_append_args (message, DBUS_TYPE_INT32, &interface, DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INVALID))
goto dbus_error;
reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error);
if (dbus_error_is_set (&error) || reply == NULL)
goto dbus_error;
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID))
goto dbus_error;
if (dbus_error_is_set (&error) || path == NULL)
goto dbus_error;
tmp = malloc (sizeof (AvahiServiceTypeBrowser));
tmp->client = client;
tmp->callback = callback;
tmp->user_data = user_data;
tmp->path = strdup (path);
AVAHI_LLIST_PREPEND(AvahiServiceTypeBrowser, service_type_browsers, client->service_type_browsers, tmp);
return tmp;
dbus_error:
dbus_error_free (&error);
avahi_client_set_errno (client, AVAHI_ERR_DBUS_ERROR);
return NULL;
}
char*
avahi_service_type_browser_path (AvahiServiceTypeBrowser *b)
{
return b->path;
}
DBusHandlerResult
avahi_service_type_browser_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message)
{
AvahiServiceTypeBrowser *n, *db = NULL;
DBusError error;
const char *path;
char *domain, *type;
int interface, protocol;
dbus_error_init (&error);
path = dbus_message_get_path (message);
if (path == NULL)
goto out;
for (n = client->service_type_browsers; n != NULL; n = n->service_type_browsers_next)
{
printf ("cmp: %s, %s\n", n->path, path);
if (strcmp (n->path, path) == 0) {
db = n;
break;
}
}
if (db == NULL)
goto out;
dbus_message_get_args (message, &error,
DBUS_TYPE_INT32, &interface,
DBUS_TYPE_INT32, &protocol,
DBUS_TYPE_STRING, &type,
DBUS_TYPE_STRING, &domain,
DBUS_TYPE_INVALID);
if (dbus_error_is_set (&error))
goto out;
db->callback (db, interface, protocol, event, type, domain, db->user_data);
return DBUS_HANDLER_RESULT_HANDLED;
out:
dbus_error_free (&error);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
|