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

char* avahi_escape_label ( const char *  src,
size_t  src_length,
char **  ret_name,
size_t *  ret_size 
)

Escape the domain name in *src and write it to *ret_name

Definition at line 116 of file domain.c.

                                                                                                {
    char *r;

    assert(src);
    assert(ret_name);
    assert(*ret_name);
    assert(ret_size);
    assert(*ret_size > 0);

    r = *ret_name;

    while (src_length > 0) {
        if (*src == '.' || *src == '\\') {

            /* Dot or backslash */

            if (*ret_size < 3)
                return NULL;

            *((*ret_name) ++) = '\\';
            *((*ret_name) ++) = *src;
            (*ret_size) -= 2;

        } else if (
            *src == '_' ||
            *src == '-' ||
            (*src >= '0' && *src <= '9') ||
            (*src >= 'a' && *src <= 'z') ||
            (*src >= 'A' && *src <= 'Z')) {

            /* Proper character */

            if (*ret_size < 2)
                return NULL;

            *((*ret_name)++) = *src;
            (*ret_size) --;

        } else {

            /* Everything else */

            if (*ret_size < 5)
                return NULL;

            *((*ret_name) ++) = '\\';
            *((*ret_name) ++) = '0' + (char)  ((uint8_t) *src / 100);
            *((*ret_name) ++) = '0' + (char) (((uint8_t) *src / 10) % 10);
            *((*ret_name) ++) = '0' + (char)  ((uint8_t) *src % 10);

            (*ret_size) -= 4;
        }

        src_length --;
        src++;
    }

    **ret_name = 0;

    return r;
}

Generated by  Doxygen 1.6.0   Back to index