unsigned char *tcore_util_unpack_gsm7bit(const unsigned char *src, unsigned int src_len)
{
unsigned char *dest;
- int i = 0, j = 0;
- unsigned int pos = 0;
- unsigned char shift = 0;
- int outlen = 0;
-
- if (!src || src_len == 0)
- return NULL;
-
- outlen = (src_len * 8) / 7;
-
- dest = calloc(1, outlen + 1);
- if (!dest)
- return NULL;
-
- for (i = 0; pos < src_len; i++, pos++) {
- dest[i] = (src[pos] << shift) & 0x7F;
-
- if (pos != 0) {
- /*
- * except the first byte, a character contains some bits
- * from the previous byte.
- */
- dest[i] |= src[pos - 1] >> (8 - shift);
- }
-
- shift++;
-
- if (shift == 7) {
- shift = 0;
-
- /* a possible extra complete character is available */
- i++;
- dest[i] = src[pos] >> 1;
- }
- }
-
- /* If a character is '\r'(13), change it to space(32) */
- for (i = 0, j = 0; i < outlen; i++, j++) {
- if (dest[i] == '\r')
- dest[j] = ' ';
- else if (dest[i] == 0x1B) /* If a charater is 0x1B (escape), next charater is changed on gsm 7bit extension table */
- dest[j] = _convert_gsm7bit_extension(dest[++i]);
- else
- dest[j] = dest[i];
- }
-
- outlen -= (i - j);
+ unsigned int outlen = 0;
- dest[outlen] = '\0';
+ dest = tcore_util_unpack_gsm7bit_ex(src, src_len, &outlen);
+ info("length of unpacked data = %d", outlen);
return dest;
}