[avahi] AvahiPublishFlags#AVAHI_PUBLISH_UPDATE what does it mean?
Ruoruo Zhang(Lily)
lilyruo at gmail.com
Fri Jun 14 21:13:45 PDT 2013
I am trying to understand different AvahiPublishFlags to choose a right
one. What does AvahiPublishFlags#AVAHI_PUBLISH_UPDATE mean?
Documentation says:
Update existing records instead of adding new ones.
Reference:
http://avahi.org/download/doxygen/defs_8h.html#a4b10ef40d32caa6ef2e2d62cae00b4a3
I traced the implementation into entry.c#server_add_service_strlst_nocopy()
as follows but still, AVAHI_PUBLISH_UPDATE is only used for error checking.
Any help is welcomed
static int server_add_service_strlst_nocopy(
AvahiServer *s,
AvahiSEntryGroup *g,
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiPublishFlags flags,
const char *name,
const char *type,
const char *domain,
const char *host,
uint16_t port,
AvahiStringList *strlst) {
char ptr_name[AVAHI_DOMAIN_NAME_MAX], svc_name[AVAHI_DOMAIN_NAME_MAX],
enum_ptr[AVAHI_DOMAIN_NAME_MAX], *h = NULL;
AvahiRecord *r = NULL;
int ret = AVAHI_OK;
AvahiEntry *srv_entry = NULL, *txt_entry = NULL, *ptr_entry = NULL,
*enum_entry = NULL;
assert(s);
assert(type);
assert(name);
AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_IF_VALID(interface),
AVAHI_ERR_INVALID_INTERFACE);
AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_PROTO_VALID(protocol),
AVAHI_ERR_INVALID_PROTOCOL);
AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_FLAGS_VALID(flags,
AVAHI_PUBLISH_NO_COOKIE|
AVAHI_PUBLISH_UPDATE|
AVAHI_PUBLISH_USE_WIDE_AREA|
AVAHI_PUBLISH_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS);
AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s,
avahi_is_valid_service_name(name), AVAHI_ERR_INVALID_SERVICE_NAME);
AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s,
avahi_is_valid_service_type_strict(type), AVAHI_ERR_INVALID_SERVICE_TYPE);
AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, !domain ||
avahi_is_valid_domain_name(domain), AVAHI_ERR_INVALID_DOMAIN_NAME);
AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, !host ||
avahi_is_valid_fqdn(host), AVAHI_ERR_INVALID_HOST_NAME);
if (!domain)
domain = s->domain_name;
if (!host)
host = s->host_name_fqdn;
transport_flags_from_domain(s, &flags, domain);
AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, flags &
AVAHI_PUBLISH_USE_MULTICAST, AVAHI_ERR_NOT_SUPPORTED);
if (!(h = avahi_normalize_name_strdup(host))) {
ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
goto fail;
}
if ((ret = avahi_service_name_join(svc_name, sizeof(svc_name), name,
type, domain)) < 0 ||
(ret = avahi_service_name_join(ptr_name, sizeof(ptr_name), NULL,
type, domain)) < 0 ||
(ret = avahi_service_name_join(enum_ptr, sizeof(enum_ptr), NULL,
"_services._dns-sd._udp", domain)) < 0) {
avahi_server_set_errno(s, ret);
goto fail;
}
/* Add service enumeration PTR record */
if (!(ptr_entry = server_add_ptr_internal(s, g, interface, protocol, 0,
AVAHI_DEFAULT_TTL, ptr_name, svc_name))) {
ret = avahi_server_errno(s);
goto fail;
}
/* Add SRV record */
if (!(r = avahi_record_new_full(svc_name, AVAHI_DNS_CLASS_IN,
AVAHI_DNS_TYPE_SRV, AVAHI_DEFAULT_TTL_HOST_NAME))) {
ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
goto fail;
}
r->data.srv.priority = 0;
r->data.srv.weight = 0;
r->data.srv.port = port;
r->data.srv.name = h;
h = NULL;
srv_entry = server_add_internal(s, g, interface, protocol,
AVAHI_PUBLISH_UNIQUE, r);
avahi_record_unref(r);
if (!srv_entry) {
ret = avahi_server_errno(s);
goto fail;
}
/* Add TXT record */
if (!(flags & AVAHI_PUBLISH_NO_COOKIE))
strlst = add_magic_cookie(s, strlst);
txt_entry = server_add_txt_strlst_nocopy(s, g, interface, protocol,
AVAHI_PUBLISH_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst);
strlst = NULL;
if (!txt_entry) {
ret = avahi_server_errno(s);
goto fail;
}
/* Add service type enumeration record */
if (!(enum_entry = server_add_ptr_internal(s, g, interface, protocol,
0, AVAHI_DEFAULT_TTL, enum_ptr, ptr_name))) {
ret = avahi_server_errno(s);
goto fail;
}
fail:
if (ret != AVAHI_OK && !(flags & AVAHI_PUBLISH_UPDATE)) {
if (srv_entry)
avahi_entry_free(s, srv_entry);
if (txt_entry)
avahi_entry_free(s, txt_entry);
if (ptr_entry)
avahi_entry_free(s, ptr_entry);
if (enum_entry)
avahi_entry_free(s, enum_entry);
}
avahi_string_list_free(strlst);
avahi_free(h);
return ret;
}
Ruoruo Zhang(Lily)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/avahi/attachments/20130614/e618ef78/attachment.html>
More information about the avahi
mailing list