Пример #1
0
// Decode a text string according to ETSI EN 300 468 Annex A
QString dvb_decode_text(const unsigned char *src, uint raw_length,
                        const unsigned char *encoding_override,
                        uint encoding_override_length)
{
    if (!raw_length)
        return "";

    if (src[0] == 0x1f)
        return freesat_huffman_to_string(src, raw_length);

    /* UCS-2 aka ISO/IEC 10646-1 Basic Multilingual Plane */
    if (src[0] == 0x11)
    {
        size_t length = (raw_length - 1) / 2;
        QChar *to = new QChar[length];
        for (size_t i=0; i<length; i++)
            to[i] = (src[1 + i*2] << 8) + src[1 + i*2 + 1];
        QString to2(to, length);
        delete [] to;
        return to2;
    }

    if (((0x11 < src[0]) && (src[0] < 0x15)) ||
        ((0x15 < src[0]) && (src[0] < 0x1f)))
    {
        // TODO: Handle multi-byte encodings
        LOG(VB_SIPARSER, LOG_ERR,
            "dvb_decode_text: Multi-byte coded text is not yet supported.");
        return "";
    }

    // if a override encoding is specified and the default ISO 6937 encoding
    // would be used copy the override encoding in front of the text
    unsigned char *dst =
        new unsigned char[raw_length + encoding_override_length];

    uint length = 0;
    if (encoding_override && src[0] >= 0x20) {
        memcpy(dst, encoding_override, encoding_override_length);
        length = encoding_override_length;
    }

    // Strip formatting characters
    for (uint i = 0; i < raw_length; i++)
    {
        if ((src[i] < 0x80) || (src[i] > 0x9F))
            dst[length++] = src[i];
        // replace CR/LF with a space
        else if (src[i] == 0x8A)
            dst[length++] = 0x20;
    }

    // Exit on empty string, sans formatting.

    QString sStr = (!length) ? "" : decode_text(dst, length);

    delete [] dst;

    return sStr;
}
Пример #2
0
// Decode a text string according to ETSI EN 300 468 Annex A
QString dvb_decode_text(const unsigned char *src, uint raw_length,
                        const unsigned char *encoding_override,
                        uint encoding_override_length)
{
    if (!raw_length)
        return "";

    if (src[0] == 0x1f)
        return freesat_huffman_to_string(src, raw_length);

    if ((0x10 < src[0]) && (src[0] < 0x20))
    {
        // TODO: Handle multi-byte encodings
        VERBOSE(VB_SIPARSER, "dvb_decode_text: "
                "Multi-byte coded text is not yet supported.");
        return "";
    }

    // if a override encoding is specified and the default ISO 6937 encoding
    // would be used copy the override encoding in front of the text
    unsigned char *dst = new unsigned char[ raw_length + encoding_override_length ];

    uint length = 0;
    if (encoding_override && src[0] >= 0x20) {
        memcpy(dst, encoding_override, encoding_override_length);
        length = encoding_override_length;
    }

    // Strip formatting characters
    for (uint i = 0; i < raw_length; i++)
    {
        if ((src[i] < 0x80) || (src[i] > 0x9F))
            dst[length++] = src[i];
        // replace CR/LF with a space
        else if (src[i] == 0x8A)
            dst[length++] = 0x20;
    }

    // Exit on empty string, sans formatting.

    QString sStr = (!length) ? "" : decode_text(dst, length);

    delete [] dst;

    return sStr;
}
Пример #3
0
/*
 * Convert the DVB text in the string passed in.
 * If the buffer is Freesat huffman encoded, then decode that.
 * Text is converted to UTF-8 and XML entities are encoded.
 */
const char *convert_text(const char *s) {
	char cs_new[16];
	size_t ret;

	int i = (int) (unsigned char) s[0];
	if (i < 0x1F) {
		if (encoding[i].handler(cs_new, &s, encoding[i].data))
			return "";
	} else {
		if (encoding_default(cs_new, &s, NULL))
			return "";
	}
	if (i == 0x1F) {
		s = (char *) freesat_huffman_to_string((unsigned char *) s, strlen(s));
	}
	if (strncmp(cs_old, cs_new, 16)) {
		if (cd) {
			iconv_close(cd);
			cd = NULL;
		} // if
		cd = iconv_open("UTF-8", cs_new);
		if (cd == (iconv_t) - 1) {
			log_message(ERROR, "iconv_open() failed: %s", strerror(errno));
			exit(1);
		} // if
		strncpy(cs_old, cs_new, 16);
	} // if

	char *inbuf = (char *) s;
	size_t inbytesleft = strlen(s);
	char *outbuf = (char *) buf;
	size_t outbytesleft = sizeof(buf);
	ret = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
	*outbuf = 0;
	// FIXME: handle errors
	return xmlify(buf);
}