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