static void finish(AvahiSServiceResolver *r, AvahiResolverEvent event) {
    AvahiLookupResultFlags flags;

    assert(r);

    if (r->time_event) {
        avahi_time_event_free(r->time_event);
        r->time_event = NULL;
    }

    flags =
        r->txt_flags |
        r->srv_flags |
        r->address_flags;

    switch (event) {
        case AVAHI_RESOLVER_FAILURE:

            r->callback(
                r,
                r->interface,
                r->protocol,
                event,
                r->service_name,
                r->service_type,
                r->domain_name,
                NULL,
                NULL,
                0,
                NULL,
                flags,
                r->userdata);

            break;

        case AVAHI_RESOLVER_FOUND: {
            AvahiAddress a;

            assert(event == AVAHI_RESOLVER_FOUND);

            assert(r->srv_record);

            if (r->address_record) {
                switch (r->address_record->key->type) {
                    case AVAHI_DNS_TYPE_A:
                        a.proto = AVAHI_PROTO_INET;
                        a.data.ipv4 = r->address_record->data.a.address;
                        break;

                    case AVAHI_DNS_TYPE_AAAA:
                        a.proto = AVAHI_PROTO_INET6;
                        a.data.ipv6 = r->address_record->data.aaaa.address;
                        break;

                    default:
                        assert(0);
                }
            }

            r->callback(
                r,
                r->interface,
                r->protocol,
                event,
                r->service_name,
                r->service_type,
                r->domain_name,
                r->srv_record->data.srv.name,
                r->address_record ? &a : NULL,
                r->srv_record->data.srv.port,
                r->txt_record ? r->txt_record->data.txt.string_list : NULL,
                flags,
                r->userdata);

            break;
        }
    }
}
static void finish(AvahiSServiceResolver *r, AvahiResolverEvent event) {
    AvahiLookupResultFlags flags;

    assert(r);

    if (r->time_event) {
        avahi_time_event_free(r->time_event);
        r->time_event = NULL;
    }

    flags =
        r->txt_flags |
        r->srv_flags |
        r->address_flags;

    switch (event) {
        case AVAHI_RESOLVER_FAILURE:

            r->callback(
                r,
                r->interface,
                r->protocol,
                event,
                r->service_name,
                r->service_type,
                r->domain_name,
                NULL,
                NULL,
                0,
                NULL,
                flags,
                r->userdata);

            break;

        case AVAHI_RESOLVER_FOUND: {
            AvahiAddress a;

            assert(event == AVAHI_RESOLVER_FOUND);

            assert(r->srv_record);

            if (r->address_record) {
                switch (r->address_record->key->type) {
                    case AVAHI_DNS_TYPE_A:
                        a.proto = AVAHI_PROTO_INET;
                        a.data.ipv4 = r->address_record->data.a.address;
                        break;

                    case AVAHI_DNS_TYPE_AAAA:
                        a.proto = AVAHI_PROTO_INET6;
                        a.data.ipv6 = r->address_record->data.aaaa.address;
                        break;

                    default:
                        assert(0);
                }
            }

            r->callback(
                r,
                r->interface,
                r->protocol,
                event,
                r->service_name,
                r->service_type,
                r->domain_name,
                r->srv_record->data.srv.name,
                r->address_record ? &a : NULL,
                r->srv_record->data.srv.port,
                r->txt_record ? r->txt_record->data.txt.string_list : NULL,
                flags,
                r->userdata);

            break;
        }
    }
}