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

int avahi_service_name_split ( const char *  p,
char *  name,
size_t  name_size,
char *  type,
size_t  type_size,
char *  domain,
size_t  domain_size 
)

Split a full service name into name, type and domain

Definition at line 496 of file domain.c.

References AVAHI_ERR_NO_MEMORY.

                                                                                                                                          {
    enum {
        NAME,
        TYPE,
        DOMAIN
    } state;
    int type_empty = 1, domain_empty = 1;

    assert(p);
    assert(type);
    assert(type_size > 0);
    assert(domain);
    assert(domain_size > 0);

    if (name) {
        assert(name_size > 0);
        *name = 0;
        state = NAME;
    } else
        state = TYPE;

    *type = *domain = 0;

    while (*p) {
        char buf[64];

        if (!(avahi_unescape_label(&p, buf, sizeof(buf))))
            return -1;

        switch (state) {
            case NAME:
                strlcpy(name, buf, name_size);
                state = TYPE;
                break;

            case TYPE:

                if (buf[0] == '_') {

                    if (!type_empty) {
                        if (!type_size)
                            return AVAHI_ERR_NO_MEMORY;

                        *(type++) = '.';
                        type_size --;

                    } else
                        type_empty = 0;

                    if (!(avahi_escape_label(buf, strlen(buf), &type, &type_size)))
                        return AVAHI_ERR_NO_MEMORY;

                    break;
                }

                state = DOMAIN;
                /* fall through */

            case DOMAIN:

                if (!domain_empty) {
                    if (!domain_size)
                        return AVAHI_ERR_NO_MEMORY;

                    *(domain++) = '.';
                    domain_size --;
                } else
                    domain_empty = 0;

                if (!(avahi_escape_label(buf, strlen(buf), &domain, &domain_size)))
                    return AVAHI_ERR_NO_MEMORY;

                break;
        }
    }

    return 0;
}


Generated by  Doxygen 1.6.0   Back to index