]> git.meshlink.io Git - catta/commitdiff
add new public function avahi_server_is_service_local()
authorLennart Poettering <lennart@poettering.net>
Sat, 10 Sep 2005 02:20:51 +0000 (02:20 +0000)
committerLennart Poettering <lennart@poettering.net>
Sat, 10 Sep 2005 02:20:51 +0000 (02:20 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@561 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-core/core.h
avahi-core/server.c

index 427a09a36298005b47d05cf2186e9ad9b55c4a8b..abc30c00635a9c45e0ae08b656b06a7d5276845a 100644 (file)
@@ -568,6 +568,9 @@ int avahi_server_errno(AvahiServer *s);
 /** Return the local service cookie */
 uint32_t avahi_server_get_local_service_cookie(AvahiServer *s);
 
+/** Return 1 if there is a local service with the specified credentials registeresd. Return 0 if not, negative on failure */
+int avahi_server_is_service_local(AvahiServer *s, AvahiIfIndex, AvahiProtocol protocol, const char *name, const char *type,  const char*domain);
+
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 AVAHI_C_DECL_END
 #endif
index 625af50f349cbe911ef9043721e6eb7ea5695f6f..11deb249d9f2a4ebd2e88d561f2680f5822583e1 100644 (file)
@@ -2464,3 +2464,69 @@ 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) {
+    AvahiKey *key = NULL;
+    char *d, *t;
+    char ename[64], n[256];
+    int ret;
+    AvahiEntry *e;
+    
+    assert(s);
+    assert(name);
+    assert(type);
+    assert(domain);
+
+    if (!avahi_is_valid_service_name(name))
+        return avahi_server_set_errno(s, AVAHI_ERR_INVALID_SERVICE_NAME);
+
+    if (!avahi_is_valid_service_type(type))
+        return avahi_server_set_errno(s, AVAHI_ERR_INVALID_SERVICE_TYPE);
+
+    if (domain && !avahi_is_valid_domain_name(domain))
+        return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);
+
+    escape_service_name(ename, sizeof(ename), name);
+    
+    if (!(d = avahi_normalize_name(domain)) ||
+        !(t = avahi_normalize_name(type))) {
+        ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
+        goto fail;
+    }
+    snprintf(n, sizeof(n), "%s.%s.%s", ename, t, d);
+    
+    if (!(key = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV))) {
+        ret = avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
+        goto fail;
+    }
+
+    ret = 0;
+    
+    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)) {
+            ret = 1;
+            break;
+        }
+    }
+    
+    avahi_key_unref(key);
+    
+    avahi_free(d);
+    avahi_free(t);
+
+    return ret;
+    
+fail:
+    if (d)
+        avahi_free(d);
+
+    if (t)
+        avahi_free(t);
+
+    if (key)
+        avahi_key_unref(key);
+
+    return ret;
+}