]> git.meshlink.io Git - catta/blobdiff - avahi-client/client-test.c
* Add custom user-specific configure flags to bootstrap.sh
[catta] / avahi-client / client-test.c
index 15af93f45722706618e5cfad363375ec8c580e8e..076fb3b4f7e36df85a6aaf25e67cef87db5715e0 100644 (file)
@@ -27,6 +27,9 @@
 #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>
@@ -42,6 +45,11 @@ static void avahi_entry_group_callback (AvahiEntryGroup *g, AvahiEntryGroupState
     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,
@@ -71,8 +79,7 @@ static void avahi_service_resolver_callback(
     
     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;
     }
@@ -129,8 +136,7 @@ static void avahi_address_resolver_callback (
     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;
     }
@@ -152,8 +158,7 @@ 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;
     }
@@ -194,6 +199,14 @@ static void test_entry_group_reset (AvahiTimeout *timeout, void* userdata)
     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);
@@ -201,11 +214,12 @@ static void terminate(AvahiTimeout *timeout, void *userdata) {
 
 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;
@@ -272,9 +286,27 @@ int main (int argc, char *argv[]) {
     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 (ret));
+            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);