From: Lennart Poettering Date: Thu, 29 Sep 2005 01:51:53 +0000 (+0000) Subject: * make all flags parameters UINT32 when marshalling for DBUS X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=424aefe8a431b79496672799dc4f4430fa935252;p=catta * make all flags parameters UINT32 when marshalling for DBUS * rename AvahiEntryFlags to AvahiPublishFlags * add flags parameter to add_service() and friends * validity checking of flags, interface and protocol parameters of add_service() and friends * make AVAHI_VALID_FLAGS a global macro * add new flag AVAHI_PUBLISH_NO_REVERSE, if set address records will no be created with matching reverse lookup PTR RRs * add new flag AVAHI_PUBLISH_NO_COOKIE, for not implicitly adding the service cookie to TXT records * minor cleanups Yes, this will break the mono bindings. More breakages to come. NO_REVERSE and NO_COOKIE needs testing. Lathiat, I guess the new flag NO_REVERSE makes the immediate need to add a client side API to add arbitrary RRs obsolete for now. You might consider moving it in the TODO list to "later". git-svn-id: file:///home/lennart/svn/public/avahi/trunk@648 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- diff --git a/avahi-client/browser.c b/avahi-client/browser.c index 1aaae8c..a83aa69 100644 --- a/avahi-client/browser.c +++ b/avahi-client/browser.c @@ -52,7 +52,8 @@ AvahiDomainBrowser* avahi_domain_browser_new( DBusMessage *message = NULL, *reply = NULL; DBusError error; char *path; - int32_t i_interface, i_protocol, i_flags, bt; + int32_t i_interface, i_protocol, bt; + uint32_t u_flags; assert(client); assert(callback); @@ -86,7 +87,7 @@ AvahiDomainBrowser* avahi_domain_browser_new( i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; bt = btype; if (!(dbus_message_append_args( @@ -95,7 +96,7 @@ AvahiDomainBrowser* avahi_domain_browser_new( DBUS_TYPE_INT32, &i_protocol, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INT32, &bt, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; @@ -175,7 +176,8 @@ DBusHandlerResult avahi_domain_browser_event (AvahiClient *client, AvahiBrowserE DBusError error; const char *path; char *domain = NULL; - int32_t interface = AVAHI_IF_UNSPEC, protocol = AVAHI_PROTO_UNSPEC, flags = 0; + int32_t interface = AVAHI_IF_UNSPEC, protocol = AVAHI_PROTO_UNSPEC; + uint32_t flags = 0; assert(client); assert(message); @@ -198,7 +200,7 @@ DBusHandlerResult avahi_domain_browser_event (AvahiClient *client, AvahiBrowserE DBUS_TYPE_INT32, &interface, DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &domain, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || dbus_error_is_set (&error)) { fprintf(stderr, "Failed to parse browser event.\n"); @@ -229,7 +231,8 @@ AvahiServiceTypeBrowser* avahi_service_type_browser_new( DBusMessage *message = NULL, *reply = NULL; DBusError error; char *path; - int32_t i_interface, i_protocol, i_flags; + int32_t i_interface, i_protocol; + uint32_t u_flags; assert(client); assert(callback); @@ -263,14 +266,14 @@ AvahiServiceTypeBrowser* avahi_service_type_browser_new( i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; if (!dbus_message_append_args( message, DBUS_TYPE_INT32, &i_interface, DBUS_TYPE_INT32, &i_protocol, DBUS_TYPE_STRING, &domain, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID)) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; @@ -349,7 +352,8 @@ DBusHandlerResult avahi_service_type_browser_event (AvahiClient *client, AvahiBr DBusError error; const char *path; char *domain = NULL, *type = NULL; - int32_t interface = AVAHI_IF_UNSPEC, protocol = AVAHI_PROTO_UNSPEC, flags = 0; + int32_t interface = AVAHI_IF_UNSPEC, protocol = AVAHI_PROTO_UNSPEC; + uint32_t flags = 0; assert(client); assert(message); @@ -373,7 +377,7 @@ DBusHandlerResult avahi_service_type_browser_event (AvahiClient *client, AvahiBr DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || dbus_error_is_set(&error)) { fprintf(stderr, "Failed to parse browser event.\n"); @@ -406,7 +410,8 @@ AvahiServiceBrowser* avahi_service_browser_new( DBusMessage *message = NULL, *reply = NULL; DBusError error; char *path; - int32_t i_protocol, i_interface, i_flags; + int32_t i_protocol, i_interface; + uint32_t u_flags; assert(client); assert(type); @@ -441,7 +446,7 @@ AvahiServiceBrowser* avahi_service_browser_new( i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; if (!dbus_message_append_args( message, @@ -449,7 +454,7 @@ AvahiServiceBrowser* avahi_service_browser_new( DBUS_TYPE_INT32, &i_protocol, DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID)) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; @@ -528,7 +533,8 @@ DBusHandlerResult avahi_service_browser_event (AvahiClient *client, AvahiBrowser DBusError error; const char *path; char *name = NULL, *type = NULL, *domain = NULL; - int32_t interface = AVAHI_IF_UNSPEC, protocol = AVAHI_PROTO_UNSPEC, flags = 0; + int32_t interface = AVAHI_IF_UNSPEC, protocol = AVAHI_PROTO_UNSPEC; + uint32_t flags = 0; dbus_error_init (&error); @@ -550,7 +556,7 @@ DBusHandlerResult avahi_service_browser_event (AvahiClient *client, AvahiBrowser DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || dbus_error_is_set(&error)) { fprintf(stderr, "Failed to parse browser event.\n"); diff --git a/avahi-client/client-test.c b/avahi-client/client-test.c index 24576dd..15af93f 100644 --- a/avahi-client/client-test.c +++ b/avahi-client/client-test.c @@ -189,7 +189,7 @@ static void test_entry_group_reset (AvahiTimeout *timeout, void* userdata) 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); } @@ -243,7 +243,7 @@ int main (int argc, char *argv[]) { 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); diff --git a/avahi-client/client.h b/avahi-client/client.h index 4a915ac..31997cf 100644 --- a/avahi-client/client.h +++ b/avahi-client/client.h @@ -185,6 +185,7 @@ int avahi_entry_group_add_service( AvahiEntryGroup *group, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *name, const char *type, const char *domain, @@ -197,6 +198,7 @@ int avahi_entry_group_add_service_strlst( AvahiEntryGroup *group, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *name, const char *type, const char *domain, @@ -209,6 +211,7 @@ int avahi_entry_group_add_service_va( AvahiEntryGroup *group, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *name, const char *type, const char *domain, diff --git a/avahi-client/entrygroup.c b/avahi-client/entrygroup.c index dc0994a..2dffcf6 100644 --- a/avahi-client/entrygroup.c +++ b/avahi-client/entrygroup.c @@ -334,6 +334,7 @@ int avahi_entry_group_add_service_strlst( AvahiEntryGroup *group, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *name, const char *type, const char *domain, @@ -348,6 +349,7 @@ int avahi_entry_group_add_service_strlst( DBusError error; AvahiClient *client; int32_t i_interface, i_protocol; + uint32_t u_flags; assert(group); assert(name); @@ -373,11 +375,13 @@ int avahi_entry_group_add_service_strlst( i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; + u_flags = (uint32_t) flags; if (!dbus_message_append_args( message, DBUS_TYPE_INT32, &i_interface, DBUS_TYPE_INT32, &i_protocol, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, @@ -460,6 +464,7 @@ int avahi_entry_group_add_service( AvahiEntryGroup *group, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *name, const char *type, const char *domain, @@ -473,7 +478,7 @@ int avahi_entry_group_add_service( assert(group); va_start(va, port); - r = avahi_entry_group_add_service_va(group, interface, protocol, name, type, domain, host, port, va); + r = avahi_entry_group_add_service_va(group, interface, protocol, flags, name, type, domain, host, port, va); va_end(va); return r; } @@ -482,6 +487,7 @@ int avahi_entry_group_add_service_va( AvahiEntryGroup *group, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *name, const char *type, const char *domain, @@ -495,7 +501,7 @@ int avahi_entry_group_add_service_va( assert(group); txt = avahi_string_list_new_va(va); - r = avahi_entry_group_add_service_strlst(group, interface, protocol, name, type, domain, host, port, txt); + r = avahi_entry_group_add_service_strlst(group, interface, protocol, flags, name, type, domain, host, port, txt); avahi_string_list_free(txt); return r; diff --git a/avahi-client/resolver.c b/avahi-client/resolver.c index f08ce77..d054ae7 100644 --- a/avahi-client/resolver.c +++ b/avahi-client/resolver.c @@ -63,7 +63,8 @@ DBusHandlerResult avahi_service_resolver_event (AvahiClient *client, AvahiResolv if (event == AVAHI_RESOLVER_FOUND) { int j; - int32_t interface, flags, protocol, aprotocol; + int32_t interface, protocol, aprotocol; + uint32_t flags; char *name, *type, *domain, *host, *address; uint16_t port; DBusMessageIter iter, sub; @@ -130,8 +131,8 @@ DBusHandlerResult avahi_service_resolver_event (AvahiClient *client, AvahiResolv dbus_message_iter_next(&iter); - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) { - fprintf(stderr, "Failed to parse resolver event. XXX %i\n", dbus_message_iter_get_arg_type(&iter)); + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32) { + fprintf(stderr, "Failed to parse resolver event.\n"); goto fail; } @@ -175,7 +176,8 @@ AvahiServiceResolver * avahi_service_resolver_new( DBusError error; AvahiServiceResolver *r; DBusMessage *message = NULL, *reply = NULL; - int32_t i_interface, i_protocol, i_aprotocol, i_flags; + int32_t i_interface, i_protocol, i_aprotocol; + uint32_t u_flags; char *path; assert(client); @@ -214,7 +216,7 @@ AvahiServiceResolver * avahi_service_resolver_new( i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; i_aprotocol = (int32_t) aprotocol; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; if (!(dbus_message_append_args( message, @@ -224,7 +226,7 @@ AvahiServiceResolver * avahi_service_resolver_new( DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INT32, &i_aprotocol, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; @@ -324,7 +326,8 @@ DBusHandlerResult avahi_host_name_resolver_event (AvahiClient *client, AvahiReso goto fail; if (event == AVAHI_RESOLVER_FOUND) { - int32_t interface, protocol, aprotocol, flags; + int32_t interface, protocol, aprotocol; + uint32_t flags; char *name, *address; AvahiAddress a; @@ -335,7 +338,7 @@ DBusHandlerResult avahi_host_name_resolver_event (AvahiClient *client, AvahiReso DBUS_TYPE_STRING, &name, DBUS_TYPE_INT32, &aprotocol, DBUS_TYPE_STRING, &address, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || dbus_error_is_set (&error)) { fprintf(stderr, "Failed to parse resolver event.\n"); @@ -348,7 +351,7 @@ DBusHandlerResult avahi_host_name_resolver_event (AvahiClient *client, AvahiReso goto fail; } - r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, name, &a, flags, r->userdata); + r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, name, &a, (AvahiLookupResultFlags) flags, r->userdata); } else r->callback(r, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, event, NULL, NULL, 0, r->userdata); @@ -374,7 +377,8 @@ AvahiHostNameResolver * avahi_host_name_resolver_new( DBusError error; AvahiHostNameResolver *r; DBusMessage *message = NULL, *reply = NULL; - int32_t i_interface, i_protocol, i_aprotocol, i_flags; + int32_t i_interface, i_protocol, i_aprotocol; + uint32_t u_flags; char *path; assert(client); @@ -407,7 +411,7 @@ AvahiHostNameResolver * avahi_host_name_resolver_new( i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; i_aprotocol = (int32_t) aprotocol; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; if (!(dbus_message_append_args( message, @@ -415,7 +419,7 @@ AvahiHostNameResolver * avahi_host_name_resolver_new( DBUS_TYPE_INT32, &i_protocol, DBUS_TYPE_STRING, &name, DBUS_TYPE_INT32, &i_aprotocol, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; @@ -514,7 +518,8 @@ DBusHandlerResult avahi_address_resolver_event (AvahiClient *client, AvahiResolv goto fail; if (event == AVAHI_RESOLVER_FOUND) { - int32_t interface, protocol, aprotocol, flags; + int32_t interface, protocol, aprotocol; + uint32_t flags; char *name, *address; AvahiAddress a; @@ -525,7 +530,7 @@ DBusHandlerResult avahi_address_resolver_event (AvahiClient *client, AvahiResolv DBUS_TYPE_INT32, &aprotocol, DBUS_TYPE_STRING, &address, DBUS_TYPE_STRING, &name, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || dbus_error_is_set (&error)) { fprintf(stderr, "Failed to parse resolver event.\n"); @@ -585,7 +590,8 @@ AvahiAddressResolver * avahi_address_resolver_new( DBusError error; AvahiAddressResolver *r; DBusMessage *message = NULL, *reply = NULL; - int32_t i_interface, i_protocol, i_flags; + int32_t i_interface, i_protocol; + uint32_t u_flags; char *path; assert(client); @@ -616,14 +622,14 @@ AvahiAddressResolver * avahi_address_resolver_new( i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; if (!(dbus_message_append_args( message, DBUS_TYPE_INT32, &i_interface, DBUS_TYPE_INT32, &i_protocol, DBUS_TYPE_STRING, &address, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID))) { avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); goto fail; diff --git a/avahi-common/defs.h b/avahi-common/defs.h index a0fb034..06b48a6 100644 --- a/avahi-common/defs.h +++ b/avahi-common/defs.h @@ -152,6 +152,17 @@ typedef enum { AVAHI_DOMAIN_BROWSER_MAX } AvahiDomainBrowserType; +/** Some flags for publishing functions */ +typedef enum { + AVAHI_PUBLISH_NULL = 0, + AVAHI_PUBLISH_UNIQUE = 1, /**< For raw records: The RRset is intended to be unique */ + AVAHI_PUBLISH_NO_PROBE = 2, /**< For raw records: Though the RRset is intended to be unique no probes shall be sent */ + AVAHI_PUBLISH_NO_ANNOUNCE = 4, /**< For raw records: Do not announce this RR to other hosts */ + AVAHI_PUBLISH_ALLOW_MULTIPLE = 8, /**< For raw records: Allow multiple local records of this type, even if they are intended to be unique */ + AVAHI_PUBLISH_NO_REVERSE = 16, /**< For address records: don't create a reverse (PTR) entry */ + AVAHI_PUBLISH_NO_COOKIE = 32 /**< For service records: do not implicitly add the local service cookie to TXT data */ +} AvahiPublishFlags; + /** Some flags for lookup functions */ typedef enum { AVAHI_LOOKUP_NULL = 0, diff --git a/avahi-core/announce.c b/avahi-core/announce.c index c21b147..025331d 100644 --- a/avahi-core/announce.c +++ b/avahi-core/announce.c @@ -155,7 +155,7 @@ static void next_state(AvahiAnnouncement *a) { } else if (a->state == AVAHI_ANNOUNCING) { - if (a->entry->flags & AVAHI_ENTRY_UNIQUE) + if (a->entry->flags & AVAHI_PUBLISH_UNIQUE) /* Send the whole rrset at once */ avahi_server_prepare_matching_responses(a->server, a->interface, a->entry->record->key, 0); else @@ -212,9 +212,9 @@ static void go_to_initial_state(AvahiAnnouncement *a, int immediately) { assert(a); e = a->entry; - if ((e->flags & AVAHI_ENTRY_UNIQUE) && !(e->flags & AVAHI_ENTRY_NOPROBE)) + if ((e->flags & AVAHI_PUBLISH_UNIQUE) && !(e->flags & AVAHI_PUBLISH_NO_PROBE)) a->state = AVAHI_PROBING; - else if (!(e->flags & AVAHI_ENTRY_NOANNOUNCE)) { + else if (!(e->flags & AVAHI_PUBLISH_NO_ANNOUNCE)) { if (!e->group || e->group->state == AVAHI_ENTRY_GROUP_ESTABLISHED) a->state = AVAHI_ANNOUNCING; @@ -336,7 +336,7 @@ int avahi_entry_is_registered(AvahiServer *s, AvahiEntry *e, AvahiInterface *i) return a->state == AVAHI_ANNOUNCING || a->state == AVAHI_ESTABLISHED || - (a->state == AVAHI_WAITING && !(e->flags & AVAHI_ENTRY_UNIQUE)); + (a->state == AVAHI_WAITING && !(e->flags & AVAHI_PUBLISH_UNIQUE)); } int avahi_entry_is_probing(AvahiServer *s, AvahiEntry *e, AvahiInterface *i) { @@ -354,7 +354,7 @@ int avahi_entry_is_probing(AvahiServer *s, AvahiEntry *e, AvahiInterface *i) { return a->state == AVAHI_PROBING || - (a->state == AVAHI_WAITING && (e->flags & AVAHI_ENTRY_UNIQUE)); + (a->state == AVAHI_WAITING && (e->flags & AVAHI_PUBLISH_UNIQUE)); } void avahi_entry_return_to_initial_state(AvahiServer *s, AvahiEntry *e, AvahiInterface *i) { @@ -403,7 +403,7 @@ static void send_goodbye_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, v if (!avahi_interface_match(i, e->interface, e->protocol)) return; - if (e->flags & AVAHI_ENTRY_NOANNOUNCE) + if (e->flags & AVAHI_PUBLISH_NO_ANNOUNCE) return; if (!avahi_entry_is_registered(m->server, e, i)) @@ -412,7 +412,7 @@ static void send_goodbye_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, v if (!(g = make_goodbye_record(e->record))) return; /* OOM */ - avahi_interface_post_response(i, g, e->flags & AVAHI_ENTRY_UNIQUE, NULL, 1); + avahi_interface_post_response(i, g, e->flags & AVAHI_PUBLISH_UNIQUE, NULL, 1); avahi_record_unref(g); } diff --git a/avahi-core/avahi-test.c b/avahi-core/avahi-test.c index 0490c84..7ed5991 100644 --- a/avahi-core/avahi-test.c +++ b/avahi-core/avahi-test.c @@ -164,22 +164,22 @@ static void create_entries(int new_name) { service_name = n; } - if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, service_name, "_http._tcp", NULL, NULL, 80, "foo", NULL) < 0) { + if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, service_name, "_http._tcp", NULL, NULL, 80, "foo", NULL) < 0) { avahi_log_error("Failed to add HTTP service"); goto fail; } - if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, service_name, "_ftp._tcp", NULL, NULL, 21, "foo", NULL) < 0) { + if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, service_name, "_ftp._tcp", NULL, NULL, 21, "foo", NULL) < 0) { avahi_log_error("Failed to add FTP service"); goto fail; } - if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, service_name, "_webdav._tcp", NULL, NULL, 80, "foo", NULL) < 0) { + if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0,service_name, "_webdav._tcp", NULL, NULL, 80, "foo", NULL) < 0) { avahi_log_error("Failed to add WEBDAV service"); goto fail; } - if (avahi_server_add_dns_server_address(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, NULL, AVAHI_DNS_SERVER_RESOLVE, avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &a), 53) < 0) { + if (avahi_server_add_dns_server_address(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, NULL, AVAHI_DNS_SERVER_RESOLVE, avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &a), 53) < 0) { avahi_log_error("Failed to add new DNS Server address"); goto fail; } diff --git a/avahi-core/browse-dns-server.c b/avahi-core/browse-dns-server.c index 675000b..31da536 100644 --- a/avahi-core/browse-dns-server.c +++ b/avahi-core/browse-dns-server.c @@ -262,7 +262,7 @@ AvahiSDNSServerBrowser *avahi_s_dns_server_browser_new( if (!domain) domain = server->domain_name; - if (!AVAHI_VALID_FLAGS(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) { + if (!AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) { avahi_server_set_errno(server, AVAHI_ERR_INVALID_FLAGS); return NULL; } diff --git a/avahi-core/browse-domain.c b/avahi-core/browse-domain.c index c5d2ba8..6cbc93a 100644 --- a/avahi-core/browse-domain.c +++ b/avahi-core/browse-domain.c @@ -97,7 +97,7 @@ AvahiSDomainBrowser *avahi_s_domain_browser_new( if (!domain) domain = server->domain_name; - if (!AVAHI_VALID_FLAGS(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) { + if (!AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) { avahi_server_set_errno(server, AVAHI_ERR_INVALID_FLAGS); return NULL; } diff --git a/avahi-core/browse-service-type.c b/avahi-core/browse-service-type.c index 3ea28c0..25673fa 100644 --- a/avahi-core/browse-service-type.c +++ b/avahi-core/browse-service-type.c @@ -120,7 +120,7 @@ AvahiSServiceTypeBrowser *avahi_s_service_type_browser_new( if (!domain) domain = server->domain_name; - if (!AVAHI_VALID_FLAGS(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) { + if (!AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) { avahi_server_set_errno(server, AVAHI_ERR_INVALID_FLAGS); return NULL; } diff --git a/avahi-core/browse-service.c b/avahi-core/browse-service.c index 55fba6a..dfa6050 100644 --- a/avahi-core/browse-service.c +++ b/avahi-core/browse-service.c @@ -128,7 +128,7 @@ AvahiSServiceBrowser *avahi_s_service_browser_new( if (!domain) domain = server->domain_name; - if (!AVAHI_VALID_FLAGS(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) { + if (!AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) { avahi_server_set_errno(server, AVAHI_ERR_INVALID_FLAGS); return NULL; } diff --git a/avahi-core/browse.c b/avahi-core/browse.c index 64680b7..f47418a 100644 --- a/avahi-core/browse.c +++ b/avahi-core/browse.c @@ -527,7 +527,7 @@ AvahiSRecordBrowser *avahi_s_record_browser_new( CHECK_VALIDITY_RETURN_NULL(server, AVAHI_IF_VALID(interface), AVAHI_ERR_INVALID_INTERFACE); CHECK_VALIDITY_RETURN_NULL(server, !avahi_key_is_pattern(key), AVAHI_ERR_IS_PATTERN); CHECK_VALIDITY_RETURN_NULL(server, avahi_key_is_valid(key), AVAHI_ERR_INVALID_KEY); - CHECK_VALIDITY_RETURN_NULL(server, AVAHI_VALID_FLAGS(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS); + CHECK_VALIDITY_RETURN_NULL(server, AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS); CHECK_VALIDITY_RETURN_NULL(server, !(flags & AVAHI_LOOKUP_USE_WIDE_AREA) || !(flags & AVAHI_LOOKUP_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS); if (!(b = avahi_new(AvahiSRecordBrowser, 1))) { diff --git a/avahi-core/browse.h b/avahi-core/browse.h index 70e724f..a340c7f 100644 --- a/avahi-core/browse.h +++ b/avahi-core/browse.h @@ -60,6 +60,4 @@ void avahi_s_record_browser_destroy(AvahiSRecordBrowser *b); void avahi_s_record_browser_restart(AvahiSRecordBrowser *b); void avahi_s_record_browser_cancel(AvahiSRecordBrowser *b); -#define AVAHI_VALID_FLAGS(flags, max) (!((flags) & ~(max))) - #endif diff --git a/avahi-core/conformance-test.c b/avahi-core/conformance-test.c index 392dddc..1856fc5 100644 --- a/avahi-core/conformance-test.c +++ b/avahi-core/conformance-test.c @@ -74,7 +74,7 @@ static void create_service(const char *t) { else group = avahi_s_entry_group_new(avahi, entry_group_callback, NULL); - avahi_server_add_service(avahi, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, name, "_http._tcp", NULL, NULL, 80, "foo", NULL); + avahi_server_add_service(avahi, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_http._tcp", NULL, NULL, 80, "foo", NULL); avahi_s_entry_group_commit(group); try++; diff --git a/avahi-core/core.h b/avahi-core/core.h index 4883c6b..e3bf8a3 100644 --- a/avahi-core/core.h +++ b/avahi-core/core.h @@ -50,15 +50,6 @@ AVAHI_C_DECL_BEGIN /** Maximum number of defined DNS servers for wide area DNS */ #define AVAHI_MAX_WIDE_AREA_SERVERS 4 -/** Flags for server entries */ -typedef enum { - AVAHI_ENTRY_NULL = 0, /**< No special flags */ - AVAHI_ENTRY_UNIQUE = 1, /**< The RRset is intended to be unique */ - AVAHI_ENTRY_NOPROBE = 2, /**< Though the RRset is intended to be unique no probes shall be sent */ - AVAHI_ENTRY_NOANNOUNCE = 4, /**< Do not announce this RR to other hosts */ - AVAHI_ENTRY_ALLOWMUTIPLE = 8 /**< Allow multiple local records of this type, even if they are intended to be unique */ -} AvahiEntryFlags; - /** Prototype for callback functions which are called whenever the state of an AvahiServer object changes */ typedef void (*AvahiServerCallback) (AvahiServer *s, AvahiServerState state, void* userdata); diff --git a/avahi-core/iface.c b/avahi-core/iface.c index f882988..e3e2cd7 100644 --- a/avahi-core/iface.c +++ b/avahi-core/iface.c @@ -142,8 +142,8 @@ static void update_hw_interface_rr(AvahiInterfaceMonitor *m, AvahiHwInterface *h if (!name) return; /* OOM */ - if (avahi_server_add_service(m->server, hw->entry_group, hw->index, AVAHI_PROTO_UNSPEC, name, "_workstation._tcp", NULL, NULL, 9, NULL) < 0) { - avahi_log_warn(__FILE__": avahi_server_add_service() failed."); + if (avahi_server_add_service(m->server, hw->entry_group, hw->index, AVAHI_PROTO_UNSPEC, 0, name, "_workstation._tcp", NULL, NULL, 9, NULL) < 0) { + avahi_log_warn(__FILE__": avahi_server_add_service() failed: %s", avahi_strerror(m->server->error)); avahi_s_entry_group_free(hw->entry_group); hw->entry_group = NULL; } else diff --git a/avahi-core/publish.h b/avahi-core/publish.h index 4e632f8..c75c067 100644 --- a/avahi-core/publish.h +++ b/avahi-core/publish.h @@ -93,8 +93,9 @@ int avahi_server_add( AvahiSEntryGroup *g, /**< An entry group object if this new record shall be attached to one, or NULL. If you plan to remove the record sometime later you a required to pass an entry group object here. */ AvahiIfIndex interface, /**< A numeric index of a network interface to attach this record to, or AVAHI_IF_UNSPEC to attach this record to all interfaces */ AvahiProtocol protocol, /**< A protocol family to attach this record to. One of the AVAHI_PROTO_xxx constants. Use AVAHI_PROTO_UNSPEC to make this record available on all protocols (wich means on both IPv4 and IPv6). */ - AvahiEntryFlags flags, /**< Special flags for this record */ - AvahiRecord *r /**< The record to add. This function increases the reference counter of this object. */ ); + AvahiPublishFlags flags, /**< Special flags for this record */ + AvahiRecord *r /**< The record to add. This function increases the reference counter of this object. */); + /** Add a PTR RR to the server. See avahi_server_add() for more information. */ int avahi_server_add_ptr( @@ -102,7 +103,7 @@ int avahi_server_add_ptr( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, - AvahiEntryFlags flags, + AvahiPublishFlags flags, uint32_t ttl, /**< DNS TTL for this record */ const char *name, /**< PTR record name */ const char *dest /**< pointer destination */ ); @@ -113,7 +114,7 @@ int avahi_server_add_txt( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, - AvahiEntryFlags flags, + AvahiPublishFlags flags, uint32_t ttl, /**< DNS TTL for this record */ const char *name, /**< TXT record name */ ... /**< Text record data, terminated by NULL */) AVAHI_GCC_SENTINEL; @@ -126,7 +127,7 @@ int avahi_server_add_txt_va( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, - AvahiEntryFlags flags, + AvahiPublishFlags flags, uint32_t ttl, const char *name, va_list va); @@ -139,7 +140,7 @@ int avahi_server_add_txt_strlst( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, - AvahiEntryFlags flags, + AvahiPublishFlags flags, uint32_t ttl, const char *name, AvahiStringList *strlst /**< TXT decord data as a AvahiString. This routine makes a deep copy of this object. */ ); @@ -156,7 +157,7 @@ int avahi_server_add_address( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, - AvahiEntryFlags flags, + AvahiPublishFlags flags, const char *name, AvahiAddress *a); @@ -171,6 +172,7 @@ int avahi_server_add_service( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *name, /**< Service name, e.g. "Lennart's Files" */ const char *type, /**< DNS-SD type, e.g. "_http._tcp" */ const char *domain, @@ -184,6 +186,7 @@ int avahi_server_add_service_va( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *name, const char *type, const char *domain, @@ -197,6 +200,7 @@ int avahi_server_add_service_strlst( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *name, const char *type, const char *domain, @@ -218,6 +222,7 @@ int avahi_server_add_dns_server_address( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *domain, AvahiDNSServerType type, const AvahiAddress *address, @@ -231,6 +236,7 @@ int avahi_server_add_dns_server_name( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *domain, AvahiDNSServerType type, const char *name, diff --git a/avahi-core/resolve-address.c b/avahi-core/resolve-address.c index 4fb588e..704dab4 100644 --- a/avahi-core/resolve-address.c +++ b/avahi-core/resolve-address.c @@ -202,7 +202,7 @@ AvahiSAddressResolver *avahi_s_address_resolver_new( return NULL; } - if (!AVAHI_VALID_FLAGS(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) { + if (!AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) { avahi_server_set_errno(server, AVAHI_ERR_INVALID_FLAGS); return NULL; } diff --git a/avahi-core/resolve-host-name.c b/avahi-core/resolve-host-name.c index 622ece1..940febf 100644 --- a/avahi-core/resolve-host-name.c +++ b/avahi-core/resolve-host-name.c @@ -234,7 +234,7 @@ AvahiSHostNameResolver *avahi_s_host_name_resolver_new( return NULL; } - if (!AVAHI_VALID_FLAGS(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) { + if (!AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST)) { avahi_server_set_errno(server, AVAHI_ERR_INVALID_FLAGS); return NULL; } diff --git a/avahi-core/resolve-service.c b/avahi-core/resolve-service.c index 31b0081..1d79c5a 100644 --- a/avahi-core/resolve-service.c +++ b/avahi-core/resolve-service.c @@ -410,7 +410,7 @@ AvahiSServiceResolver *avahi_s_service_resolver_new( if (!domain) domain = server->domain_name; - if (!AVAHI_VALID_FLAGS(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST|AVAHI_LOOKUP_NO_TXT|AVAHI_LOOKUP_NO_ADDRESS)) { + if (!AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST|AVAHI_LOOKUP_NO_TXT|AVAHI_LOOKUP_NO_ADDRESS)) { avahi_server_set_errno(server, AVAHI_ERR_INVALID_FLAGS); return NULL; } diff --git a/avahi-core/server.c b/avahi-core/server.c index 6b7571e..49821d8 100644 --- a/avahi-core/server.c +++ b/avahi-core/server.c @@ -139,7 +139,7 @@ static void enum_aux_records(AvahiServer *s, AvahiInterface *i, const char *name for (e = avahi_hashmap_lookup(s->entries_by_key, k); e; e = e->by_key_next) if (!e->dead && avahi_entry_is_registered(s, e, i)) - callback(s, e->record, e->flags & AVAHI_ENTRY_UNIQUE, userdata); + callback(s, e->record, e->flags & AVAHI_PUBLISH_UNIQUE, userdata); avahi_key_unref(k); } @@ -166,7 +166,7 @@ void avahi_server_prepare_response(AvahiServer *s, AvahiInterface *i, AvahiEntry assert(i); assert(e); - avahi_record_list_push(s->record_list, e->record, e->flags & AVAHI_ENTRY_UNIQUE, unicast_response, auxiliary); + avahi_record_list_push(s->record_list, e->record, e->flags & AVAHI_PUBLISH_UNIQUE, unicast_response, auxiliary); } void avahi_server_prepare_matching_responses(AvahiServer *s, AvahiInterface *i, AvahiKey *k, int unicast_response) { @@ -319,7 +319,7 @@ static int handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord *recor continue; } - if (!(e->flags & AVAHI_ENTRY_UNIQUE) && !unique) + if (!(e->flags & AVAHI_PUBLISH_UNIQUE) && !unique) continue; /* Either our entry or the other is intended to be unique, so let's check */ @@ -1195,7 +1195,7 @@ static void register_hinfo(AvahiServer *s) { r->data.hinfo.cpu = avahi_strdup(avahi_strup(utsname.machine)); r->data.hinfo.os = avahi_strdup(avahi_strup(utsname.sysname)); - if (avahi_server_add(s, s->hinfo_entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_ENTRY_UNIQUE, r) < 0) { + if (avahi_server_add(s, s->hinfo_entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_PUBLISH_UNIQUE, r) < 0) { avahi_log_warn("Failed to add HINFO RR: %s", avahi_strerror(s->error)); return; } @@ -1214,10 +1214,10 @@ static void register_localhost(AvahiServer *s) { /* Add localhost entries */ avahi_address_parse("127.0.0.1", AVAHI_PROTO_INET, &a); - avahi_server_add_address(s, NULL, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_ENTRY_NOPROBE|AVAHI_ENTRY_NOANNOUNCE, "localhost", &a); + avahi_server_add_address(s, NULL, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_PUBLISH_NO_PROBE|AVAHI_PUBLISH_NO_ANNOUNCE, "localhost", &a); avahi_address_parse("::1", AVAHI_PROTO_INET6, &a); - avahi_server_add_address(s, NULL, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_ENTRY_NOPROBE|AVAHI_ENTRY_NOANNOUNCE, "ip6-localhost", &a); + avahi_server_add_address(s, NULL, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_PUBLISH_NO_PROBE|AVAHI_PUBLISH_NO_ANNOUNCE, "ip6-localhost", &a); } static void register_browse_domain(AvahiServer *s) { @@ -1418,7 +1418,6 @@ AvahiServer *avahi_server_new(const AvahiPoll *poll_api, const AvahiServerConfig s->legacy_unicast_reflect_slots = NULL; s->legacy_unicast_reflect_id = 0; - if (s->config.enable_wide_area) { s->wide_area_lookup_engine = avahi_wide_area_engine_new(s); avahi_wide_area_set_servers(s->wide_area_lookup_engine, s->config.wide_area_servers, s->config.n_wide_area_servers); @@ -1535,7 +1534,7 @@ void avahi_server_free(AvahiServer* s) { avahi_free(s); } -static int check_record_conflict(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiRecord *r, AvahiEntryFlags flags) { +static int check_record_conflict(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiRecord *r, AvahiPublishFlags flags) { AvahiEntry *e; assert(s); @@ -1545,10 +1544,10 @@ static int check_record_conflict(AvahiServer *s, AvahiIfIndex interface, AvahiPr if (e->dead) continue; - if (!(flags & AVAHI_ENTRY_UNIQUE) && !(e->flags & AVAHI_ENTRY_UNIQUE)) + if (!(flags & AVAHI_PUBLISH_UNIQUE) && !(e->flags & AVAHI_PUBLISH_UNIQUE)) continue; - if ((flags & AVAHI_ENTRY_ALLOWMUTIPLE) && (e->flags & AVAHI_ENTRY_ALLOWMUTIPLE) ) + if ((flags & AVAHI_PUBLISH_ALLOW_MULTIPLE) && (e->flags & AVAHI_PUBLISH_ALLOW_MULTIPLE) ) continue; if ((interface <= 0 || @@ -1569,7 +1568,7 @@ int avahi_server_add( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, - AvahiEntryFlags flags, + AvahiPublishFlags flags, AvahiRecord *r) { AvahiEntry *e, *t; @@ -1577,6 +1576,18 @@ int avahi_server_add( assert(s); assert(r); + if (!AVAHI_IF_VALID(interface)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_INTERFACE); + + if (!AVAHI_PROTO_VALID(protocol)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PROTOCOL); + + if (!AVAHI_FLAGS_VALID(flags, AVAHI_PUBLISH_NO_ANNOUNCE|AVAHI_PUBLISH_NO_PROBE|AVAHI_PUBLISH_UNIQUE|AVAHI_PUBLISH_ALLOW_MULTIPLE)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_FLAGS); + + if (!avahi_is_valid_domain_name(r->key->name)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME); + if (r->ttl == 0) return avahi_server_set_errno(s, AVAHI_ERR_INVALID_TTL); @@ -1590,7 +1601,7 @@ int avahi_server_add( return avahi_server_set_errno(s, AVAHI_ERR_LOCAL_COLLISION); if (!(e = avahi_new(AvahiEntry, 1))) - return avahi_server_set_errno(s, AVAHI_ERR_NO_NETWORK); + return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY); e->server = s; e->record = avahi_record_ref(r); @@ -1671,7 +1682,7 @@ int avahi_server_add_ptr( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, - AvahiEntryFlags flags, + AvahiPublishFlags flags, uint32_t ttl, const char *name, const char *dest) { @@ -1682,7 +1693,13 @@ int avahi_server_add_ptr( assert(s); assert(dest); - if (!(r = avahi_record_new_full(name ? name : s->host_name_fqdn, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR, ttl))) + if ((name && !avahi_is_valid_domain_name(name)) || !avahi_is_valid_domain_name(dest)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME); + + if (!name) + name = s->host_name_fqdn; + + if (!(r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR, ttl))) return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY); r->data.ptr.name = avahi_normalize_name(dest); @@ -1696,30 +1713,38 @@ int avahi_server_add_address( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, - AvahiEntryFlags flags, + AvahiPublishFlags flags, const char *name, AvahiAddress *a) { char *n = NULL; int ret = AVAHI_OK; + assert(s); assert(a); - if (name) { + if (!AVAHI_IF_VALID(interface)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_INTERFACE); + + if (!AVAHI_PROTO_VALID(protocol) || !AVAHI_PROTO_VALID(a->proto)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PROTOCOL); + + if (!AVAHI_FLAGS_VALID(flags, AVAHI_PUBLISH_NO_REVERSE|AVAHI_PUBLISH_NO_ANNOUNCE|AVAHI_PUBLISH_NO_PROBE)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_FLAGS); + + if (name && !avahi_is_valid_domain_name(name)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME); + + if (!name) + name = s->host_name_fqdn; + else { if (!(n = avahi_normalize_name(name))) return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY); name = n; - } else - name = s->host_name_fqdn; - - if (!avahi_is_valid_domain_name(name)) { - ret = avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME); - goto fail; } if (a->proto == AVAHI_PROTO_INET) { - char *reverse; AvahiRecord *r; if (!(r = avahi_record_new_full(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A, AVAHI_DEFAULT_TTL_HOST_NAME))) { @@ -1728,22 +1753,25 @@ int avahi_server_add_address( } r->data.a.address = a->data.ipv4; - ret = avahi_server_add(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE | AVAHI_ENTRY_ALLOWMUTIPLE, r); + ret = avahi_server_add(s, g, interface, protocol, (flags & ~ AVAHI_PUBLISH_NO_REVERSE) | AVAHI_PUBLISH_UNIQUE | AVAHI_PUBLISH_ALLOW_MULTIPLE, r); avahi_record_unref(r); if (ret < 0) goto fail; - - if (!(reverse = avahi_reverse_lookup_name_ipv4(&a->data.ipv4))) { - ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY); - goto fail; - } - - ret = avahi_server_add_ptr(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE, AVAHI_DEFAULT_TTL_HOST_NAME, reverse, name); - avahi_free(reverse); + if (!(flags & AVAHI_PUBLISH_NO_REVERSE)) { + char *reverse; + + if (!(reverse = avahi_reverse_lookup_name_ipv4(&a->data.ipv4))) { + ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY); + goto fail; + } + + ret = avahi_server_add_ptr(s, g, interface, protocol, flags | AVAHI_PUBLISH_UNIQUE, AVAHI_DEFAULT_TTL_HOST_NAME, reverse, name); + avahi_free(reverse); + } + } else { - char *reverse; AvahiRecord *r; assert(a->proto == AVAHI_PROTO_INET6); @@ -1754,30 +1782,34 @@ int avahi_server_add_address( } r->data.aaaa.address = a->data.ipv6; - ret = avahi_server_add(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE | AVAHI_ENTRY_ALLOWMUTIPLE, r); + ret = avahi_server_add(s, g, interface, protocol, (flags & ~ AVAHI_PUBLISH_NO_REVERSE) | AVAHI_PUBLISH_UNIQUE | AVAHI_PUBLISH_ALLOW_MULTIPLE, r); avahi_record_unref(r); if (ret < 0) goto fail; - if (!(reverse = avahi_reverse_lookup_name_ipv6_arpa(&a->data.ipv6))) { - ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY); - goto fail; - } - - ret = avahi_server_add_ptr(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE, AVAHI_DEFAULT_TTL_HOST_NAME, reverse, name); - avahi_free(reverse); + if (!(flags & AVAHI_PUBLISH_NO_REVERSE)) { + char *reverse; - if (ret < 0) - goto fail; - - if (!(reverse = avahi_reverse_lookup_name_ipv6_int(&a->data.ipv6))) { - ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY); - goto fail; + if (!(reverse = avahi_reverse_lookup_name_ipv6_arpa(&a->data.ipv6))) { + ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY); + goto fail; + } + + ret = avahi_server_add_ptr(s, g, interface, protocol, flags | AVAHI_PUBLISH_UNIQUE, AVAHI_DEFAULT_TTL_HOST_NAME, reverse, name); + avahi_free(reverse); + + if (ret < 0) + goto fail; + + if (!(reverse = avahi_reverse_lookup_name_ipv6_int(&a->data.ipv6))) { + ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY); + goto fail; + } + + ret = avahi_server_add_ptr(s, g, interface, protocol, flags | AVAHI_PUBLISH_UNIQUE, AVAHI_DEFAULT_TTL_HOST_NAME, reverse, name); + avahi_free(reverse); } - - ret = avahi_server_add_ptr(s, g, interface, protocol, flags | AVAHI_ENTRY_UNIQUE, AVAHI_DEFAULT_TTL_HOST_NAME, reverse, name); - avahi_free(reverse); } fail: @@ -1792,7 +1824,7 @@ static int server_add_txt_strlst_nocopy( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, - AvahiEntryFlags flags, + AvahiPublishFlags flags, uint32_t ttl, const char *name, AvahiStringList *strlst) { @@ -1801,7 +1833,7 @@ static int server_add_txt_strlst_nocopy( int ret; assert(s); - + if (!(r = avahi_record_new_full(name ? name : s->host_name_fqdn, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_TXT, ttl))) return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY); @@ -1817,7 +1849,7 @@ int avahi_server_add_txt_strlst( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, - AvahiEntryFlags flags, + AvahiPublishFlags flags, uint32_t ttl, const char *name, AvahiStringList *strlst) { @@ -1832,7 +1864,7 @@ int avahi_server_add_txt_va( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, - AvahiEntryFlags flags, + AvahiPublishFlags flags, uint32_t ttl, const char *name, va_list va) { @@ -1847,7 +1879,7 @@ int avahi_server_add_txt( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, - AvahiEntryFlags flags, + AvahiPublishFlags flags, uint32_t ttl, const char *name, ...) { @@ -1907,6 +1939,7 @@ static int server_add_service_strlst_nocopy( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *name, const char *type, const char *domain, @@ -1923,6 +1956,15 @@ static int server_add_service_strlst_nocopy( assert(type); assert(name); + if (!AVAHI_IF_VALID(interface)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_INTERFACE); + + if (!AVAHI_PROTO_VALID(protocol)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PROTOCOL); + + if (!AVAHI_FLAGS_VALID(flags, AVAHI_PUBLISH_NO_COOKIE)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_FLAGS); + if (!avahi_is_valid_service_name(name)) return avahi_server_set_errno(s, AVAHI_ERR_INVALID_SERVICE_NAME); @@ -1953,7 +1995,7 @@ static int server_add_service_strlst_nocopy( snprintf(ptr_name, sizeof(ptr_name), "%s.%s", t, d); snprintf(svc_name, sizeof(svc_name), "%s.%s.%s", ename, t, d); - if ((ret = avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, AVAHI_DEFAULT_TTL, ptr_name, svc_name)) < 0) + if ((ret = avahi_server_add_ptr(s, g, interface, protocol, 0, AVAHI_DEFAULT_TTL, ptr_name, svc_name)) < 0) goto fail; if (!(r = avahi_record_new_full(svc_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV, AVAHI_DEFAULT_TTL_HOST_NAME))) { @@ -1966,22 +2008,23 @@ static int server_add_service_strlst_nocopy( r->data.srv.port = port; r->data.srv.name = h; h = NULL; - ret = avahi_server_add(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, r); + ret = avahi_server_add(s, g, interface, protocol, AVAHI_PUBLISH_UNIQUE, r); avahi_record_unref(r); if (ret < 0) goto fail; - strlst = add_magic_cookie(s, strlst); + if (!(flags & AVAHI_PUBLISH_NO_COOKIE)) + strlst = add_magic_cookie(s, strlst); - ret = server_add_txt_strlst_nocopy(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst); + ret = server_add_txt_strlst_nocopy(s, g, interface, protocol, AVAHI_PUBLISH_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst); strlst = NULL; if (ret < 0) goto fail; snprintf(enum_ptr, sizeof(enum_ptr), "_services._dns-sd._udp.%s", d); - ret = avahi_server_add_ptr(s, g, interface, protocol, AVAHI_ENTRY_NULL, AVAHI_DEFAULT_TTL, enum_ptr, ptr_name); + ret = avahi_server_add_ptr(s, g, interface, protocol, 0, AVAHI_DEFAULT_TTL, enum_ptr, ptr_name); fail: @@ -1999,6 +2042,7 @@ int avahi_server_add_service_strlst( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *name, const char *type, const char *domain, @@ -2010,7 +2054,7 @@ int avahi_server_add_service_strlst( assert(type); assert(name); - return server_add_service_strlst_nocopy(s, g, interface, protocol, name, type, domain, host, port, avahi_string_list_copy(strlst)); + return server_add_service_strlst_nocopy(s, g, interface, protocol, flags, name, type, domain, host, port, avahi_string_list_copy(strlst)); } int avahi_server_add_service_va( @@ -2018,6 +2062,7 @@ int avahi_server_add_service_va( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *name, const char *type, const char *domain, @@ -2029,7 +2074,7 @@ int avahi_server_add_service_va( assert(type); assert(name); - return server_add_service_strlst_nocopy(s, g, interface, protocol, name, type, domain, host, port, avahi_string_list_new_va(va)); + return server_add_service_strlst_nocopy(s, g, interface, protocol, flags, name, type, domain, host, port, avahi_string_list_new_va(va)); } int avahi_server_add_service( @@ -2037,6 +2082,7 @@ int avahi_server_add_service( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *name, const char *type, const char *domain, @@ -2052,7 +2098,7 @@ int avahi_server_add_service( assert(name); va_start(va, port); - ret = avahi_server_add_service_va(s, g, interface, protocol, name, type, domain, host, port, va); + ret = avahi_server_add_service_va(s, g, interface, protocol, flags, name, type, domain, host, port, va); va_end(va); return ret; } @@ -2084,6 +2130,7 @@ int avahi_server_add_dns_server_address( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *domain, AvahiDNSServerType type, const AvahiAddress *address, @@ -2095,23 +2142,33 @@ int avahi_server_add_dns_server_address( assert(s); assert(address); - assert(type == AVAHI_DNS_SERVER_UPDATE || type == AVAHI_DNS_SERVER_RESOLVE); - assert(address->proto == AVAHI_PROTO_INET || address->proto == AVAHI_PROTO_INET6); + if (!AVAHI_IF_VALID(interface)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_INTERFACE); + + if (!AVAHI_PROTO_VALID(protocol) || !AVAHI_PROTO_VALID(address->proto)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PROTOCOL); + + if (!AVAHI_FLAGS_VALID(flags, 0) || (type != AVAHI_DNS_SERVER_UPDATE && type != AVAHI_DNS_SERVER_RESOLVE)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_FLAGS); + if (port == 0) return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PORT); if (domain && !avahi_is_valid_domain_name(domain)) return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME); + if (!domain) + domain = s->domain_name; + if (address->proto == AVAHI_PROTO_INET) { hexstring(h, sizeof(h), &address->data, sizeof(AvahiIPv4Address)); - snprintf(n, sizeof(n), "ip-%s.%s", h, s->domain_name); + snprintf(n, sizeof(n), "ip-%s.%s", h, domain); r = avahi_record_new_full(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A, AVAHI_DEFAULT_TTL_HOST_NAME); r->data.a.address = address->data.ipv4; } else { hexstring(h, sizeof(h), &address->data, sizeof(AvahiIPv6Address)); - snprintf(n, sizeof(n), "ip6-%s.%s", h, s->domain_name); + snprintf(n, sizeof(n), "ip6-%s.%s", h, domain); r = avahi_record_new_full(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA, AVAHI_DEFAULT_TTL_HOST_NAME); r->data.aaaa.address = address->data.ipv6; } @@ -2119,13 +2176,13 @@ int avahi_server_add_dns_server_address( if (!r) return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY); - ret = avahi_server_add(s, g, interface, protocol, AVAHI_ENTRY_UNIQUE | AVAHI_ENTRY_ALLOWMUTIPLE, r); + ret = avahi_server_add(s, g, interface, protocol, AVAHI_PUBLISH_UNIQUE | AVAHI_PUBLISH_ALLOW_MULTIPLE, r); avahi_record_unref(r); if (ret < 0) return ret; - return avahi_server_add_dns_server_name(s, g, interface, protocol, domain, type, n, port); + return avahi_server_add_dns_server_name(s, g, interface, protocol, flags, domain, type, n, port); } int avahi_server_add_dns_server_name( @@ -2133,6 +2190,7 @@ int avahi_server_add_dns_server_name( AvahiSEntryGroup *g, AvahiIfIndex interface, AvahiProtocol protocol, + AvahiPublishFlags flags, const char *domain, AvahiDNSServerType type, const char *name, @@ -2144,8 +2202,16 @@ int avahi_server_add_dns_server_name( assert(s); assert(name); - assert(type == AVAHI_DNS_SERVER_UPDATE || type == AVAHI_DNS_SERVER_RESOLVE); + if (!AVAHI_IF_VALID(interface)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_INTERFACE); + + if (!AVAHI_PROTO_VALID(protocol)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PROTOCOL); + + if (!AVAHI_FLAGS_VALID(flags, 0) || (type != AVAHI_DNS_SERVER_UPDATE && type != AVAHI_DNS_SERVER_RESOLVE)) + return avahi_server_set_errno(s, AVAHI_ERR_INVALID_FLAGS); + if (port == 0) return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PORT); @@ -2154,7 +2220,6 @@ int avahi_server_add_dns_server_name( if (domain && !avahi_is_valid_domain_name(domain)) return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME); - if (!domain) domain = s->domain_name; @@ -2178,7 +2243,7 @@ int avahi_server_add_dns_server_name( r->data.srv.weight = 0; r->data.srv.port = port; r->data.srv.name = n; - ret = avahi_server_add(s, g, interface, protocol, AVAHI_ENTRY_NULL, r); + ret = avahi_server_add(s, g, interface, protocol, AVAHI_PUBLISH_NULL, r); avahi_record_unref(r); return ret; diff --git a/avahi-core/server.h b/avahi-core/server.h index 600e442..3e439f9 100644 --- a/avahi-core/server.h +++ b/avahi-core/server.h @@ -42,6 +42,8 @@ typedef struct AvahiEntry AvahiEntry; #define AVAHI_MAX_LEGACY_UNICAST_REFLECT_SLOTS 100 +#define AVAHI_FLAGS_VALID(flags, max) (!((flags) & ~(max))) + typedef struct AvahiLegacyUnicastReflectSlot AvahiLegacyUnicastReflectSlot; struct AvahiLegacyUnicastReflectSlot { @@ -61,7 +63,7 @@ struct AvahiEntry { int dead; - AvahiEntryFlags flags; + AvahiPublishFlags flags; AvahiRecord *record; AvahiIfIndex interface; AvahiProtocol protocol; diff --git a/avahi-daemon/AddressResolver.introspect b/avahi-daemon/AddressResolver.introspect index 5d6afa7..61a6e9c 100644 --- a/avahi-daemon/AddressResolver.introspect +++ b/avahi-daemon/AddressResolver.introspect @@ -21,7 +21,7 @@ - + diff --git a/avahi-daemon/DomainBrowser.introspect b/avahi-daemon/DomainBrowser.introspect index 3da9e00..85e7e73 100644 --- a/avahi-daemon/DomainBrowser.introspect +++ b/avahi-daemon/DomainBrowser.introspect @@ -19,14 +19,14 @@ - + - + diff --git a/avahi-daemon/EntryGroup.introspect b/avahi-daemon/EntryGroup.introspect index 40ddf3a..51cddf6 100644 --- a/avahi-daemon/EntryGroup.introspect +++ b/avahi-daemon/EntryGroup.introspect @@ -30,6 +30,7 @@ + @@ -41,6 +42,7 @@ + diff --git a/avahi-daemon/HostNameResolver.introspect b/avahi-daemon/HostNameResolver.introspect index 2484100..d3337f9 100644 --- a/avahi-daemon/HostNameResolver.introspect +++ b/avahi-daemon/HostNameResolver.introspect @@ -21,7 +21,7 @@ - + diff --git a/avahi-daemon/Server.introspect b/avahi-daemon/Server.introspect index cb4616c..5d5e862 100644 --- a/avahi-daemon/Server.introspect +++ b/avahi-daemon/Server.introspect @@ -61,28 +61,28 @@ - + - + - + - + @@ -92,7 +92,7 @@ - + @@ -104,7 +104,7 @@ - + @@ -126,7 +126,7 @@ - + @@ -135,7 +135,7 @@ - + @@ -145,7 +145,7 @@ - + @@ -157,7 +157,7 @@ - + @@ -167,7 +167,7 @@ - + @@ -176,7 +176,7 @@ - + diff --git a/avahi-daemon/ServiceBrowser.introspect b/avahi-daemon/ServiceBrowser.introspect index abb065d..350026d 100644 --- a/avahi-daemon/ServiceBrowser.introspect +++ b/avahi-daemon/ServiceBrowser.introspect @@ -21,7 +21,7 @@ - + @@ -30,7 +30,7 @@ - + diff --git a/avahi-daemon/ServiceResolver.introspect b/avahi-daemon/ServiceResolver.introspect index 8d00983..7b752e3 100644 --- a/avahi-daemon/ServiceResolver.introspect +++ b/avahi-daemon/ServiceResolver.introspect @@ -26,7 +26,7 @@ - + diff --git a/avahi-daemon/ServiceTypeBrowser.introspect b/avahi-daemon/ServiceTypeBrowser.introspect index 7e080d6..1540a8f 100644 --- a/avahi-daemon/ServiceTypeBrowser.introspect +++ b/avahi-daemon/ServiceTypeBrowser.introspect @@ -20,7 +20,7 @@ - + @@ -28,7 +28,7 @@ - + diff --git a/avahi-daemon/dbus-protocol.c b/avahi-daemon/dbus-protocol.c index e5b0998..9270168 100644 --- a/avahi-daemon/dbus-protocol.c +++ b/avahi-daemon/dbus-protocol.c @@ -786,6 +786,7 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddService")) { int32_t interface, protocol; + uint32_t flags; char *type, *name, *domain, *host; uint16_t port; AvahiStringList *strlst; @@ -796,6 +797,7 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, m, &error, DBUS_TYPE_INT32, &interface, DBUS_TYPE_INT32, &protocol, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, @@ -808,7 +810,7 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, dbus_message_iter_init(m, &iter); - for (j = 0; j < 7; j++) + for (j = 0; j < 8; j++) dbus_message_iter_next(&iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || @@ -854,7 +856,7 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, if (host && !*host) host = NULL; - if (avahi_server_add_service_strlst(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, type, domain, host, port, strlst) < 0) { + if (avahi_server_add_service_strlst(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, name, type, domain, host, port, strlst) < 0) { avahi_string_list_free(strlst); return respond_error(c, m, avahi_server_errno(avahi_server), NULL); } else @@ -866,6 +868,7 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddAddress")) { int32_t interface, protocol; + uint32_t flags; char *name, *address; AvahiAddress a; @@ -873,6 +876,7 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, m, &error, DBUS_TYPE_INT32, &interface, DBUS_TYPE_INT32, &protocol, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID) || !name || !address) { @@ -889,7 +893,7 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, return respond_error(c, m, AVAHI_ERR_INVALID_ADDRESS, NULL); } - if (avahi_server_add_address(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, 0, name, &a) < 0) + if (avahi_server_add_address(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, name, &a) < 0) return respond_error(c, m, avahi_server_errno(avahi_server), NULL); else i->n_entries ++; @@ -915,7 +919,8 @@ static void sync_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIfI if (event == AVAHI_RESOLVER_FOUND) { char t[256], *pt = t; - int32_t i_interface, i_protocol, i_aprotocol, i_flags; + int32_t i_interface, i_protocol, i_aprotocol; + uint32_t u_flags; DBusMessage *reply; assert(a); @@ -924,7 +929,7 @@ static void sync_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIfI i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; i_aprotocol = (int32_t) a->proto; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; reply = dbus_message_new_method_return(i->message); dbus_message_append_args( @@ -934,7 +939,7 @@ static void sync_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIfI DBUS_TYPE_STRING, &host_name, DBUS_TYPE_INT32, &i_aprotocol, DBUS_TYPE_STRING, &pt, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); dbus_connection_send(server->bus, reply, NULL); @@ -954,7 +959,8 @@ static void sync_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfInde if (event == AVAHI_RESOLVER_FOUND) { char t[256], *pt = t; - int32_t i_interface, i_protocol, i_aprotocol, i_flags; + int32_t i_interface, i_protocol, i_aprotocol; + uint32_t u_flags; DBusMessage *reply; assert(host_name); @@ -963,7 +969,7 @@ static void sync_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfInde i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; i_aprotocol = (int32_t) address->proto; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; reply = dbus_message_new_method_return(i->message); dbus_message_append_args( @@ -973,7 +979,7 @@ static void sync_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfInde DBUS_TYPE_INT32, &i_aprotocol, DBUS_TYPE_STRING, &pt, DBUS_TYPE_STRING, &host_name, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); dbus_connection_send(server->bus, reply, NULL); @@ -1031,14 +1037,15 @@ fail: static void domain_browser_callback(AvahiSDomainBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *domain, AvahiLookupResultFlags flags, void* userdata) { DomainBrowserInfo *i = userdata; DBusMessage *m; - int32_t i_interface, i_protocol, i_flags; + int32_t i_interface, i_protocol; + uint32_t u_flags; assert(b); assert(i); i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, map_browse_signal_name(event)); @@ -1049,7 +1056,7 @@ static void domain_browser_callback(AvahiSDomainBrowser *b, AvahiIfIndex interfa DBUS_TYPE_INT32, &i_interface, DBUS_TYPE_INT32, &i_protocol, DBUS_TYPE_STRING, &domain, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); } @@ -1105,14 +1112,15 @@ fail: static void service_type_browser_callback(AvahiSServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *type, const char *domain, AvahiLookupResultFlags flags, void* userdata) { ServiceTypeBrowserInfo *i = userdata; DBusMessage *m; - int32_t i_interface, i_protocol, i_flags; + int32_t i_interface, i_protocol; + uint32_t u_flags; assert(b); assert(i); i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, map_browse_signal_name(event)); @@ -1125,7 +1133,7 @@ static void service_type_browser_callback(AvahiSServiceTypeBrowser *b, AvahiIfIn DBUS_TYPE_INT32, &i_protocol, DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); } @@ -1181,14 +1189,15 @@ fail: static void service_browser_callback(AvahiSServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void* userdata) { ServiceBrowserInfo *i = userdata; DBusMessage *m; - int32_t i_interface, i_protocol, i_flags; + int32_t i_interface, i_protocol; + uint32_t u_flags; assert(b); assert(i); i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, map_browse_signal_name(event)); @@ -1204,7 +1213,7 @@ static void service_browser_callback(AvahiSServiceBrowser *b, AvahiIfIndex inter DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); } @@ -1256,7 +1265,8 @@ static void sync_service_resolver_callback( if (event == AVAHI_RESOLVER_FOUND) { char t[256], *pt = t; - int32_t i_interface, i_protocol, i_aprotocol, i_flags; + int32_t i_interface, i_protocol, i_aprotocol; + uint32_t u_flags; DBusMessage *reply; assert(host_name); @@ -1270,7 +1280,7 @@ static void sync_service_resolver_callback( i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; i_aprotocol = (int32_t) a->proto; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; reply = dbus_message_new_method_return(i->message); dbus_message_append_args( @@ -1290,7 +1300,7 @@ static void sync_service_resolver_callback( dbus_message_append_args( reply, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); dbus_connection_send(server->bus, reply, NULL); @@ -1312,7 +1322,8 @@ static void async_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfInd if (event == AVAHI_RESOLVER_FOUND) { char t[256], *pt = t; - int32_t i_interface, i_protocol, i_aprotocol, i_flags; + int32_t i_interface, i_protocol, i_aprotocol; + uint32_t u_flags; assert(address); assert(host_name); @@ -1321,7 +1332,7 @@ static void async_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfInd i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; i_aprotocol = (int32_t) address->proto; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; dbus_message_append_args( reply, @@ -1330,7 +1341,7 @@ static void async_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfInd DBUS_TYPE_INT32, &i_aprotocol, DBUS_TYPE_STRING, &pt, DBUS_TYPE_STRING, &host_name, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); } @@ -1395,7 +1406,8 @@ static void async_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIf if (event == AVAHI_RESOLVER_FOUND) { char t[256], *pt = t; - int32_t i_interface, i_protocol, i_aprotocol, i_flags; + int32_t i_interface, i_protocol, i_aprotocol; + uint32_t u_flags; assert(a); assert(host_name); @@ -1404,7 +1416,7 @@ static void async_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIf i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; i_aprotocol = (int32_t) a->proto; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; dbus_message_append_args( reply, @@ -1413,7 +1425,7 @@ static void async_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIf DBUS_TYPE_STRING, &host_name, DBUS_TYPE_INT32, &i_aprotocol, DBUS_TYPE_STRING, &pt, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); } @@ -1490,7 +1502,8 @@ static void async_service_resolver_callback( if (event == AVAHI_RESOLVER_FOUND) { char t[256], *pt = t; - int32_t i_interface, i_protocol, i_aprotocol, i_flags; + int32_t i_interface, i_protocol, i_aprotocol; + uint32_t u_flags; assert(host_name); @@ -1505,7 +1518,7 @@ static void async_service_resolver_callback( i_interface = (int32_t) interface; i_protocol = (int32_t) protocol; i_aprotocol = (int32_t) a->proto; - i_flags = (int32_t) flags; + u_flags = (uint32_t) flags; dbus_message_append_args( reply, @@ -1524,7 +1537,7 @@ static void async_service_resolver_callback( dbus_message_append_args( reply, - DBUS_TYPE_INT32, &i_flags, + DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); } @@ -1811,7 +1824,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveHostName")) { Client *client; - int32_t interface, protocol, aprotocol, flags; + int32_t interface, protocol, aprotocol; + uint32_t flags; char *name; SyncHostNameResolverInfo *i; @@ -1821,7 +1835,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &name, DBUS_TYPE_INT32, &aprotocol, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || !name) { avahi_log_warn("Error parsing Server::ResolveHostName message"); goto fail; @@ -1852,7 +1866,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveAddress")) { Client *client; - int32_t interface, protocol, flags; + int32_t interface, protocol; + uint32_t flags; char *address; SyncAddressResolverInfo *i; AvahiAddress a; @@ -1862,7 +1877,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void DBUS_TYPE_INT32, &interface, DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &address, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || !address) { avahi_log_warn("Error parsing Server::ResolveAddress message"); goto fail; @@ -1905,7 +1920,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void NULL, NULL }; - int32_t interface, protocol, type, flags; + int32_t interface, protocol, type; + uint32_t flags; char *domain; if (!dbus_message_get_args( @@ -1914,7 +1930,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INT32, &type, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || type < 0 || type >= AVAHI_DOMAIN_BROWSER_MAX) { avahi_log_warn("Error parsing Server::DomainBrowserNew message"); goto fail; @@ -1959,7 +1975,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void NULL, NULL }; - int32_t interface, protocol, flags; + int32_t interface, protocol; + uint32_t flags; char *domain; if (!dbus_message_get_args( @@ -1967,7 +1984,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void DBUS_TYPE_INT32, &interface, DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &domain, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID)) { avahi_log_warn("Error parsing Server::ServiceTypeBrowserNew message"); goto fail; @@ -2013,7 +2030,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void NULL, NULL }; - int32_t interface, protocol, flags; + int32_t interface, protocol; + uint32_t flags; char *domain, *type; if (!dbus_message_get_args( @@ -2022,7 +2040,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || !type) { avahi_log_warn("Error parsing Server::ServiceBrowserNew message"); goto fail; @@ -2059,7 +2077,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveService")) { Client *client; - int32_t interface, protocol, aprotocol, flags; + int32_t interface, protocol, aprotocol; + uint32_t flags; char *name, *type, *domain; SyncServiceResolverInfo *i; @@ -2071,7 +2090,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INT32, &aprotocol, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || !type) { avahi_log_warn("Error parsing Server::ResolveService message"); goto fail; @@ -2108,7 +2127,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ServiceResolverNew")) { Client *client; - int32_t interface, protocol, aprotocol, flags; + int32_t interface, protocol, aprotocol; + uint32_t flags; char *name, *type, *domain; AsyncServiceResolverInfo *i; static const DBusObjectPathVTable vtable = { @@ -2128,7 +2148,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void DBUS_TYPE_STRING, &type, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INT32, &aprotocol, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || !type) { avahi_log_warn("Error parsing Server::ServiceResolverNew message"); goto fail; @@ -2169,7 +2189,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "HostNameResolverNew")) { Client *client; - int32_t interface, protocol, aprotocol, flags; + int32_t interface, protocol, aprotocol; + uint32_t flags; char *name; AsyncHostNameResolverInfo *i; static const DBusObjectPathVTable vtable = { @@ -2187,7 +2208,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &name, DBUS_TYPE_INT32, &aprotocol, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || !name) { avahi_log_warn("Error parsing Server::HostNameResolverNew message"); goto fail; @@ -2220,7 +2241,8 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "AddressResolverNew")) { Client *client; - int32_t interface, protocol, flags; + int32_t interface, protocol; + uint32_t flags; char *address; AsyncAddressResolverInfo *i; AvahiAddress a; @@ -2238,7 +2260,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void DBUS_TYPE_INT32, &interface, DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &address, - DBUS_TYPE_INT32, &flags, + DBUS_TYPE_UINT32, &flags, DBUS_TYPE_INVALID) || !address) { avahi_log_warn("Error parsing Server::AddressResolverNew message"); goto fail; diff --git a/avahi-daemon/main.c b/avahi-daemon/main.c index 07d7127..de74178 100644 --- a/avahi-daemon/main.c +++ b/avahi-daemon/main.c @@ -178,7 +178,7 @@ static AvahiSEntryGroup* add_dns_servers(AvahiServer *s, AvahiSEntryGroup* g, ch if (!avahi_address_parse(*p, AVAHI_PROTO_UNSPEC, &a)) avahi_log_warn("Failed to parse address '%s', ignoring.", *p); else - if (avahi_server_add_dns_server_address(s, g, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, NULL, AVAHI_DNS_SERVER_RESOLVE, &a, 53) < 0) { + if (avahi_server_add_dns_server_address(s, g, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, NULL, AVAHI_DNS_SERVER_RESOLVE, &a, 53) < 0) { avahi_s_entry_group_free(g); avahi_log_error("Failed to add DNS server address: %s", avahi_strerror(avahi_server_errno(s))); return NULL; diff --git a/avahi-daemon/static-services.c b/avahi-daemon/static-services.c index e459bbc..09777cc 100644 --- a/avahi-daemon/static-services.c +++ b/avahi-daemon/static-services.c @@ -221,7 +221,8 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) { if (avahi_server_add_service_strlst( avahi_server, g->entry_group, - -1, s->protocol, + AVAHI_IF_UNSPEC, s->protocol, + 0, g->chosen_name, s->type, s->domain_name, s->host_name, s->port, s->txt_records) < 0) { diff --git a/examples/client-publish-service.c b/examples/client-publish-service.c index 9b12f5c..c3f11ad 100644 --- a/examples/client-publish-service.c +++ b/examples/client-publish-service.c @@ -83,13 +83,13 @@ static void create_services(AvahiClient *c) { snprintf(r, sizeof(r), "random=%i", rand()); /* Add the service for IPP */ - if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, name, "_ipp._tcp", NULL, NULL, 651, "test=blah", r, NULL)) < 0) { + if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_ipp._tcp", NULL, NULL, 651, "test=blah", r, NULL)) < 0) { fprintf(stderr, "Failed to add _ipp._tcp service: %s\n", avahi_strerror(ret)); goto fail; } /* Add the same service for BSD LPR */ - if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, name, "_printer._tcp", NULL, NULL, 515, NULL)) < 0) { + if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_printer._tcp", NULL, NULL, 515, NULL)) < 0) { fprintf(stderr, "Failed to add _printer._tcp service: %s\n", avahi_strerror(ret)); goto fail; } diff --git a/examples/core-publish-service.c b/examples/core-publish-service.c index 67f88db..62badf3 100644 --- a/examples/core-publish-service.c +++ b/examples/core-publish-service.c @@ -85,13 +85,13 @@ static void create_services(AvahiServer *s) { snprintf(r, sizeof(r), "random=%i", rand()); /* Add the service for IPP */ - if ((ret = avahi_server_add_service(s, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, name, "_ipp._tcp", NULL, NULL, 651, "test=blah", r, NULL)) < 0) { + if ((ret = avahi_server_add_service(s, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_ipp._tcp", NULL, NULL, 651, "test=blah", r, NULL)) < 0) { fprintf(stderr, "Failed to add _ipp._tcp service: %s\n", avahi_strerror(ret)); goto fail; } /* Add the same service for BSD LPR */ - if ((ret = avahi_server_add_service(s, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, name, "_printer._tcp", NULL, NULL, 515, NULL)) < 0) { + if ((ret = avahi_server_add_service(s, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_printer._tcp", NULL, NULL, 515, NULL)) < 0) { fprintf(stderr, "Failed to add _printer._tcp service: %s\n", avahi_strerror(ret)); goto fail; }