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

char* zbar_symbol_xml ( const zbar_symbol_t symbol,
char **  buffer,
unsigned *  buflen 
)

print XML symbol element representation to user result buffer.

See also:
http://zbar.sourceforge.net/2008/barcode.xsd for the schema.
Parameters:
symbol is the symbol to print
buffer is the inout result pointer, it will be reallocated with a larger size if necessary.
buflen is inout length of the result buffer.
Returns:
the buffer pointer
Since:
0.6

Definition at line 155 of file symbol.c.

References zbar_get_symbol_name(), and zbar_symbol_xml().

Referenced by zbar::Symbol::xml(), and zbar_symbol_xml().

{
    const char *type = zbar_get_symbol_name(sym->type);
    /* FIXME binary data */
    unsigned datalen = strlen(sym->data);
    unsigned maxlen = (strlen(xmlfmt[0]) + strlen(xmlfmt[1]) +
                       strlen(xmlfmt[2]) + strlen(xmlfmt[3]) +
                       strlen(type) + datalen + MAX_INT_DIGITS + 1);
    if(!*buf || (*len < maxlen)) {
        if(*buf)
            free(*buf);
        *buf = malloc(maxlen);
        /* FIXME check OOM */
        *len = maxlen;
    }

    int n = snprintf(*buf, maxlen, xmlfmt[0], type, sym->quality);
    assert(n > 0);
    assert(n <= maxlen);

    if(sym->cache_count) {
        int i = snprintf(*buf + n, maxlen - n, xmlfmt[1], sym->cache_count);
        assert(i > 0);
        n += i;
        assert(n <= maxlen);
    }

    int i = strlen(xmlfmt[2]);
    memcpy(*buf + n, xmlfmt[2], i + 1);
    n += i;
    assert(n <= maxlen);

    /* FIXME binary data */
    /* FIXME handle "]]>" */
    strncpy(*buf + n, sym->data, datalen + 1);
    n += datalen;
    assert(n <= maxlen);

    i = strlen(xmlfmt[3]);
    memcpy(*buf + n, xmlfmt[3], i + 1);
    n += i;
    assert(n <= maxlen);

    *len = n;
    return(*buf);
}


Generated by  Doxygen 1.6.0   Back to index