#include <assert.h>
#include <avahi-client/client.h>
+#include <avahi-client/lookup.h>
+#include <avahi-client/publish.h>
+
#include <avahi-common/error.h>
#include <avahi-common/simple-watch.h>
#include <avahi-common/malloc.h>
+#include <avahi-common/timeval.h>
static const AvahiPoll *poll_api = NULL;
static AvahiSimplePoll *simple_poll = NULL;
printf ("ENTRY-GROUP: Callback on %p, state -> %d, data -> %s\n", (void*) g, state, (char*)userdata);
}
+static void avahi_entry_group2_callback (AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) {
+ printf ("ENTRY-GROUP2: Callback on %p, state -> %d, data -> %s\n", (void*) g, state, (char*)userdata);
+}
+
+
static void avahi_domain_browser_callback(
AvahiDomainBrowser *b,
AvahiIfIndex interface,
char addr[64];
char *txtr;
- if (event == AVAHI_RESOLVER_TIMEOUT)
- {
+ if (event == AVAHI_RESOLVER_FAILURE) {
printf ("SERVICE-RESOLVER: ServiceResolver %p timed out (%s %s)\n", (void*) r, name, type);
return;
}
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiResolverEvent event,
- AvahiProtocol aprotocol,
const AvahiAddress *address,
const char *name,
AvahiLookupResultFlags flags,
void *userdata) {
char addr[64];
- if (event == AVAHI_RESOLVER_TIMEOUT)
- {
+ if (event == AVAHI_RESOLVER_FAILURE) {
printf ("ADDRESS-RESOLVER: Callback on AddressResolver, timed out.\n");
return;
}
avahi_address_snprint (addr, sizeof (addr), address);
- printf ("ADDRESS-RESOLVER: Callback on AddressResolver, interface (%d), protocol (%d), even (%d), aprotocol (%d), address (%s), name (%s), data(%s)\n", interface, protocol, event, aprotocol, addr, name, (char*) userdata);
+ printf ("ADDRESS-RESOLVER: Callback on AddressResolver, interface (%d), protocol (%d), even (%d), address (%s), name (%s), data(%s)\n", interface, protocol, event, addr, name, (char*) userdata);
}
static void avahi_host_name_resolver_callback (
AvahiAddressResolver *ar;
char addr[64];
- if (event == AVAHI_RESOLVER_TIMEOUT)
- {
+ if (event == AVAHI_RESOLVER_FAILURE) {
printf ("HOST-NAME-RESOLVER: Callback on HostNameResolver, timed out.\n");
return;
}
client = avahi_host_name_resolver_get_client (r);
- ar = avahi_address_resolver_new_a (client, interface, protocol, a, 0, avahi_address_resolver_callback, "omghai6u");
+ ar = avahi_address_resolver_new(client, interface, protocol, a, 0, avahi_address_resolver_callback, "omghai6u");
if (ar)
{
printf ("Succesfully created address resolver object\n");
printf ("Resetting entry group\n");
avahi_entry_group_reset (g);
- avahi_entry_group_add_service (g, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "Lathiat's Site", "_http._tcp", NULL, NULL, 80, "foo=bar2", NULL);
+ avahi_entry_group_add_service (g, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "Lathiat's Site", "_http._tcp", NULL, NULL, 80, "foo=bar2", NULL);
avahi_entry_group_commit (g);
}
+static void test_entry_group_update(AvahiTimeout *timeout, void* userdata) {
+ AvahiEntryGroup *g = userdata;
+
+ printf ("Updating entry group\n");
+
+ avahi_entry_group_update_service_txt(g, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "Lathiat's Site", "_http._tcp", NULL, "foo=bar3", NULL);
+}
+
static void terminate(AvahiTimeout *timeout, void *userdata) {
avahi_simple_poll_quit(simple_poll);
int main (int argc, char *argv[]) {
AvahiClient *avahi;
- AvahiEntryGroup *group;
+ AvahiEntryGroup *group, *group2;
AvahiDomainBrowser *domain;
AvahiServiceBrowser *sb;
AvahiServiceTypeBrowser *st;
AvahiHostNameResolver *hnr;
+ AvahiAddress *aar;
const char *ret;
int error;
uint32_t cookie;
printf("Sucessfully created entry group %p\n", (void*) group);
- avahi_entry_group_add_service (group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "Lathiat's Site", "_http._tcp", NULL, NULL, 80, "foo=bar", NULL);
+ avahi_entry_group_add_service (group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "Lathiat's Site", "_http._tcp", NULL, NULL, 80, "foo=bar", NULL);
avahi_entry_group_commit (group);
else
printf ("Successfully created hostname resolver object\n");
+ aar = avahi_address_parse ("224.0.0.251", AF_UNSPEC, aar);
+ if (aar == NULL) {
+ printf ("failed to create address object\n");
+ } else {
+ group2 = avahi_entry_group_new (avahi, avahi_entry_group2_callback, "omghai222");
+ if ((error = avahi_entry_group_add_address (group2, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "test-mdns.local.", aar)) < 0)
+ {
+ printf ("*** failed to add address to entry group: %s\n", avahi_strerror (error));
+ avahi_entry_group_free (group2);
+ } else {
+ printf ("*** success, added address\n");
+ avahi_entry_group_commit (group2);
+ }
+
+ }
+
avahi_elapse_time(&tv, 8000, 0);
poll_api->timeout_new(poll_api, &tv, test_entry_group_reset, group);
+ avahi_elapse_time(&tv, 15000, 0);
+ poll_api->timeout_new(poll_api, &tv, test_entry_group_update, group);
avahi_elapse_time(&tv, 20000, 0);
poll_api->timeout_new(poll_api, &tv, test_free_entry_group, group);
avahi_elapse_time(&tv, 25000, 0);