diff options
| author | Lennart Poettering <lennart@poettering.net> | 2005-10-26 02:03:11 +0000 | 
|---|---|---|
| committer | Lennart Poettering <lennart@poettering.net> | 2005-10-26 02:03:11 +0000 | 
| commit | 58dbdd3113ff75b7262ac2e7a8474550a2dacfd3 (patch) | |
| tree | 417edea9a9ed886ceb77b78bda618387c3ff83a2 | |
| parent | 182da3ab7be8f813a09f1807c1c76747eff02af6 (diff) | |
* add support for subtypes for static services
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@875 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
| -rw-r--r-- | avahi-daemon/avahi-service.dtd | 4 | ||||
| -rw-r--r-- | avahi-daemon/example.service | 1 | ||||
| -rw-r--r-- | avahi-daemon/static-services.c | 80 | ||||
| -rw-r--r-- | docs/TODO | 2 | ||||
| -rw-r--r-- | man/avahi.service.5.xml.in | 14 | 
5 files changed, 80 insertions, 21 deletions
diff --git a/avahi-daemon/avahi-service.dtd b/avahi-daemon/avahi-service.dtd index 8ac1ca6..c3c25e2 100644 --- a/avahi-daemon/avahi-service.dtd +++ b/avahi-daemon/avahi-service.dtd @@ -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)> diff --git a/avahi-daemon/example.service b/avahi-daemon/example.service index 0e565b9..27d8a19 100644 --- a/avahi-daemon/example.service +++ b/avahi-daemon/example.service @@ -13,6 +13,7 @@    <service>      <type>_ipp._tcp</type> +    <subtype>_foo._sub._ipp._tcp</subtype>      <port>631</port>    </service> diff --git a/avahi-daemon/static-services.c b/avahi-daemon/static-services.c index 09777cc..5eba8b2 100644 --- a/avahi-daemon/static-services.c +++ b/avahi-daemon/static-services.c @@ -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; @@ -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 diff --git a/man/avahi.service.5.xml.in b/man/avahi.service.5.xml.in index 7580d63..168682d 100644 --- a/man/avahi.service.5.xml.in +++ b/man/avahi.service.5.xml.in @@ -59,12 +59,12 @@          type. Should contain one <opt><type></opt> and one          <opt><port></opt> element. Optionally it may contain one          <opt><domain-name></opt>, one -        <opt><host-name></opt> and multiple +        <opt><host-name></opt>, any number of +        <opt><subtype></opt> and any number of          <opt><txt-record></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> @@ -72,6 +72,10 @@        </option>        <option> +        <p><opt><subtype></opt> Contains an additional DNS-SD service subtype for this service. e.g. "_anon._sub._ftp._tcp".</p> +      </option> + +      <option>          <p><opt><domain-name></opt> The domain name this service          should be registered. If omited defaults to the default domain          of the avahi daemon. (probably .local)</p>  | 
