]> git.meshlink.io Git - catta/blobdiff - avahi-core/server.c
* remove AVAHI_PUBLISH_IS_PROXY, it was a bad idea
[catta] / avahi-core / server.c
index 40d437e78f0a42013b5c5ac247c65b6f2b731c2a..a1486f88935e52148d65d7c70fab7ebe6b9461e2 100644 (file)
 #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;
@@ -1075,19 +1076,13 @@ void avahi_server_decrease_host_rr_pending(AvahiServer *s) {
         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)) {
@@ -1178,7 +1173,7 @@ static void register_stuff(AvahiServer *s) {
     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);
@@ -1571,17 +1566,40 @@ uint32_t avahi_server_get_local_service_cookie(AvahiServer *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);
 
@@ -1597,21 +1615,54 @@ int avahi_server_is_service_local(AvahiServer *s, AvahiIfIndex interface, AvahiP
     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 */