Logo Search packages:      
Sourcecode: avahi version File versions  Download package

int avahi_service_name_join ( char *  p,
size_t  size,
const char *  name,
const char *  type,
const char *  domain 
)

Construct a valid complete DNS-SD service name from a name, a type and a domain

Definition at line 440 of file domain.c.

References AVAHI_DOMAIN_NAME_MAX, AVAHI_ERR_INVALID_DOMAIN_NAME, AVAHI_ERR_INVALID_SERVICE_NAME, AVAHI_ERR_INVALID_SERVICE_TYPE, AVAHI_LABEL_MAX, and AVAHI_OK.

                                                                                                          {
    char escaped_name[AVAHI_LABEL_MAX*4];
    char normalized_type[AVAHI_DOMAIN_NAME_MAX];
    char normalized_domain[AVAHI_DOMAIN_NAME_MAX];

    assert(p);

    /* Validity checks */

    if ((name && !avahi_is_valid_service_name(name)))
        return AVAHI_ERR_INVALID_SERVICE_NAME;

    if (!avahi_is_valid_service_type_generic(type))
        return AVAHI_ERR_INVALID_SERVICE_TYPE;

    if (!avahi_is_valid_domain_name(domain))
        return AVAHI_ERR_INVALID_DOMAIN_NAME;

    /* Preparation */

    if (name) {
        size_t l = sizeof(escaped_name);
        char *e = escaped_name, *r;
        r = avahi_escape_label(name, strlen(name), &e, &l);
        assert(r);
    }

    if (!(avahi_normalize_name(type, normalized_type, sizeof(normalized_type))))
        return AVAHI_ERR_INVALID_SERVICE_TYPE;

    if (!(avahi_normalize_name(domain, normalized_domain, sizeof(normalized_domain))))
        return AVAHI_ERR_INVALID_DOMAIN_NAME;

    /* Concatenation */

    snprintf(p, size, "%s%s%s.%s", name ? escaped_name : "", name ? "." : "", normalized_type, normalized_domain);

    return AVAHI_OK;
}


Generated by  Doxygen 1.6.0   Back to index