#include <avahi-common/malloc.h>
#include <avahi-common/error.h>
-#include "server.h"
+#include "internal.h"
#include "iface.h"
#include "socket.h"
#include "browse.h"
#include "log.h"
#include "util.h"
+#include "dns-srv-rr.h"
static void enum_aux_records(AvahiServer *s, AvahiInterface *i, const char *name, uint16_t type, void (*callback)(AvahiServer *s, AvahiRecord *r, int flush_cache, void* userdata), void* userdata) {
AvahiKey *k;
server_set_state(s, AVAHI_SERVER_RUNNING);
}
-void avahi_server_increase_host_rr_pending(AvahiServer *s) {
- assert(s);
-
- s->n_host_rr_pending ++;
-}
-
void avahi_host_rr_entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void *userdata) {
assert(s);
assert(g);
if (state == AVAHI_ENTRY_GROUP_REGISTERING &&
s->state == AVAHI_SERVER_REGISTERING)
- avahi_server_increase_host_rr_pending(s);
+ s->n_host_rr_pending ++;
else if (state == AVAHI_ENTRY_GROUP_COLLISION &&
(s->state == AVAHI_SERVER_REGISTERING || s->state == AVAHI_SERVER_RUNNING)) {
assert(s);
server_set_state(s, AVAHI_SERVER_REGISTERING);
- s->n_host_rr_pending ++; /** Make sure that the state isn't changed tp AVAHI_SERVER_RUNNING too early */
+ s->n_host_rr_pending ++; /** Make sure that the state isn't changed tp AVAHI_SERVER_RUNNING too early */
register_hinfo(s);
register_browse_domain(s);
return s->local_service_cookie;
}
-int avahi_server_is_service_local(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char*domain) {
+static AvahiEntry *find_entry(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiKey *key) {
+ AvahiEntry *e;
+
+ assert(s);
+ assert(key);
+
+ for (e = avahi_hashmap_lookup(s->entries_by_key, key); e; e = e->by_key_next)
+
+ if ((e->interface == interface || e->interface <= 0 || interface <= 0) &&
+ (e->protocol == protocol || e->protocol == AVAHI_PROTO_UNSPEC || protocol == AVAHI_PROTO_UNSPEC) &&
+ (!e->group || e->group->state == AVAHI_ENTRY_GROUP_ESTABLISHED || e->group->state == AVAHI_ENTRY_GROUP_REGISTERING))
+
+ return e;
+
+ return NULL;
+}
+
+int avahi_server_get_group_of_service(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, AvahiSEntryGroup** ret_group) {
AvahiKey *key = NULL;
- char n[256];
- int ret;
AvahiEntry *e;
+ int ret;
+ char n[AVAHI_DOMAIN_NAME_MAX];
assert(s);
assert(name);
assert(type);
- assert(domain);
+ assert(ret_group);
+
+ if (!AVAHI_IF_VALID(interface))
+ return avahi_server_set_errno(s, AVAHI_ERR_INVALID_INTERFACE);
+ if (!AVAHI_IF_VALID(protocol))
+ return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PROTOCOL);
+
if (!avahi_is_valid_service_name(name))
return avahi_server_set_errno(s, AVAHI_ERR_INVALID_SERVICE_NAME);
if (!(key = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV)))
return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
- ret = 0;
-
- for (e = avahi_hashmap_lookup(s->entries_by_key, key); e; e = e->by_key_next) {
+ e = find_entry(s, interface, protocol, key);
+ avahi_key_unref(key);
- if ((e->interface == interface || e->interface <= 0 || interface <= 0) &&
- (e->protocol == protocol || e->protocol == AVAHI_PROTO_UNSPEC || protocol == AVAHI_PROTO_UNSPEC) &&
- !(e->flags & AVAHI_PUBLISH_IS_PROXY)) {
- ret = 1;
- break;
- }
+ if (e) {
+ *ret_group = e->group;
+ return AVAHI_OK;
}
+
+ return avahi_server_set_errno(s, AVAHI_ERR_NOT_FOUND);
+}
+
+int avahi_server_is_service_local(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, const char *name) {
+ AvahiKey *key = NULL;
+ AvahiEntry *e;
+
+ assert(s);
+ assert(name);
+
+ if (!s->host_name_fqdn)
+ return 0;
+ if (!(key = avahi_key_new(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV)))
+ return 0;
+
+ e = find_entry(s, interface, protocol, key);
avahi_key_unref(key);
+
+ if (!e)
+ return 0;
- return ret;
+ return avahi_domain_equal(s->host_name_fqdn, e->record->data.srv.name);
+}
+
+int avahi_server_is_record_local(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiRecord *record) {
+ AvahiEntry *e;
+
+ assert(s);
+ assert(record);
+
+ for (e = avahi_hashmap_lookup(s->entries_by_key, record->key); e; e = e->by_key_next)
+
+ if ((e->interface == interface || e->interface <= 0 || interface <= 0) &&
+ (e->protocol == protocol || e->protocol == AVAHI_PROTO_UNSPEC || protocol == AVAHI_PROTO_UNSPEC) &&
+ (!e->group || e->group->state == AVAHI_ENTRY_GROUP_ESTABLISHED || e->group->state == AVAHI_ENTRY_GROUP_REGISTERING) &&
+ avahi_record_equal_no_ttl(record, e->record))
+ return 1;
+
+ return 0;
}
/** Set the wide area DNS servers */