4 This file is part of avahi.
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.
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.
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
22 #include <sys/socket.h>
23 #include <arpa/inet.h>
25 #include <sys/utsname.h>
32 #include "subscribe.h"
34 static void free_entry(AvahiServer*s, AvahiEntry *e) {
40 avahi_goodbye_entry(s, e, TRUE);
42 /* Remove from linked list */
43 AVAHI_LLIST_REMOVE(AvahiEntry, entries, s->entries, e);
45 /* Remove from hash table indexed by name */
46 t = g_hash_table_lookup(s->entries_by_key, e->record->key);
47 AVAHI_LLIST_REMOVE(AvahiEntry, by_key, t, e);
49 g_hash_table_replace(s->entries_by_key, t->record->key, t);
51 g_hash_table_remove(s->entries_by_key, e->record->key);
53 /* Remove from associated group */
55 AVAHI_LLIST_REMOVE(AvahiEntry, by_group, e->group->entries, e);
57 avahi_record_unref(e->record);
61 static void free_group(AvahiServer *s, AvahiEntryGroup *g) {
66 free_entry(s, g->entries);
68 AVAHI_LLIST_REMOVE(AvahiEntryGroup, groups, s->groups, g);
72 static void cleanup_dead(AvahiServer *s) {
73 AvahiEntryGroup *g, *ng;
78 if (s->need_group_cleanup) {
79 for (g = s->groups; g; g = ng) {
86 s->need_group_cleanup = FALSE;
89 if (s->need_entry_cleanup) {
90 for (e = s->entries; e; e = ne) {
97 s->need_entry_cleanup = FALSE;
101 static void handle_query_key(AvahiServer *s, AvahiKey *k, AvahiInterface *i, const AvahiAddress *a, guint16 port, gboolean legacy_unicast, gboolean unicast_response) {
110 g_message("Handling query: %s", txt = avahi_key_to_string(k));
113 avahi_packet_scheduler_incoming_query(i->scheduler, k);
115 if (k->type == AVAHI_DNS_TYPE_ANY) {
117 /* Handle ANY query */
119 for (e = s->entries; e; e = e->entries_next)
120 if (!e->dead && avahi_key_pattern_match(k, e->record->key) && avahi_entry_registered(s, e, i))
121 avahi_interface_post_response(i, a, e->record, e->flags & AVAHI_ENTRY_UNIQUE, FALSE);
124 /* Handle all other queries */
126 for (e = g_hash_table_lookup(s->entries_by_key, k); e; e = e->by_key_next)
127 if (!e->dead && avahi_entry_registered(s, e, i))
128 avahi_interface_post_response(i, a, e->record, e->flags & AVAHI_ENTRY_UNIQUE, FALSE);
132 static void withdraw_entry(AvahiServer *s, AvahiEntry *e) {
140 for (k = e->group->entries; k; k = k->by_group_next) {
141 avahi_goodbye_entry(s, k, FALSE);
145 avahi_entry_group_change_state(e->group, AVAHI_ENTRY_GROUP_COLLISION);
147 avahi_goodbye_entry(s, e, FALSE);
151 s->need_entry_cleanup = TRUE;
154 static void incoming_probe(AvahiServer *s, AvahiRecord *record, AvahiInterface *i) {
162 t = avahi_record_to_string(record);
164 /* g_message("PROBE: [%s]", t); */
166 for (e = g_hash_table_lookup(s->entries_by_key, record->key); e; e = n) {
169 if (e->dead || avahi_record_equal_no_ttl(record, e->record))
172 if (avahi_entry_registering(s, e, i)) {
175 if ((cmp = avahi_record_lexicographical_compare(record, e->record)) > 0) {
176 withdraw_entry(s, e);
177 g_message("Recieved conflicting probe [%s]. Local host lost. Withdrawing.", t);
179 g_message("Recieved conflicting probe [%s]. Local host won.", t);
187 static void handle_query(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a, guint16 port, gboolean legacy_unicast) {
195 /* Handle the questions */
196 for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT); n > 0; n --) {
198 gboolean unicast_response = FALSE;
200 if (!(key = avahi_dns_packet_consume_key(p, &unicast_response))) {
201 g_warning("Packet too short (1)");
205 handle_query_key(s, key, i, a, port, legacy_unicast, unicast_response);
206 avahi_key_unref(key);
209 /* Known Answer Suppression */
210 for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT); n > 0; n --) {
212 gboolean unique = FALSE;
214 if (!(record = avahi_dns_packet_consume_record(p, &unique))) {
215 g_warning("Packet too short (2)");
219 avahi_packet_scheduler_incoming_known_answer(i->scheduler, record, a);
220 avahi_record_unref(record);
224 for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT); n > 0; n --) {
226 gboolean unique = FALSE;
228 if (!(record = avahi_dns_packet_consume_record(p, &unique))) {
229 g_warning("Packet too short (3)");
233 if (record->key->type != AVAHI_DNS_TYPE_ANY)
234 incoming_probe(s, record, i);
236 avahi_record_unref(record);
240 static gboolean handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord *record, gboolean unique, const AvahiAddress *a) {
241 gboolean valid = TRUE;
249 t = avahi_record_to_string(record);
251 /* g_message("CHECKING FOR CONFLICT: [%s]", t); */
253 for (e = g_hash_table_lookup(s->entries_by_key, record->key); e; e = n) {
259 if (avahi_entry_registered(s, e, i)) {
261 gboolean equal = avahi_record_equal_no_ttl(record, e->record);
263 /* Check whether there is a unique record conflict */
264 if (!equal && ((e->flags & AVAHI_ENTRY_UNIQUE) || unique)) {
267 /* The lexicographically later data wins. */
268 if ((cmp = avahi_record_lexicographical_compare(record, e->record)) > 0) {
269 g_message("Recieved conflicting record [%s]. Local host lost. Withdrawing.", t);
270 withdraw_entry(s, e);
271 } else if (cmp < 0) {
272 /* Tell the other host that our entry is lexicographically later */
274 g_message("Recieved conflicting record [%s]. Local host won. Refreshing.", t);
277 avahi_interface_post_response(i, a, e->record, e->flags & AVAHI_ENTRY_UNIQUE, TRUE);
280 /* Check wheter there is a TTL conflict */
281 } else if (equal && record->ttl <= e->record->ttl/2) {
282 /* Correct the TTL */
284 avahi_interface_post_response(i, a, e->record, e->flags & AVAHI_ENTRY_UNIQUE, TRUE);
285 g_message("Recieved record with bad TTL [%s]. Refreshing.", t);
288 } else if (avahi_entry_registering(s, e, i)) {
290 if (!avahi_record_equal_no_ttl(record, e->record) && ((e->flags & AVAHI_ENTRY_UNIQUE) || unique)) {
292 /* We are currently registering a matching record, but
293 * someone else already claimed it, so let's
296 g_message("Recieved conflicting record [%s] with local record to be. Withdrawing.", t);
297 withdraw_entry(s, e);
307 static void handle_response(AvahiServer *s, AvahiDnsPacket *p, AvahiInterface *i, const AvahiAddress *a) {
315 for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) +
316 avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ARCOUNT); n > 0; n--) {
318 gboolean cache_flush = FALSE;
321 if (!(record = avahi_dns_packet_consume_record(p, &cache_flush))) {
322 g_warning("Packet too short (4)");
326 if (record->key->type != AVAHI_DNS_TYPE_ANY) {
328 g_message("Handling response: %s", txt = avahi_record_to_string(record));
331 if (handle_conflict(s, i, record, cache_flush, a)) {
332 avahi_cache_update(i->cache, record, cache_flush, a);
333 avahi_packet_scheduler_incoming_response(i->scheduler, record);
337 avahi_record_unref(record);
341 static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, struct sockaddr *sa, gint iface, gint ttl) {
351 if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, sa->sa_family))) {
352 g_warning("Recieved packet from invalid interface.");
356 g_message("new packet recieved on interface '%s.%i'.", i->hardware->name, i->protocol);
358 if (sa->sa_family == AF_INET6) {
359 static const guint8 ipv4_in_ipv6[] = {
360 0x00, 0x00, 0x00, 0x00,
361 0x00, 0x00, 0x00, 0x00,
362 0xFF, 0xFF, 0xFF, 0xFF };
364 /* This is an IPv4 address encapsulated in IPv6, so let's ignore it. */
366 if (memcmp(((struct sockaddr_in6*) sa)->sin6_addr.s6_addr, ipv4_in_ipv6, sizeof(ipv4_in_ipv6)) == 0)
370 if (avahi_dns_packet_check_valid(p) < 0) {
371 g_warning("Recieved invalid packet.");
375 port = avahi_port_from_sockaddr(sa);
376 avahi_address_from_sockaddr(sa, &a);
378 if (avahi_dns_packet_is_query(p)) {
379 gboolean legacy_unicast = FALSE;
381 if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT) == 0 ||
382 avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ARCOUNT) != 0) {
383 g_warning("Invalid query packet.");
387 if (port != AVAHI_MDNS_PORT) {
390 if ((avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) != 0 ||
391 avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) != 0)) {
392 g_warning("Invalid legacy unicast query packet.");
396 legacy_unicast = TRUE;
399 handle_query(s, p, i, &a, port, legacy_unicast);
401 g_message("Handled query");
404 if (port != AVAHI_MDNS_PORT) {
405 g_warning("Recieved repsonse with invalid source port %u on interface '%s.%i'", port, i->hardware->name, i->protocol);
410 g_warning("Recieved response with invalid TTL %u on interface '%s.%i'.", ttl, i->hardware->name, i->protocol);
411 if (!s->ignore_bad_ttl)
415 if (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT) != 0 ||
416 avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) == 0 ||
417 avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) != 0) {
418 g_warning("Invalid response packet.");
422 handle_response(s, p, i, &a);
423 g_message("Handled response");
427 static void work(AvahiServer *s) {
428 struct sockaddr_in6 sa6;
429 struct sockaddr_in sa;
436 if (s->pollfd_ipv4.revents & G_IO_IN) {
437 if ((p = avahi_recv_dns_packet_ipv4(s->fd_ipv4, &sa, &iface, &ttl))) {
438 dispatch_packet(s, p, (struct sockaddr*) &sa, iface, ttl);
439 avahi_dns_packet_free(p);
443 if (s->pollfd_ipv6.revents & G_IO_IN) {
444 if ((p = avahi_recv_dns_packet_ipv6(s->fd_ipv6, &sa6, &iface, &ttl))) {
445 dispatch_packet(s, p, (struct sockaddr*) &sa6, iface, ttl);
446 avahi_dns_packet_free(p);
451 static gboolean prepare_func(GSource *source, gint *timeout) {
459 static gboolean check_func(GSource *source) {
463 s = *((AvahiServer**) (((guint8*) source) + sizeof(GSource)));
466 return (s->pollfd_ipv4.revents | s->pollfd_ipv6.revents) & (G_IO_IN | G_IO_HUP | G_IO_ERR);
469 static gboolean dispatch_func(GSource *source, GSourceFunc callback, gpointer user_data) {
473 s = *((AvahiServer**) (((guint8*) source) + sizeof(GSource)));
482 static void add_default_entries(AvahiServer *s) {
483 struct utsname utsname;
489 /* Fill in HINFO rr */
490 r = avahi_record_new_full(s->hostname, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_HINFO);
492 r->data.hinfo.cpu = g_strdup(g_strup(utsname.machine));
493 r->data.hinfo.os = g_strdup(g_strup(utsname.sysname));
494 avahi_server_add(s, NULL, 0, AF_UNSPEC, AVAHI_ENTRY_UNIQUE, r);
495 avahi_record_unref(r);
497 /* Add localhost entries */
498 avahi_address_parse("127.0.0.1", AF_INET, &a);
499 avahi_server_add_address(s, NULL, 0, AF_UNSPEC, AVAHI_ENTRY_UNIQUE|AVAHI_ENTRY_NOPROBE|AVAHI_ENTRY_NOANNOUNCE, "localhost", &a);
501 avahi_address_parse("::1", AF_INET6, &a);
502 avahi_server_add_address(s, NULL, 0, AF_UNSPEC, AVAHI_ENTRY_UNIQUE|AVAHI_ENTRY_NOPROBE|AVAHI_ENTRY_NOANNOUNCE, "ip6-localhost", &a);
505 AvahiServer *avahi_server_new(GMainContext *c) {
509 static GSourceFuncs source_funcs = {
518 s = g_new(AvahiServer, 1);
520 s->ignore_bad_ttl = FALSE;
521 s->need_entry_cleanup = s->need_group_cleanup = FALSE;
523 s->fd_ipv4 = avahi_open_socket_ipv4();
524 s->fd_ipv6 = avahi_open_socket_ipv6();
526 if (s->fd_ipv6 < 0 && s->fd_ipv4 < 0) {
527 g_critical("Failed to create IP sockets.\n");
533 g_message("Failed to create IPv4 socket, proceeding in IPv6 only mode");
534 else if (s->fd_ipv6 < 0)
535 g_message("Failed to create IPv6 socket, proceeding in IPv4 only mode");
538 g_main_context_ref(s->context = c);
540 s->context = g_main_context_default();
542 AVAHI_LLIST_HEAD_INIT(AvahiEntry, s->entries);
543 s->entries_by_key = g_hash_table_new((GHashFunc) avahi_key_hash, (GEqualFunc) avahi_key_equal);
544 AVAHI_LLIST_HEAD_INIT(AvahiGroup, s->groups);
546 AVAHI_LLIST_HEAD_INIT(AvahiSubscription, s->subscriptions);
547 s->subscription_hashtable = g_hash_table_new((GHashFunc) avahi_key_hash, (GEqualFunc) avahi_key_equal);
550 hn = avahi_get_host_name();
551 hn[strcspn(hn, ".")] = 0;
553 s->hostname = g_strdup_printf("%s.local.", hn);
556 s->time_event_queue = avahi_time_event_queue_new(s->context, G_PRIORITY_DEFAULT+10); /* Slightly less priority than the FDs */
557 s->monitor = avahi_interface_monitor_new(s);
558 avahi_interface_monitor_sync(s->monitor);
559 add_default_entries(s);
561 /* Prepare IO source registration */
562 s->source = g_source_new(&source_funcs, sizeof(GSource) + sizeof(AvahiServer*));
563 *((AvahiServer**) (((guint8*) s->source) + sizeof(GSource))) = s;
565 memset(&s->pollfd_ipv4, 0, sizeof(s->pollfd_ipv4));
566 s->pollfd_ipv4.fd = s->fd_ipv4;
567 s->pollfd_ipv4.events = G_IO_IN|G_IO_ERR|G_IO_HUP;
568 g_source_add_poll(s->source, &s->pollfd_ipv4);
570 memset(&s->pollfd_ipv6, 0, sizeof(s->pollfd_ipv6));
571 s->pollfd_ipv6.fd = s->fd_ipv6;
572 s->pollfd_ipv6.events = G_IO_IN|G_IO_ERR|G_IO_HUP;
573 g_source_add_poll(s->source, &s->pollfd_ipv6);
575 g_source_attach(s->source, s->context);
580 void avahi_server_free(AvahiServer* s) {
584 free_entry(s, s->entries);
586 avahi_interface_monitor_free(s->monitor);
589 free_group(s, s->groups);
591 while (s->subscriptions)
592 avahi_subscription_free(s->subscriptions);
593 g_hash_table_destroy(s->subscription_hashtable);
595 g_hash_table_destroy(s->entries_by_key);
597 avahi_time_event_queue_free(s->time_event_queue);
606 g_source_destroy(s->source);
607 g_source_unref(s->source);
608 g_main_context_unref(s->context);
613 void avahi_server_add(
618 AvahiEntryFlags flags,
625 g_assert(r->key->type != AVAHI_DNS_TYPE_ANY);
627 e = g_new(AvahiEntry, 1);
629 e->record = avahi_record_ref(r);
631 e->interface = interface;
632 e->protocol = protocol;
636 AVAHI_LLIST_HEAD_INIT(AvahiAnnouncement, e->announcements);
638 AVAHI_LLIST_PREPEND(AvahiEntry, entries, s->entries, e);
640 /* Insert into hash table indexed by name */
641 t = g_hash_table_lookup(s->entries_by_key, e->record->key);
642 AVAHI_LLIST_PREPEND(AvahiEntry, by_key, t, e);
643 g_hash_table_replace(s->entries_by_key, e->record->key, t);
645 /* Insert into group list */
647 AVAHI_LLIST_PREPEND(AvahiEntry, by_group, g->entries, e);
649 avahi_announce_entry(s, e);
651 const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiEntryGroup *g, void **state) {
652 AvahiEntry **e = (AvahiEntry**) state;
657 *e = g ? g->entries : s->entries;
659 while (*e && (*e)->dead)
660 *e = g ? (*e)->by_group_next : (*e)->entries_next;
665 return avahi_record_ref((*e)->record);
668 void avahi_server_dump(AvahiServer *s, FILE *f) {
673 fprintf(f, "\n;;; ZONE DUMP FOLLOWS ;;;\n");
675 for (e = s->entries; e; e = e->entries_next) {
681 t = avahi_record_to_string(e->record);
682 fprintf(f, "%s ; iface=%i proto=%i\n", t, e->interface, e->protocol);
686 avahi_dump_caches(s->monitor, f);
689 void avahi_server_add_ptr(
694 AvahiEntryFlags flags,
702 r = avahi_record_new_full(name ? name : s->hostname, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
703 r->data.ptr.name = avahi_normalize_name(dest);
704 avahi_server_add(s, g, interface, protocol, flags, r);
705 avahi_record_unref(r);
708 void avahi_server_add_address(
713 AvahiEntryFlags flags,
721 name = name ? (n = avahi_normalize_name(name)) : s->hostname;
723 if (a->family == AF_INET) {
727 r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A);
728 r->data.a.address = a->data.ipv4;
729 avahi_server_add(s, g, interface, protocol, flags, r);
730 avahi_record_unref(r);
732 reverse = avahi_reverse_lookup_name_ipv4(&a->data.ipv4);
734 avahi_server_add_ptr(s, g, interface, protocol, flags, reverse, name);
741 r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA);
742 r->data.aaaa.address = a->data.ipv6;
743 avahi_server_add(s, g, interface, protocol, flags, r);
744 avahi_record_unref(r);
746 reverse = avahi_reverse_lookup_name_ipv6_arpa(&a->data.ipv6);
748 avahi_server_add_ptr(s, g, interface, protocol, flags, reverse, name);
751 reverse = avahi_reverse_lookup_name_ipv6_int(&a->data.ipv6);
753 avahi_server_add_ptr(s, g, interface, protocol, flags, reverse, name);
760 void avahi_server_add_text_strlst(
765 AvahiEntryFlags flags,
767 AvahiStringList *strlst) {
773 r = avahi_record_new_full(name ? name : s->hostname, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_TXT);
774 r->data.txt.string_list = strlst;
775 avahi_server_add(s, g, interface, protocol, flags, r);
776 avahi_record_unref(r);
779 void avahi_server_add_text_va(
784 AvahiEntryFlags flags,
790 avahi_server_add_text_strlst(s, g, interface, protocol, flags, name, avahi_string_list_new_va(va));
793 void avahi_server_add_text(
798 AvahiEntryFlags flags,
807 avahi_server_add_text_va(s, g, interface, protocol, flags, name, va);
811 static void escape_service_name(gchar *d, guint size, const gchar *s) {
816 while (*s && size >= 2) {
817 if (*s == '.' || *s == '\\') {
833 void avahi_server_add_service_strlst(
843 AvahiStringList *strlst) {
845 gchar ptr_name[256], svc_name[256], ename[64], enum_ptr[256];
852 escape_service_name(ename, sizeof(ename), name);
855 while (domain[0] == '.')
863 snprintf(ptr_name, sizeof(ptr_name), "%s.%s", type, domain);
864 snprintf(svc_name, sizeof(svc_name), "%s.%s.%s", ename, type, domain);
866 avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, ptr_name, svc_name);
868 r = avahi_record_new_full(svc_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV);
869 r->data.srv.priority = 0;
870 r->data.srv.weight = 0;
871 r->data.srv.port = port;
872 r->data.srv.name = avahi_normalize_name(host);
873 avahi_server_add(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, r);
874 avahi_record_unref(r);
876 avahi_server_add_text_strlst(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, svc_name, strlst);
878 snprintf(enum_ptr, sizeof(enum_ptr), "_services._dns-sd._udp.%s", domain);
879 avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, enum_ptr, ptr_name);
882 void avahi_server_add_service_va(
898 avahi_server_add_service(s, g, interface, protocol, type, name, domain, host, port, avahi_string_list_new_va(va));
901 void avahi_server_add_service(
920 avahi_server_add_service_va(s, g, interface, protocol, type, name, domain, host, port, va);
924 static void post_query_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata) {
925 AvahiKey *k = userdata;
931 avahi_interface_post_query(i, k, FALSE);
934 void avahi_server_post_query(AvahiServer *s, gint interface, guchar protocol, AvahiKey *key) {
938 avahi_interface_monitor_walk(s->monitor, interface, protocol, post_query_callback, key);
943 gboolean flush_cache;
946 static void post_response_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata) {
947 struct tmpdata *tmpdata = userdata;
953 avahi_interface_post_response(i, NULL, tmpdata->record, tmpdata->flush_cache, FALSE);
956 void avahi_server_post_response(AvahiServer *s, gint interface, guchar protocol, AvahiRecord *record, gboolean flush_cache) {
957 struct tmpdata tmpdata;
962 tmpdata.record = record;
963 tmpdata.flush_cache = flush_cache;
965 avahi_interface_monitor_walk(s->monitor, interface, protocol, post_response_callback, &tmpdata);
968 void avahi_entry_group_change_state(AvahiEntryGroup *g, AvahiEntryGroupState state) {
974 g->callback(g->server, g, state, g->userdata);
979 AvahiEntryGroup *avahi_entry_group_new(AvahiServer *s, AvahiEntryGroupCallback callback, gpointer userdata) {
984 g = g_new(AvahiEntryGroup, 1);
986 g->callback = callback;
987 g->userdata = userdata;
989 g->state = AVAHI_ENTRY_GROUP_UNCOMMITED;
991 AVAHI_LLIST_HEAD_INIT(AvahiEntry, g->entries);
993 AVAHI_LLIST_PREPEND(AvahiEntryGroup, groups, s->groups, g);
997 void avahi_entry_group_free(AvahiEntryGroup *g) {
1002 g->server->need_group_cleanup = TRUE;
1005 void avahi_entry_group_commit(AvahiEntryGroup *g) {
1009 if (g->state != AVAHI_ENTRY_GROUP_UNCOMMITED)
1012 avahi_entry_group_change_state(g, AVAHI_ENTRY_GROUP_REGISTERING);
1013 avahi_announce_group(g->server, g);
1014 avahi_entry_group_check_probed(g, FALSE);
1017 gboolean avahi_entry_commited(AvahiEntry *e) {
1022 e->group->state == AVAHI_ENTRY_GROUP_REGISTERING ||
1023 e->group->state == AVAHI_ENTRY_GROUP_ESTABLISHED;
1026 AvahiEntryGroupState avahi_entry_group_get_state(AvahiEntryGroup *g) {