diff options
author | Lennart Poettering <lennart@poettering.net> | 2005-10-15 02:23:21 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2005-10-15 02:23:21 +0000 |
commit | a96f0540a6eb9a9cfaabef829982576ebec6e596 (patch) | |
tree | dadfae22e15057450afead584639ac9bcf81e8d7 /avahi-compat-howl/samples | |
parent | 2d6a80b9c57b32e5202c91b2239374555a098997 (diff) |
* implement compat-howl core
* add HOWL examples to or build
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@765 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-compat-howl/samples')
-rw-r--r-- | avahi-compat-howl/samples/browse.c | 184 | ||||
-rw-r--r-- | avahi-compat-howl/samples/publish.c | 110 | ||||
-rw-r--r-- | avahi-compat-howl/samples/query.c | 98 | ||||
-rw-r--r-- | avahi-compat-howl/samples/resolve.c | 111 |
4 files changed, 503 insertions, 0 deletions
diff --git a/avahi-compat-howl/samples/browse.c b/avahi-compat-howl/samples/browse.c new file mode 100644 index 0000000..b4a8cf3 --- /dev/null +++ b/avahi-compat-howl/samples/browse.c @@ -0,0 +1,184 @@ +/* + * Copyright 2003, 2004, 2004 Porchdog Software. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY PORCHDOG SOFTWARE ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE HOWL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those + * of the authors and should not be interpreted as representing official policies, + * either expressed or implied, of Porchdog Software. + */ + +#include <howl.h> +#include <salt/debug.h> +#include <stdio.h> + + +static sw_result HOWL_API +my_resolver( + sw_discovery discovery, + sw_discovery_oid oid, + sw_uint32 interface_index, + sw_const_string name, + sw_const_string type, + sw_const_string domain, + sw_ipv4_address address, + sw_port port, + sw_octets text_record, + sw_uint32 text_record_len, + sw_opaque_t extra) +{ + sw_text_record_iterator it; + sw_int8 name_buf[16]; + sw_int8 key[SW_TEXT_RECORD_MAX_LEN]; + sw_int8 sval[SW_TEXT_RECORD_MAX_LEN]; + sw_uint8 oval[SW_TEXT_RECORD_MAX_LEN]; + sw_uint32 oval_len; + sw_result err = SW_OKAY; + + sw_discovery_cancel(discovery, oid); + + fprintf(stderr, "resolve reply: 0x%x %s %s %s %s %d\n", interface_index, name, type, domain, sw_ipv4_address_name(address, name_buf, 16), port); + + if ((text_record_len > 0) && (text_record) && (*text_record != '\0')) + { + err = sw_text_record_iterator_init(&it, text_record, text_record_len); + sw_check_okay(err, exit); + + while (sw_text_record_iterator_next(it, key, oval, &oval_len) == SW_OKAY) + { + fprintf(stderr, "Txt: [%s]=[%s] - (%d bytes)\n", key, oval, oval_len); + } + + err = sw_text_record_iterator_fina(it); + sw_check_okay(err, exit); + } + +exit: + + return err; +} + + +static sw_result HOWL_API +my_browser( + sw_discovery discovery, + sw_discovery_oid oid, + sw_discovery_browse_status status, + sw_uint32 interface_index, + sw_const_string name, + sw_const_string type, + sw_const_string domain, + sw_opaque_t extra) +{ + sw_discovery_resolve_id rid; + + switch (status) + { + case SW_DISCOVERY_BROWSE_INVALID: + { + fprintf(stderr, "browse reply: Invalid\n"); + } + break; + + case SW_DISCOVERY_BROWSE_RELEASE: + { + fprintf(stderr, "browse reply: Release\n"); + } + break; + + case SW_DISCOVERY_BROWSE_ADD_DOMAIN: + { + fprintf(stderr, "browse reply: Add Domain\n"); + } + break; + + case SW_DISCOVERY_BROWSE_ADD_DEFAULT_DOMAIN: + { + fprintf(stderr, "browse reply: Add Default Domain\n"); + } + break; + + case SW_DISCOVERY_BROWSE_REMOVE_DOMAIN: + { + fprintf(stderr, "browse reply: Remove Domain\n"); + } + break; + + case SW_DISCOVERY_BROWSE_ADD_SERVICE: + { + fprintf(stderr, "browse reply: Add Service 0x%x %s %s %s\n", interface_index, name, type, domain); + if (sw_discovery_resolve(discovery, interface_index, name, type, domain, my_resolver, NULL, &rid) != SW_OKAY) + { + fprintf(stderr, "resolve failed\n"); + } + } + break; + + case SW_DISCOVERY_BROWSE_REMOVE_SERVICE: + { + fprintf(stderr, "browse reply: Remove Service\n"); + fprintf(stderr, "remove service: 0x%x %s %s %s\n", interface_index, name, type, domain); + } + break; + + case SW_DISCOVERY_BROWSE_RESOLVED: + { + fprintf(stderr, "browse reply: Resolved\n"); + } + break; + } + + return SW_OKAY; +} + + +#if defined(WIN32) +int __cdecl +#else +int +#endif +main( + int argc, + char ** argv) +{ + sw_discovery discovery; + sw_discovery_oid oid; + sw_result err; + + err = sw_discovery_init(&discovery); + sw_check_okay(err, exit); + + if (argc != 2) + { + fprintf(stderr, "usage: mDNSBrowse <type>\n"); + return -1; + } + + err = sw_discovery_browse(discovery, 0, argv[1], NULL, my_browser, NULL, &oid); + sw_check_okay(err, exit); + + err = sw_discovery_run(discovery); + sw_check_okay(err, exit); + +exit: + + return err; +} diff --git a/avahi-compat-howl/samples/publish.c b/avahi-compat-howl/samples/publish.c new file mode 100644 index 0000000..cca6040 --- /dev/null +++ b/avahi-compat-howl/samples/publish.c @@ -0,0 +1,110 @@ +/* + * Copyright 2003, 2004 Porchdog Software. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY PORCHDOG SOFTWARE ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE HOWL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those + * of the authors and should not be interpreted as representing official policies, + * either expressed or implied, of Porchdog Software. + */ + +#include <howl.h> +#include <stdio.h> + + +static sw_result HOWL_API +my_service_reply( + sw_discovery discovery, + sw_discovery_oid oid, + sw_discovery_publish_status status, + sw_opaque extra) +{ + static sw_string + status_text[] = + { + "Started", + "Stopped", + "Name Collision", + "Invalid" + }; + + fprintf(stderr, "publish reply: %s\n", status_text[status]); + return SW_OKAY; +} + + +#if defined(WIN32) +int __cdecl +#else +int +#endif +main( + int argc, + char ** argv) +{ + sw_discovery discovery; + sw_text_record text_record; + sw_result result; + sw_discovery_publish_id id; + int i; + + if (sw_discovery_init(&discovery) != SW_OKAY) + { + fprintf(stderr, "sw_discovery_init() failed\n"); + return -1; + } + + if (argc < 4) + { + fprintf(stderr, "usage: mDNSPublish <name> <type> <port> [service text 1]...[service text n]\n"); + return -1; + } + + if (sw_text_record_init(&text_record) != SW_OKAY) + { + fprintf(stderr, "sw_text_record_init() failed\n"); + return -1; + } + + for (i = 4; i < argc; i++) + { + if (sw_text_record_add_string(text_record, argv[i]) != SW_OKAY) + { + fprintf(stderr, "unable to add service text: %s\n", argv[i]); + return -1; + } + } + + printf("%s %s %d\n", argv[1], argv[2], atoi(argv[3])); + + if ((result = sw_discovery_publish(discovery, 0, argv[1], argv[2], NULL, NULL, atoi(argv[3]), sw_text_record_bytes(text_record), sw_text_record_len(text_record), my_service_reply, NULL, &id)) != SW_OKAY) + { + fprintf(stderr, "publish failed: %d\n", result); + sw_text_record_fina(text_record); + return -1; + } + + sw_text_record_fina(text_record); + + sw_discovery_run(discovery); + + return 0; +} diff --git a/avahi-compat-howl/samples/query.c b/avahi-compat-howl/samples/query.c new file mode 100644 index 0000000..a74a81c --- /dev/null +++ b/avahi-compat-howl/samples/query.c @@ -0,0 +1,98 @@ +/* + * Copyright 2003, 2004, 2004 Porchdog Software. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY PORCHDOG SOFTWARE ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE HOWL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those + * of the authors and should not be interpreted as representing official policies, + * either expressed or implied, of Porchdog Software. + */ + +#include <howl.h> +#include <salt/debug.h> +#include <stdio.h> + + +static sw_result HOWL_API +query_record_reply( + sw_discovery session, + sw_discovery_oid oid, + sw_discovery_query_record_status status, + sw_uint32 interface_index, + sw_const_string fullname, + sw_uint16 rrtype, + sw_uint16 rrclass, + sw_uint16 rrdatalen, + sw_const_octets rrdata, + sw_uint32 ttl, + sw_opaque extra) +{ + sw_ipv4_address address; + + fprintf(stderr, "interface index = 0x%x, fullname is %s\n", interface_index, fullname); + + if ((rrtype == 1) && (rrclass == 1)) + { + sw_ipv4_address address; + sw_char name[16]; + + sw_ipv4_address_init_from_saddr(&address, *(sw_saddr*) rrdata); + + fprintf(stderr, "address is %s\n", sw_ipv4_address_name(address, name, sizeof(name))); + } + + return SW_OKAY; +} + + + +#if defined(WIN32) +int __cdecl +#else +int +#endif +main( + int argc, + char ** argv) +{ + sw_discovery discovery; + sw_discovery_oid oid; + sw_result err; + + err = sw_discovery_init(&discovery); + sw_check_okay(err, exit); + + if (argc != 4) + { + fprintf(stderr, "usage: mDNSBrowse <name> <rrtype> <rrclass>\n"); + return -1; + } + + err = sw_discovery_query_record(discovery, 0, 0, argv[1], atoi(argv[2]), atoi(argv[3]), query_record_reply, NULL, &oid); + sw_check_okay(err, exit); + + err = sw_discovery_run(discovery); + sw_check_okay(err, exit); + +exit: + + return err; +} diff --git a/avahi-compat-howl/samples/resolve.c b/avahi-compat-howl/samples/resolve.c new file mode 100644 index 0000000..b921c27 --- /dev/null +++ b/avahi-compat-howl/samples/resolve.c @@ -0,0 +1,111 @@ +/* + * Copyright 2003, 2004, 2004 Porchdog Software. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY PORCHDOG SOFTWARE ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE HOWL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those + * of the authors and should not be interpreted as representing official policies, + * either expressed or implied, of Porchdog Software. + */ + +#include <howl.h> +#include <salt/debug.h> +#include <stdio.h> + + +static sw_result HOWL_API +my_resolver( + sw_discovery discovery, + sw_discovery_oid oid, + sw_uint32 interface_index, + sw_const_string name, + sw_const_string type, + sw_const_string domain, + sw_ipv4_address address, + sw_port port, + sw_octets text_record, + sw_uint32 text_record_len, + sw_opaque_t extra) +{ + sw_text_record_iterator it; + sw_int8 name_buf[16]; + sw_int8 key[SW_TEXT_RECORD_MAX_LEN]; + sw_int8 sval[SW_TEXT_RECORD_MAX_LEN]; + sw_uint8 oval[SW_TEXT_RECORD_MAX_LEN]; + sw_uint32 oval_len; + sw_result err = SW_OKAY; + + sw_discovery_cancel(discovery, oid); + + fprintf(stderr, "resolve reply: 0x%x %s %s %s %s %d\n", interface_index, name, type, domain, sw_ipv4_address_name(address, name_buf, 16), port); + + if ((text_record_len > 0) && (text_record) && (*text_record != '\0')) + { + err = sw_text_record_iterator_init(&it, text_record, text_record_len); + sw_check_okay(err, exit); + + while (sw_text_record_iterator_next(it, key, oval, &oval_len) == SW_OKAY) + { + fprintf(stderr, "key = %s, data is %d bytes\n", key, oval_len); + } + + err = sw_text_record_iterator_fina(it); + sw_check_okay(err, exit); + } + +exit: + + return err; +} + + +#if defined(WIN32) +int __cdecl +#else +int +#endif +main( + int argc, + char ** argv) +{ + sw_discovery discovery; + sw_discovery_oid oid; + sw_result err; + + err = sw_discovery_init(&discovery); + sw_check_okay(err, exit); + + if (argc != 3) + { + fprintf(stderr, "usage: mDNSResolve <name> <type>\n"); + return -1; + } + + err = sw_discovery_resolve(discovery, 0, argv[1], argv[2], "local.", my_resolver, NULL, &oid); + sw_check_okay(err, exit); + + err = sw_discovery_run(discovery); + sw_check_okay(err, exit); + +exit: + + return err; +} |