]> git.meshlink.io Git - catta/blob - avahi-core/update-test.c
* do no longer include timeval.h in watch.h by default
[catta] / avahi-core / update-test.c
1 /* $Id$ */
2
3 /***
4   This file is part of avahi.
5  
6   avahi is free software; you can redistribute it and/or modify it
7   under the terms of the GNU Lesser General Public License as
8   published by the Free Software Foundation; either version 2.1 of the
9   License, or (at your option) any later version.
10  
11   avahi is distributed in the hope that it will be useful, but WITHOUT
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14   Public License for more details.
15  
16   You should have received a copy of the GNU Lesser General Public
17   License along with avahi; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19   USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <assert.h>
27
28 #include <avahi-common/error.h>
29 #include <avahi-common/watch.h>
30 #include <avahi-common/simple-watch.h>
31 #include <avahi-common/malloc.h>
32 #include <avahi-common/alternative.h>
33 #include <avahi-common/timeval.h>
34
35 #include <avahi-core/core.h>
36 #include <avahi-core/log.h>
37 #include <avahi-core/publish.h>
38 #include <avahi-core/lookup.h>
39
40 static AvahiSEntryGroup *group = NULL;
41
42 static void server_callback(AvahiServer *s, AvahiServerState state, void* userdata) {
43
44     avahi_log_debug("server state: %i", state); 
45     
46     if (state == AVAHI_SERVER_RUNNING) {
47         int ret;
48         
49         group = avahi_s_entry_group_new(s, NULL, NULL);
50         assert(group);
51
52         ret = avahi_server_add_service(s, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "foo", "_http._tcp", NULL, NULL, 80, "test1", NULL);
53         assert(ret == AVAHI_OK);
54
55         avahi_s_entry_group_commit(group);
56     }
57 }
58
59 static void modify_txt_callback(AvahiTimeout *e, void *userdata) {
60     int ret;
61     AvahiServer *s = userdata;
62
63     ret = avahi_server_update_service_txt(s, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "foo", "_http._tcp", NULL, "test2", NULL);
64     assert(ret == AVAHI_OK);
65 }
66
67 int main(int argc, char *argv[]) {
68     AvahiSimplePoll *simple_poll;
69     const AvahiPoll *poll_api;
70     AvahiServer *server;
71     struct timeval tv;
72     AvahiServerConfig config;
73
74     simple_poll = avahi_simple_poll_new();
75     assert(simple_poll);
76     
77     poll_api = avahi_simple_poll_get(simple_poll);
78     assert(poll_api);
79
80     avahi_server_config_init(&config);
81     config.publish_domain = config.publish_workstation = config.use_ipv6 = config.publish_hinfo = 0;
82     server = avahi_server_new(poll_api, &config, server_callback, NULL, NULL);
83     assert(server);
84     avahi_server_config_free(&config);
85
86     poll_api->timeout_new(poll_api, avahi_elapse_time(&tv, 1000*20, 0), modify_txt_callback, server);
87
88     avahi_simple_poll_loop(simple_poll);
89 }