components/avahi/patches/03-entry.patch
changeset 5257 0da26ce015ab
equal deleted inserted replaced
5256:1c3e20e70cc3 5257:0da26ce015ab
       
     1 Source: Desktop consolidation
       
     2 Upstream promotion status: unknown
       
     3 
       
     4 --- /usr/tmp/clean/avahi-0.6.28/avahi-core/entry.c	2010-08-26 01:51:38.985153000 +0100
       
     5 +++ avahi-0.6.28/avahi-core/entry.c	2011-01-20 12:01:24.322248863 +0000
       
     6 @@ -50,6 +50,33 @@
       
     7  #include "rr-util.h"
       
     8  #include "domain-util.h"
       
     9  
       
    10 +#ifdef HAVE_BONJOUR
       
    11 +
       
    12 +struct AvahiService {
       
    13 +    AvahiServer *server;
       
    14 +    AvahiSEntryGroup *group;
       
    15 +
       
    16 +    int dead;
       
    17 +
       
    18 +    AvahiPublishFlags flags;
       
    19 +    AvahiIfIndex interface;
       
    20 +    AvahiProtocol protocol;
       
    21 +
       
    22 +    char *name;
       
    23 +    char *type;
       
    24 +    char *domain;
       
    25 +    char *host;
       
    26 +    uint16_t port;
       
    27 +
       
    28 +    AvahiWatch *watch;
       
    29 +    DNSServiceRef client;
       
    30 +    size_t txtlen;
       
    31 +    uint8_t *txtrecord;
       
    32 +
       
    33 +    AVAHI_LLIST_FIELDS(AvahiService, services);
       
    34 +};
       
    35 +#endif
       
    36 +
       
    37  static void transport_flags_from_domain(AvahiServer *s, AvahiPublishFlags *flags, const char *domain) {
       
    38      assert(flags);
       
    39      assert(domain);
       
    40 @@ -69,13 +96,146 @@
       
    41          *flags |= AVAHI_PUBLISH_USE_WIDE_AREA;
       
    42  }
       
    43  
       
    44 +#ifdef HAVE_BONJOUR
       
    45 +static void register_service_reply(DNSServiceRef client, const DNSServiceFlags flags, DNSServiceErrorType errorCode,
       
    46 +        const char *name, const char *regtype, const char *domain, void *context) {
       
    47 +    AvahiService *as = context;
       
    48 +
       
    49 +    switch (errorCode) {
       
    50 +        case kDNSServiceErr_NoError:
       
    51 +            as->group->n_probing--;
       
    52 +            if (as->group->n_probing == 0) {
       
    53 +                avahi_s_entry_group_change_state(as->group, AVAHI_ENTRY_GROUP_ESTABLISHED);
       
    54 +            }
       
    55 +            break;
       
    56 +        case kDNSServiceErr_NameConflict:
       
    57 +            avahi_s_entry_group_change_state(as->group, AVAHI_ENTRY_GROUP_COLLISION);
       
    58 +            break;
       
    59 +        default: 
       
    60 +            avahi_s_entry_group_change_state(as->group, AVAHI_ENTRY_GROUP_FAILURE);
       
    61 +    }
       
    62 +}
       
    63 +
       
    64 +static void register_service_socket_event(AvahiWatch *w, int fd, AvahiWatchEvent events, void *userdata) {
       
    65 +    AvahiService *as = userdata;
       
    66 +    DNSServiceErrorType ret;
       
    67 +
       
    68 +    assert(w);
       
    69 +    assert(fd >= 0);
       
    70 +    assert(events & AVAHI_WATCH_IN);
       
    71 +
       
    72 +    assert (fd == DNSServiceRefSockFD(as->client));
       
    73 +    ret = DNSServiceProcessResult(as->client);
       
    74 +    if (ret != kDNSServiceErr_NoError) {
       
    75 +        if (as->watch) {
       
    76 +            as->server->poll_api->watch_free(as->watch);
       
    77 +            as->watch = NULL;
       
    78 +        }
       
    79 +        DNSServiceRefDeallocate(as->client);
       
    80 +        as->client = NULL;
       
    81 +        avahi_s_entry_group_change_state(as->group, AVAHI_ENTRY_GROUP_FAILURE);
       
    82 +    }
       
    83 +}
       
    84 +
       
    85 +static void avahi_service_free(AvahiServer*s, AvahiService *as) {
       
    86 +    AvahiService *t;
       
    87 +
       
    88 +    assert(s);
       
    89 +    assert(as);
       
    90 +
       
    91 +    /* Remove from linked list */
       
    92 +    AVAHI_LLIST_REMOVE(AvahiService, services, s->services, as);
       
    93 +
       
    94 +    /* Remove from associated group */
       
    95 +    if (as->group && (as->group->services != NULL))
       
    96 +        AVAHI_LLIST_REMOVE(AvahiService, services, as->group->services, as);
       
    97 +
       
    98 +    if (as->name)
       
    99 +        avahi_free(as->name);
       
   100 +
       
   101 +    if (as->type)
       
   102 +        avahi_free(as->type);
       
   103 +
       
   104 +    if (as->domain)
       
   105 +        avahi_free(as->domain);
       
   106 +
       
   107 +    if (as->host)
       
   108 +        avahi_free(as->host);
       
   109 +
       
   110 +    if (as->watch)
       
   111 +        s->poll_api->watch_free(as->watch);
       
   112 +    
       
   113 +    if (as->client)
       
   114 +        DNSServiceRefDeallocate (as->client);
       
   115 +
       
   116 +    if (as->txtrecord)
       
   117 +        avahi_free(as->txtrecord);
       
   118 +
       
   119 +    avahi_free(as);
       
   120 +}
       
   121 +
       
   122 +static void avahi_register_service(AvahiServer *s, AvahiService *as) {
       
   123 +    DNSServiceErrorType ret;
       
   124 +
       
   125 +    ret = DNSServiceRegister(&as->client, 
       
   126 +              as->interface == AVAHI_IF_UNSPEC ? 
       
   127 +                  kDNSServiceInterfaceIndexAny :
       
   128 +                  as->interface,
       
   129 +              0, 
       
   130 +              as->name,
       
   131 +              as->type,
       
   132 +              as->domain,
       
   133 +              as->host,
       
   134 +              htons(as->port),
       
   135 +              as->txtlen,
       
   136 +              as->txtrecord,
       
   137 +              register_service_reply,
       
   138 +              as);
       
   139 +    if (ret == kDNSServiceErr_NoError) {
       
   140 +        if  (!as->client) {
       
   141 +            avahi_s_entry_group_change_state(as->group, AVAHI_ENTRY_GROUP_FAILURE);
       
   142 +        } else {
       
   143 +            as->group->n_probing++;
       
   144 +            as->watch = s->poll_api->watch_new(s->poll_api, DNSServiceRefSockFD(as->client), AVAHI_WATCH_IN, register_service_socket_event, as);
       
   145 +        } 
       
   146 +    } else {
       
   147 +        if (ret == kDNSServiceErr_NameConflict) {
       
   148 +            avahi_s_entry_group_change_state(as->group, AVAHI_ENTRY_GROUP_COLLISION);
       
   149 +        }
       
   150 +        else {
       
   151 +            avahi_s_entry_group_change_state(as->group, AVAHI_ENTRY_GROUP_FAILURE);
       
   152 +        }
       
   153 +    }
       
   154 +}
       
   155 +
       
   156 +static void register_record_reply(DNSServiceRef client, DNSRecordRef recordref, const DNSServiceFlags flags, DNSServiceErrorType errorCode, void *context) {
       
   157 +    AvahiEntry *e = context;
       
   158 +    DNSServiceErrorType ret;
       
   159 +    
       
   160 +    switch (errorCode) {
       
   161 +        case kDNSServiceErr_NoError:
       
   162 +            break;
       
   163 +        case kDNSServiceErr_NameConflict:
       
   164 +            e->recordref = NULL;
       
   165 +            avahi_server_set_errno(e->server, AVAHI_ERR_COLLISION);
       
   166 +            break;
       
   167 +        default: 
       
   168 +            e->recordref = NULL;
       
   169 +            avahi_server_set_errno(e->server, AVAHI_ERR_FAILURE);
       
   170 +            break;
       
   171 +    }
       
   172 +}
       
   173 +#endif
       
   174 +
       
   175  void avahi_entry_free(AvahiServer*s, AvahiEntry *e) {
       
   176      AvahiEntry *t;
       
   177  
       
   178      assert(s);
       
   179      assert(e);
       
   180  
       
   181 +#ifndef HAVE_BONJOUR
       
   182      avahi_goodbye_entry(s, e, 1, 1);
       
   183 +#endif
       
   184  
       
   185      /* Remove from linked list */
       
   186      AVAHI_LLIST_REMOVE(AvahiEntry, entries, s->entries, e);
       
   187 @@ -102,6 +262,15 @@
       
   188  
       
   189      while (g->entries)
       
   190          avahi_entry_free(s, g->entries);
       
   191 +#ifdef HAVE_BONJOUR
       
   192 +    while (g->services)
       
   193 +        avahi_service_free(s, g->services);
       
   194 +
       
   195 +    if (g->record_connection) {
       
   196 +        DNSServiceRefDeallocate(g->record_connection);
       
   197 +        g->record_connection = NULL;
       
   198 +    }
       
   199 +#endif
       
   200  
       
   201      if (g->register_time_event)
       
   202          avahi_time_event_free(g->register_time_event);
       
   203 @@ -139,6 +308,21 @@
       
   204          s->need_entry_cleanup = 0;
       
   205      }
       
   206  
       
   207 +#ifdef HAVE_BONJOUR
       
   208 +    if (s->need_service_cleanup) {
       
   209 +        AvahiService *as, *next;
       
   210 +
       
   211 +        for (as = s->services; as; as = next) {
       
   212 +            next = as->services_next;
       
   213 +
       
   214 +            if (as->dead)
       
   215 +                avahi_service_free(s, as);
       
   216 +        }
       
   217 +
       
   218 +        s->need_service_cleanup = 0;
       
   219 +    }
       
   220 +#endif
       
   221 +
       
   222      if (s->need_browser_cleanup)
       
   223          avahi_browser_cleanup(s);
       
   224  
       
   225 @@ -245,8 +429,54 @@
       
   226  
       
   227          /* Hmm, nothing found? */
       
   228          if (!e) {
       
   229 +#ifdef HAVE_BONJOUR
       
   230 +            /*
       
   231 +             * Assume that we are updating a service's primary TXT record
       
   232 +             * so find the service
       
   233 +             */
       
   234 +            DNSServiceErrorType ret;
       
   235 +            uint16_t rlen;
       
   236 +            uint8_t rdata[AVAHI_DNS_RDATA_MAX];
       
   237 +            size_t l;
       
   238 +            AvahiService *as;
       
   239 +            int found_as = 0;
       
   240 +
       
   241 +            for (as = g->services; as; as = as->services_next) {
       
   242 +                int a_ret = AVAHI_OK;
       
   243 +                char svc_name[AVAHI_DOMAIN_NAME_MAX];
       
   244 +
       
   245 +                if ((a_ret = avahi_service_name_join(svc_name, sizeof(svc_name), as->name, as->type, as->domain ? as->domain : s->domain_name)) < 0) {
       
   246 +                      avahi_server_set_errno(s, a_ret);
       
   247 +                      return NULL;
       
   248 +                }
       
   249 +                if (!strcmp(svc_name, r->key->name)) {
       
   250 +                    found_as = 1;
       
   251 +                    break;
       
   252 +                }
       
   253 +            }
       
   254 +
       
   255 +            if (!found_as) {
       
   256 +                avahi_server_set_errno(s, AVAHI_ERR_NOT_FOUND);
       
   257 +                return NULL;
       
   258 +            }
       
   259 +            if ((l = avahi_rdata_serialize(r, rdata, sizeof(rdata))) == (size_t) -1) {
       
   260 +                avahi_server_set_errno(s, AVAHI_ERR_FAILURE);
       
   261 +                return NULL;
       
   262 +            }
       
   263 +            ret = DNSServiceUpdateRecord(as->client,
       
   264 +                                         NULL,
       
   265 +                                         0,
       
   266 +                                         l,
       
   267 +                                         rdata,
       
   268 +                                         r->ttl);
       
   269 +            if (ret != kDNSServiceErr_NoError) {
       
   270 +                avahi_server_set_errno(s, AVAHI_ERR_FAILURE);
       
   271 +            }
       
   272 +            return NULL;
       
   273 +#else
       
   274              avahi_server_set_errno(s, AVAHI_ERR_NOT_FOUND);
       
   275              return NULL;
       
   276 +#endif
       
   277          }
       
   278  
       
   279          /* Update the entry */
       
   280 @@ -256,6 +486,36 @@
       
   281  
       
   282          /* Announce our changes when needed */
       
   283          if (!avahi_record_equal_no_ttl(old_record, r) && (!g || g->state != AVAHI_ENTRY_GROUP_UNCOMMITED)) {
       
   284 +#ifdef HAVE_BONJOUR
       
   285 +            DNSServiceErrorType ret;
       
   286 +            uint16_t rlen;
       
   287 +            uint8_t rdata[AVAHI_DNS_RDATA_MAX];
       
   288 +            size_t l;
       
   289 +
       
   290 +            if (!g->record_connection) {
       
   291 +                if (DNSServiceCreateConnection(&g->record_connection) != kDNSServiceErr_NoError) {
       
   292 +                    avahi_entry_free(s, e);
       
   293 +                    avahi_server_set_errno(s, AVAHI_ERR_FAILURE);
       
   294 +                    return NULL;
       
   295 +                }
       
   296 +            }
       
   297 +            if ((l = avahi_rdata_serialize(r, rdata, sizeof(rdata))) == (size_t) -1) {
       
   298 +                avahi_entry_free(s, e);
       
   299 +                avahi_server_set_errno(s, AVAHI_ERR_FAILURE);
       
   300 +                return NULL;
       
   301 +            }
       
   302 +            ret = DNSServiceUpdateRecord(g->record_connection,
       
   303 +                                         e->recordref,
       
   304 +                                         0,
       
   305 +                                         l,
       
   306 +                                         rdata,
       
   307 +                                         r->ttl);
       
   308 +            if (ret != kDNSServiceErr_NoError) {
       
   309 +                avahi_entry_free(s, e);
       
   310 +                avahi_server_set_errno(s, AVAHI_ERR_FAILURE);
       
   311 +                return NULL;
       
   312 +            }
       
   313 +#else
       
   314  
       
   315              /* Remove the old entry from all caches, if needed */
       
   316              if (!(e->flags & AVAHI_PUBLISH_UNIQUE))
       
   317 @@ -263,6 +523,7 @@
       
   318  
       
   319              /* Reannounce our updated entry */
       
   320              avahi_reannounce_entry(s, e);
       
   321 +#endif
       
   322          }
       
   323  
       
   324          /* If we were the first entry in the list, we need to update the key */
       
   325 @@ -273,6 +534,14 @@
       
   326  
       
   327      } else {
       
   328          AvahiEntry *t;
       
   329 +#ifdef HAVE_BONJOUR
       
   330 +        DNSServiceErrorType ret;
       
   331 +        DNSServiceFlags bflags;
       
   332 +        uint16_t rlen;
       
   333 +        uint8_t rdata[AVAHI_DNS_RDATA_MAX];
       
   334 +        size_t l;
       
   335 +        char *record_name;
       
   336 +#endif
       
   337  
       
   338          /* Add a new record */
       
   339  
       
   340 @@ -307,7 +576,69 @@
       
   341          if (g)
       
   342              AVAHI_LLIST_PREPEND(AvahiEntry, by_group, g->entries, e);
       
   343  
       
   344 +#ifdef HAVE_BONJOUR
       
   345 +        e->recordref = NULL;
       
   346 +        if (!g->record_connection) {
       
   347 +            if (DNSServiceCreateConnection(&g->record_connection) != kDNSServiceErr_NoError) {
       
   348 +                avahi_entry_free(s, e);
       
   349 +                avahi_server_set_errno(s, AVAHI_ERR_FAILURE);
       
   350 +                return NULL;
       
   351 +            }
       
   352 +        }
       
   353 +        bflags = 0;
       
   354 +        if (flags & AVAHI_PUBLISH_ALLOW_MULTIPLE)
       
   355 +            bflags |= kDNSServiceFlagsShared;
       
   356 +        else
       
   357 +            bflags |= kDNSServiceFlagsUnique;
       
   358 +
       
   359 +        switch (r->key->type) {
       
   360 +            case AVAHI_DNS_TYPE_A:
       
   361 +            case AVAHI_DNS_TYPE_AAAA:
       
   362 +                record_name = avahi_strdup(r->key->name);
       
   363 +                break;
       
   364 +            default:
       
   365 +                record_name = avahi_malloc(strlen(r->key->name) + strlen(s->host_name_fqdn) + 2);
       
   366 +                strcpy(record_name, r->key->name);
       
   367 +                strcat(record_name, ".");
       
   368 +                strcat(record_name, s->host_name_fqdn);
       
   369 +                break;
       
   370 +        }
       
   371 +
       
   372 +        if ((l = avahi_rdata_serialize(r, rdata, sizeof(rdata))) == (size_t) -1) {
       
   373 +            avahi_entry_free(s, e);
       
   374 +            avahi_server_set_errno(s, AVAHI_ERR_FAILURE);
       
   375 +            return NULL;
       
   376 +        }
       
   377 +
       
   378 +        ret = DNSServiceRegisterRecord(g->record_connection,
       
   379 +                  &e->recordref,
       
   380 +                  bflags,
       
   381 +                  interface == AVAHI_IF_UNSPEC ?
       
   382 +                      kDNSServiceInterfaceIndexAny :
       
   383 +                      interface,
       
   384 +                  record_name,
       
   385 +                  r->key->type,
       
   386 +                  r->key->clazz,
       
   387 +                  l,
       
   388 +                  rdata,
       
   389 +                  r->ttl,
       
   390 +                  register_record_reply,
       
   391 +                  e);
       
   392 +        if (ret == kDNSServiceErr_NoError) {
       
   393 +            ret = DNSServiceProcessResult(g->record_connection);
       
   394 +            if (ret != kDNSServiceErr_NoError || e->recordref == NULL) {
       
   395 +                avahi_entry_free(s, e);
       
   396 +                return NULL;
       
   397 +            }
       
   398 +        } else {
       
   399 +            avahi_entry_free(s, e);
       
   400 +            avahi_server_set_errno(s, AVAHI_ERR_FAILURE);
       
   401 +            return NULL;
       
   402 +        }
       
   403 +        avahi_free(record_name);
       
   404 +#else
       
   405          avahi_announce_entry(s, e);
       
   406 +#endif
       
   407      }
       
   408  
       
   409      return e;
       
   410 @@ -583,6 +914,9 @@
       
   411      AvahiRecord *r = NULL;
       
   412      int ret = AVAHI_OK;
       
   413      AvahiEntry *srv_entry = NULL, *txt_entry = NULL, *ptr_entry = NULL, *enum_entry = NULL;
       
   414 +#ifdef HAVE_BONJOUR
       
   415 +    AvahiService *as;
       
   416 +#endif
       
   417  
       
   418      assert(s);
       
   419      assert(type);
       
   420 @@ -603,6 +937,36 @@
       
   421      if (!domain)
       
   422          domain = s->domain_name;
       
   423  
       
   424 +#ifdef HAVE_BONJOUR
       
   425 +    as = avahi_new (AvahiService, 1);
       
   426 +    as->server = s;
       
   427 +    as->group = g;
       
   428 +    as->dead = 0;
       
   429 +    as->flags = flags;
       
   430 +    as->interface = interface;
       
   431 +    as->protocol = protocol;
       
   432 +    as->name = avahi_strdup(name);
       
   433 +    as->type = avahi_strdup(type);
       
   434 +    as->domain = avahi_strdup(domain);
       
   435 +    as->host = avahi_strdup(host);
       
   436 +    as->port = port;
       
   437 +    as->watch = NULL;
       
   438 +    as->client = NULL;
       
   439 +    as->txtlen = avahi_string_list_serialize(strlst, NULL, 0);
       
   440 +    if (as->txtlen > 0) {
       
   441 +        as->txtrecord = avahi_new(uint8_t, as->txtlen);
       
   442 +        if (as->txtrecord == NULL) {
       
   443 +            as->txtlen = 0;
       
   444 +            ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
       
   445 +            goto fail;
       
   446 +        }
       
   447 +        avahi_string_list_serialize(strlst, as->txtrecord, as->txtlen);
       
   448 +    } else
       
   449 +        as->txtrecord = NULL;
       
   450 +
       
   451 +    AVAHI_LLIST_PREPEND(AvahiService, services, s->services, as);
       
   452 +    AVAHI_LLIST_PREPEND(AvahiService, services, g->services, as);
       
   453 +#else
       
   454      if (!host)
       
   455          host = s->host_name_fqdn;
       
   456  
       
   457 @@ -667,6 +1031,7 @@
       
   458          ret = avahi_server_errno(s);
       
   459          goto fail;
       
   460      }
       
   461 +#endif
       
   462  
       
   463  fail:
       
   464      if (ret != AVAHI_OK && !(flags & AVAHI_PUBLISH_UPDATE)) {
       
   465 @@ -1013,7 +1378,11 @@
       
   466      if (g->state == state)
       
   467          return;
       
   468  
       
   469 +#ifdef HAVE_BONJOUR
       
   470 +    assert(state <= AVAHI_ENTRY_GROUP_FAILURE);
       
   471 +#else
       
   472      assert(state <= AVAHI_ENTRY_GROUP_COLLISION);
       
   473 +#endif
       
   474  
       
   475      if (g->state == AVAHI_ENTRY_GROUP_ESTABLISHED) {
       
   476  
       
   477 @@ -1063,6 +1432,10 @@
       
   478      g->register_time.tv_sec = 0;
       
   479      g->register_time.tv_usec = 0;
       
   480      AVAHI_LLIST_HEAD_INIT(AvahiEntry, g->entries);
       
   481 +#ifdef HAVE_BONJOUR
       
   482 +    AVAHI_LLIST_HEAD_INIT(AvahiService, g->services);
       
   483 +    g->record_connection = NULL;
       
   484 +#endif
       
   485  
       
   486      AVAHI_LLIST_PREPEND(AvahiSEntryGroup, groups, s->groups, g);
       
   487      return g;
       
   488 @@ -1087,16 +1460,26 @@
       
   489  
       
   490  void avahi_s_entry_group_free(AvahiSEntryGroup *g) {
       
   491      AvahiEntry *e;
       
   492 +#ifdef HAVE_BONJOUR
       
   493 +    AvahiService *s;
       
   494 +#endif
       
   495  
       
   496      assert(g);
       
   497      assert(g->server);
       
   498  
       
   499      for (e = g->entries; e; e = e->by_group_next) {
       
   500          if (!e->dead) {
       
   501 +#ifndef HAVE_BONJOUR
       
   502              avahi_goodbye_entry(g->server, e, 1, 1);
       
   503 +#endif
       
   504              e->dead = 1;
       
   505          }
       
   506      }
       
   507 +#ifdef HAVE_BONJOUR
       
   508 +    for (s = g->services; s; s = s->services_next) {
       
   509 +        s->dead = 1;
       
   510 +    }
       
   511 +#endif
       
   512  
       
   513      if (g->register_time_event) {
       
   514          avahi_time_event_free(g->register_time_event);
       
   515 @@ -1107,11 +1490,17 @@
       
   516  
       
   517      g->server->need_group_cleanup = 1;
       
   518      g->server->need_entry_cleanup = 1;
       
   519 +#ifdef HAVE_BONJOUR
       
   520 +    g->server->need_service_cleanup = 1;
       
   521 +#endif
       
   522  
       
   523      schedule_cleanup(g->server);
       
   524  }
       
   525  
       
   526  static void entry_group_commit_real(AvahiSEntryGroup *g) {
       
   527 +#ifdef HAVE_BONJOUR
       
   528 +    AvahiService *s;
       
   529 +#endif
       
   530      assert(g);
       
   531  
       
   532      gettimeofday(&g->register_time, NULL);
       
   533 @@ -1121,8 +1510,15 @@
       
   534      if (g->dead)
       
   535          return;
       
   536  
       
   537 +#ifdef HAVE_BONJOUR
       
   538 +    assert(g->server);
       
   539 +    for (s = g->services; s; s = s->services_next)
       
   540 +        if (!s->dead)
       
   541 +            avahi_register_service(g->server, s);
       
   542 +#else
       
   543      avahi_announce_group(g->server, g);
       
   544      avahi_s_entry_group_check_probed(g, 0);
       
   545 +#endif
       
   546  }
       
   547  
       
   548  static void entry_group_register_time_event_callback(AVAHI_GCC_UNUSED AvahiTimeEvent *e, void* userdata) {
       
   549 @@ -1175,16 +1571,28 @@
       
   550  
       
   551  void avahi_s_entry_group_reset(AvahiSEntryGroup *g) {
       
   552      AvahiEntry *e;
       
   553 +#ifdef HAVE_BONJOUR
       
   554 +    AvahiService *s;
       
   555 +#endif
       
   556      assert(g);
       
   557  
       
   558      for (e = g->entries; e; e = e->by_group_next) {
       
   559          if (!e->dead) {
       
   560 +#ifndef HAVE_BONJOUR
       
   561              avahi_goodbye_entry(g->server, e, 1, 1);
       
   562 +#endif
       
   563              e->dead = 1;
       
   564          }
       
   565      }
       
   566      g->server->need_entry_cleanup = 1;
       
   567  
       
   568 +#ifdef HAVE_BONJOUR
       
   569 +    for (s = g->services; s; s = s->services_next) {
       
   570 +        s->dead = 1;
       
   571 +    }
       
   572 +    g->server->need_service_cleanup = 1;
       
   573 +#endif
       
   574 +
       
   575      g->n_probing = 0;
       
   576  
       
   577      avahi_s_entry_group_change_state(g, AVAHI_ENTRY_GROUP_UNCOMMITED);
       
   578 @@ -1222,12 +1630,23 @@
       
   579  
       
   580  int avahi_s_entry_group_is_empty(AvahiSEntryGroup *g) {
       
   581      AvahiEntry *e;
       
   582 +#ifdef HAVE_BONJOUR
       
   583 +    AvahiService *s;
       
   584 +#endif
       
   585 +
       
   586      assert(g);
       
   587  
       
   588 +#ifdef HAVE_BONJOUR
       
   589 +    for (s = g->services; s; s = s->services_next)
       
   590 +        if (!s->dead)
       
   591 +            return 0;
       
   592 +#else
       
   593      /* Look for an entry that is not dead */
       
   594      for (e = g->entries; e; e = e->by_group_next)
       
   595          if (!e->dead)
       
   596              return 0;
       
   597 +#endif
       
   598  
       
   599      return 1;
       
   600  }
       
   601 +