~dobey/ubuntu/precise/avahi/bring-back-gir

« back to all changes in this revision

Viewing changes to avahi-core/avahi-test.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2009-05-06 14:04:57 UTC
  • mfrom: (4.1.13 sid)
  • Revision ID: james.westby@ubuntu.com-20090506140457-72h3msg32nuc4j7v
Tags: 0.6.27-2ubuntu1
* Merge from Debian unstable, remaining Ubuntu changes:
* debian/control:
  - Remove linux-any as it is not yet supported by Soyuz
  - Add versioned dependency on the dbus that satisfies our upstart job
    dependency.
  - Add udebs corresponding to libavahi-common3 and libavahi-core6, so that
    we can use them for Eucalyptus integration in the installer.
  - Recommend dhcp3-client instead of isc-dhcp-client (not yet available in
    Ubuntu)
* debian/rules:
* debian/avahi-daemon.init:
* debian/avahi-dnsconfd.init:
  - Avahi init scripts (daemon or dnsconfd) do not need to
    be started before gdm, and do not need to be stopped specially on
    shutdown.
* debian/avahi-daemon.postinst:
* debian/avahi-dnsconfd.postinst:
  - Use Ubuntu versions for migration scripts
* debian/avahi-autoipd.preinst:
* debian/avahi-autoipd.install:
* debian/avahi-autoipd.postinst:
* debian/avahi-autoipd.postrm:
  - Disable DHCP 3 to 4 migration (not yet in Ubuntu)
* debian/avahi-daemon.upstart:
* debian/avahi-dnsconfd.upstart:
  - Add Upstart config
* debian/patches/03_gir_1.1.patch:
  - Compile with the latest Gobject introspection

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id$ */
2
 
 
3
1
/***
4
2
  This file is part of avahi.
5
 
 
 
3
 
6
4
  avahi is free software; you can redistribute it and/or modify it
7
5
  under the terms of the GNU Lesser General Public License as
8
6
  published by the Free Software Foundation; either version 2.1 of the
9
7
  License, or (at your option) any later version.
10
 
 
 
8
 
11
9
  avahi is distributed in the hope that it will be useful, but WITHOUT
12
10
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
11
  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14
12
  Public License for more details.
15
 
 
 
13
 
16
14
  You should have received a copy of the GNU Lesser General Public
17
15
  License along with avahi; if not, write to the Free Software
18
16
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
61
59
 
62
60
static void dump_timeout_callback(AvahiTimeout *timeout, void* userdata) {
63
61
    struct timeval tv;
64
 
    
 
62
 
65
63
    AvahiServer *avahi = userdata;
66
64
    avahi_server_dump(avahi, dump_line, NULL);
67
65
 
98
96
    AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
99
97
    AVAHI_GCC_UNUSED void* userdata) {
100
98
    char *t;
101
 
    
 
99
 
102
100
    assert(r);
103
101
 
104
102
    if (record) {
113
111
static void create_entries(int new_name);
114
112
 
115
113
static void entry_group_callback(AVAHI_GCC_UNUSED AvahiServer *s, AVAHI_GCC_UNUSED AvahiSEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void* userdata) {
116
 
    avahi_log_debug("entry group state: %i", state); 
 
114
    avahi_log_debug("entry group state: %i", state);
117
115
 
118
116
    if (state == AVAHI_ENTRY_GROUP_COLLISION) {
119
117
        remove_entries();
127
125
static void server_callback(AvahiServer *s, AvahiServerState state, AVAHI_GCC_UNUSED void* userdata) {
128
126
 
129
127
    server = s;
130
 
    avahi_log_debug("server state: %i", state); 
131
 
    
 
128
    avahi_log_debug("server state: %i", state);
 
129
 
132
130
    if (state == AVAHI_SERVER_RUNNING) {
133
131
        avahi_log_debug("Server startup complete. Host name is <%s>. Service cookie is %u", avahi_server_get_host_name_fqdn(s), avahi_server_get_local_service_cookie(s));
134
132
        create_entries(0);
155
153
 
156
154
    remove_entries();
157
155
 
158
 
    if (!group) 
 
156
    if (!group)
159
157
        group = avahi_s_entry_group_new(server, entry_group_callback, NULL);
160
158
 
161
159
    assert(avahi_s_entry_group_is_empty(group));
162
 
    
 
160
 
163
161
    if (!service_name)
164
162
        service_name = avahi_strdup("Test Service");
165
163
    else if (new_name) {
167
165
        avahi_free(service_name);
168
166
        service_name = n;
169
167
    }
170
 
    
 
168
 
171
169
    if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, service_name, "_http._tcp", NULL, NULL, 80, "foo", NULL) < 0) {
172
170
        avahi_log_error("Failed to add HTTP service");
173
171
        goto fail;
190
188
 
191
189
    r = avahi_record_new_full("cname.local", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_CNAME, AVAHI_DEFAULT_TTL);
192
190
    r->data.cname.name = avahi_strdup("cocaine.local");
193
 
    
 
191
 
194
192
    if (avahi_server_add(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, r) < 0) {
195
193
        avahi_record_unref(r);
196
194
        avahi_log_error("Failed to add CNAME record");
291
289
    const AvahiAddress *a,
292
290
    uint16_t port,
293
291
    AvahiStringList *txt,
294
 
    AVAHI_GCC_UNUSED AvahiLookupResultFlags flags, 
 
292
    AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
295
293
    AVAHI_GCC_UNUSED void* userdata) {
296
294
 
297
295
    if (event != AVAHI_RESOLVER_FOUND)
298
296
        avahi_log_debug("SR: (%i.%i) <%s> as %s in <%s> [%s]", iface, protocol, name, service_type, domain_name, resolver_event_to_string(event));
299
297
    else {
300
298
        char t[AVAHI_ADDRESS_STR_MAX], *s;
301
 
        
 
299
 
302
300
        avahi_address_snprint(t, sizeof(t), a);
303
301
 
304
302
        s = avahi_string_list_to_string(txt);
317
315
    uint16_t port,
318
316
    AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
319
317
    AVAHI_GCC_UNUSED void* userdata) {
320
 
    
 
318
 
321
319
    char t[AVAHI_ADDRESS_STR_MAX] = "n/a";
322
 
    
 
320
 
323
321
    if (a)
324
322
        avahi_address_snprint(t, sizeof(t), a);
325
323
 
344
342
 
345
343
    simple_poll = avahi_simple_poll_new();
346
344
    poll_api = avahi_simple_poll_get(simple_poll);
347
 
    
 
345
 
348
346
    avahi_server_config_init(&config);
349
347
 
350
348
    avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &config.wide_area_servers[0]);
353
351
 
354
352
    server = avahi_server_new(poll_api, &config, server_callback, NULL, &error);
355
353
    avahi_server_config_free(&config);
356
 
    
 
354
 
357
355
    k = avahi_key_new("_http._tcp.0pointer.de", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
358
356
    r = avahi_s_record_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, k, 0, record_browser_callback, NULL);
359
357
    avahi_key_unref(k);
389
387
    avahi_s_dns_server_browser_free(dsb);
390
388
 
391
389
    if (group)
392
 
        avahi_s_entry_group_free(group);   
 
390
        avahi_s_entry_group_free(group);
393
391
 
394
392
    if (server)
395
393
        avahi_server_free(server);
398
396
        avahi_simple_poll_free(simple_poll);
399
397
 
400
398
    avahi_free(service_name);
401
 
    
 
399
 
402
400
    return 0;
403
401
}