]> git.meshlink.io Git - catta/commitdiff
* add support for subtypes for static services
authorLennart Poettering <lennart@poettering.net>
Wed, 26 Oct 2005 02:03:11 +0000 (02:03 +0000)
committerLennart Poettering <lennart@poettering.net>
Wed, 26 Oct 2005 02:03:11 +0000 (02:03 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@875 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-daemon/avahi-service.dtd
avahi-daemon/example.service
avahi-daemon/static-services.c
docs/TODO
man/avahi.service.5.xml.in

index 8ac1ca62078cddbf3a4502e1c5949a1c3e355e30..c3c25e23b732889cf49d4c6e6477e054243e8132 100644 (file)
@@ -4,10 +4,12 @@
 <!ATTLIST service-group>
 <!ELEMENT name (#PCDATA)>
 <!ATTLIST name replace-wildcards (yes|no) "no">
-<!ELEMENT service (type,domain-name?,host-name?,port,txt-record*)>
+<!ELEMENT service (type,subtype*,domain-name?,host-name?,port,txt-record*)>
 <!ATTLIST service protocol (ipv4|ipv6|any) "any">
 <!ELEMENT type (#PCDATA)>
 <!ATTLIST type>
+<!ELEMENT subtype (#PCDATA)>
+<!ATTLIST subtype>
 <!ELEMENT domain-name (#PCDATA)>
 <!ATTLIST domain-name>
 <!ELEMENT host-name (#PCDATA)>
index 0e565b9a0523fa9268f6f88b79f7b6383b560a11..27d8a1950a695f98dbe984e9e823be81d57fec8e 100644 (file)
@@ -13,6 +13,7 @@
 
   <service>
     <type>_ipp._tcp</type>
+    <subtype>_foo._sub._ipp._tcp</subtype>
     <port>631</port>
   </service>
 
index 09777cca847224808f06e21f021a7a8f6161a5d0..5eba8b2059a8f2461e13a75be9ba91b8eaa65a9e 100644 (file)
@@ -55,6 +55,8 @@ struct StaticService {
     uint16_t port;
     int protocol;
 
+    AvahiStringList *subtypes;
+    
     AvahiStringList *txt_records;
     
     AVAHI_LLIST_FIELDS(StaticService, services);
@@ -117,6 +119,7 @@ static StaticService *static_service_new(StaticServiceGroup *group) {
     s->protocol = AVAHI_PROTO_UNSPEC;
 
     s->txt_records = NULL;
+    s->subtypes = NULL;
 
     AVAHI_LLIST_PREPEND(StaticService, services, group->services, s);
 
@@ -150,6 +153,7 @@ static void static_service_free(StaticService *s) {
     avahi_free(s->domain_name);
 
     avahi_string_list_free(s->txt_records);
+    avahi_string_list_free(s->subtypes);
     
     avahi_free(s);
 }
@@ -176,21 +180,37 @@ static void entry_group_callback(AvahiServer *s, AvahiSEntryGroup *eg, AvahiEntr
     
     assert(s);
     assert(g);
-    
-    if (state == AVAHI_ENTRY_GROUP_COLLISION) {
-        char *n;
 
-        remove_static_service_group_from_server(g);
-
-        n = avahi_alternative_service_name(g->chosen_name);
-        avahi_free(g->chosen_name);
-        g->chosen_name = n;
+    switch (state) {
+        
+        case AVAHI_ENTRY_GROUP_COLLISION: {
+            char *n;
+            
+            remove_static_service_group_from_server(g);
+            
+            n = avahi_alternative_service_name(g->chosen_name);
+            avahi_free(g->chosen_name);
+            g->chosen_name = n;
+            
+            avahi_log_notice("Service name conflict for \"%s\" (%s), retrying with \"%s\".", g->name, g->filename, g->chosen_name);
+            
+            add_static_service_group_to_server(g);
+            break;
+        }
+            
+        case AVAHI_ENTRY_GROUP_ESTABLISHED: 
+            avahi_log_info("Service \"%s\" (%s) successfully established.", g->chosen_name, g->filename);
+            break;
 
-        avahi_log_notice("Service name conflict for \"%s\" (%s), retrying with \"%s\".", g->name, g->filename, g->chosen_name);
+        case AVAHI_ENTRY_GROUP_FAILURE: 
+            avahi_log_warn("Failed to publish service \"%s\" (%s): %s", g->chosen_name, g->filename, avahi_strerror(avahi_server_errno(s)));
+            remove_static_service_group_from_server(g);
+            break;
 
-        add_static_service_group_to_server(g);
-    } else if (state == AVAHI_ENTRY_GROUP_ESTABLISHED)
-        avahi_log_info("Service \"%s\" (%s) successfully established.", g->chosen_name, g->filename);
+        case AVAHI_ENTRY_GROUP_UNCOMMITED:
+        case AVAHI_ENTRY_GROUP_REGISTERING:
+            ;
+    }
 }
 
 static void add_static_service_group_to_server(StaticServiceGroup *g) {
@@ -217,14 +237,15 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) {
     assert(avahi_s_entry_group_is_empty(g->entry_group));
     
     for (s = g->services; s; s = s->services_next) {
+        AvahiStringList *i;
 
         if (avahi_server_add_service_strlst(
                 avahi_server,
                 g->entry_group,
                 AVAHI_IF_UNSPEC, s->protocol,
                 0, 
-                g->chosen_name, s->type, 
-                s->domain_name, s->host_name, s->port,
+                g->chosen_name, s->type, s->domain_name,
+                s->host_name, s->port,
                 s->txt_records) < 0) {
             avahi_log_error("Failed to add service '%s' of type '%s', ignoring service group (%s): %s",
                             g->chosen_name, s->type, g->filename,
@@ -232,6 +253,22 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) {
             remove_static_service_group_from_server(g);
             return;
         }
+
+        for (i = s->subtypes; i; i = i->next) {
+
+            if (avahi_server_add_service_subtype(
+                    avahi_server,
+                    g->entry_group,
+                    AVAHI_IF_UNSPEC, s->protocol,
+                    0,
+                    g->chosen_name, s->type, s->domain_name,
+                    (char*) i->text) < 0) {
+                
+                avahi_log_error("Failed to add subtype '%s' for service '%s' of type '%s', ignoring subtype (%s): %s",
+                                i->text, g->chosen_name, s->type, g->filename,
+                                avahi_strerror(avahi_server_errno(avahi_server)));
+            }
+        }
     }
 
     avahi_s_entry_group_commit(g->entry_group);
@@ -250,6 +287,7 @@ typedef enum {
     XML_TAG_NAME,
     XML_TAG_SERVICE,
     XML_TAG_TYPE,
+    XML_TAG_SUBTYPE,
     XML_TAG_DOMAIN_NAME,
     XML_TAG_HOST_NAME,
     XML_TAG_PORT,
@@ -326,6 +364,11 @@ static void XMLCALL xml_start(void *data, const char *el, const char *attr[]) {
             goto invalid_attr;
 
         u->current_tag = XML_TAG_TYPE;
+    } else if (u->current_tag == XML_TAG_SERVICE && strcmp(el, "subtype") == 0) {
+        if (attr[0])
+            goto invalid_attr;
+
+        u->current_tag = XML_TAG_SUBTYPE;
     } else if (u->current_tag == XML_TAG_SERVICE && strcmp(el, "domain-name") == 0) {
         if (attr[0])
             goto invalid_attr;
@@ -419,6 +462,14 @@ static void XMLCALL xml_end(void *data, const char *el) {
             u->current_tag = XML_TAG_SERVICE;
             break;
         }
+
+        case XML_TAG_SUBTYPE: {
+            assert(u->service);
+            
+            u->service->subtypes = avahi_string_list_add(u->service->subtypes, u->buf ? u->buf : "");
+            u->current_tag = XML_TAG_SERVICE;
+            break;
+        }
             
         case XML_TAG_TYPE:
         case XML_TAG_DOMAIN_NAME:
@@ -482,6 +533,7 @@ static void XMLCALL xml_cdata(void *data, const XML_Char *s, int len) {
 
         case XML_TAG_PORT:
         case XML_TAG_TXT_RECORD:
+        case XML_TAG_SUBTYPE:
             assert(u->service);
             u->buf = append_cdata(u->buf, s, len);
             break;
index 1712ea0659a77e7f5486418a6c11dbcea6bc97a3..c6d81aa5b9fb914cfc549e446040e60829afc0d0 100644 (file)
--- a/docs/TODO
+++ b/docs/TODO
@@ -1,7 +1,6 @@
 for 0.6:
 * remove outgoing queries from queue if the browse object they were issued from is destroyed
 * add API to allow user to tell the server that some service is not reachable
-* add support for subtypes in static services
 * Add static host configuration like static services [lathiat]
 * wrap avahi_server_add_record() via DBUS and in avahi-client [lathiat]
 
@@ -97,3 +96,4 @@ done:
 * generate local CNAME responses
 * remove irrelevant functions from pubic rr.h API
 * unify argument order of functions returning a string in a user supplied buffer 
+* add support for subtypes in static services
index 7580d63cd409f4278f349c617514a9f28b095a69..168682dcc7a33ee607265a3a8e3cd2faf3509425 100644 (file)
         type. Should contain one <opt>&lt;type&gt;</opt> and one
         <opt>&lt;port&gt;</opt> element. Optionally it may contain one
         <opt>&lt;domain-name&gt;</opt>, one
-        <opt>&lt;host-name&gt;</opt> and multiple
+        <opt>&lt;host-name&gt;</opt>, any number of
+        <opt>&lt;subtype&gt;</opt> and any number of
         <opt>&lt;txt-record&gt;</opt> elements. The attribute
-        <opt>protocol</opt> specifies the protocol to
-        advertise the service on. If <opt>any</opt> is used (which is
-        the default), the service will be advertised on both IPv4 and
-        IPv6.</p>
+        <opt>protocol</opt> specifies the protocol to advertise the
+        service on. If <opt>any</opt> is used (which is the default),
+        the service will be advertised on both IPv4 and IPv6.</p>
       </option>
 
       <option>
         <p><opt>&lt;type&gt;</opt> Contains the DNS-SD service type for this service. e.g. "_http._tcp".</p>
       </option>
 
+      <option>
+        <p><opt>&lt;subtype&gt;</opt> Contains an additional DNS-SD service subtype for this service. e.g. "_anon._sub._ftp._tcp".</p>
+      </option>
+
       <option>
         <p><opt>&lt;domain-name&gt;</opt> The domain name this service
         should be registered. If omited defaults to the default domain