Gammu internals
1.38.0
|
#include <gammu-config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <locale.h>
#include <limits.h>
#include "../../debug.h"
#include "coding.h"
Go to the source code of this file.
Macros | |
#define | ByteMask ((1 << Bits) - 1) |
#define | tolowerwchar(x) (towlower((wchar_t)( (((&(x))[0] & 0xff) << 8) | (((&(x))[1] & 0xff)) ))) |
Functions | |
unsigned char * | EncodeUnicodeSpecialChars (unsigned char *dest, const unsigned char *buffer) |
char * | EncodeSpecialChars (char *dest, const char *buffer) |
unsigned char * | DecodeUnicodeSpecialChars (unsigned char *dest, const unsigned char *buffer) |
char * | DecodeSpecialChars (char *dest, const char *buffer) |
size_t | UnicodeLength (const unsigned char *str) |
int | EncodeWithUnicodeAlphabet (const unsigned char *src, wchar_t *dest) |
int | DecodeWithUnicodeAlphabet (wchar_t src, unsigned char *dest) |
void | DecodeUnicode (const unsigned char *src, char *dest) |
char * | DecodeUnicodeString (const unsigned char *src) |
char * | DecodeUnicodeConsole (const unsigned char *src) |
void | DecodeISO88591 (unsigned char *dest, const char *src, size_t len) |
void | EncodeUnicode (unsigned char *dest, const char *src, size_t len) |
unsigned char | EncodeWithBCDAlphabet (int value) |
int | DecodeWithBCDAlphabet (unsigned char value) |
void | DecodeBCD (unsigned char *dest, const unsigned char *src, size_t len) |
void | EncodeBCD (unsigned char *dest, const unsigned char *src, size_t len, gboolean fill) |
int | DecodeWithHexBinAlphabet (unsigned char mychar) |
char | EncodeWithHexBinAlphabet (int digit) |
gboolean | DecodeHexUnicode (unsigned char *dest, const char *src, size_t len) |
void | EncodeHexUnicode (char *dest, const unsigned char *src, size_t len) |
gboolean | DecodeHexBin (unsigned char *dest, const unsigned char *src, size_t len) |
void | EncodeHexBin (char *dest, const unsigned char *src, size_t len) |
void | DecodeDefault (unsigned char *dest, const unsigned char *src, size_t len, gboolean UseExtensions, unsigned char *ExtraAlphabet) |
void | EncodeDefault (unsigned char *dest, const unsigned char *src, size_t *len, gboolean UseExtensions, unsigned char *ExtraAlphabet) |
void | FindDefaultAlphabetLen (const unsigned char *src, size_t *srclen, size_t *smslen, size_t maxlen) |
int | GSM_UnpackEightBitsToSeven (size_t offset, size_t in_length, size_t out_length, const unsigned char *input, unsigned char *output) |
int | GSM_PackSevenBitsToEight (size_t offset, const unsigned char *input, unsigned char *output, size_t length) |
GSM_Error | GSM_UnpackSemiOctetNumber (GSM_Debug_Info *di, unsigned char *retval, const unsigned char *Number, size_t *pos, size_t bufferlength, gboolean semioctet) |
int | GSM_PackSemiOctetNumber (const unsigned char *Number, unsigned char *Output, gboolean semioctet) |
void | CopyUnicodeString (unsigned char *Dest, const unsigned char *Source) |
void | ReverseUnicodeString (unsigned char *String) |
void | ReadUnicodeFile (unsigned char *Dest, const unsigned char *Source) |
int | GetBit (unsigned char *Buffer, size_t BitNum) |
int | SetBit (unsigned char *Buffer, size_t BitNum) |
int | ClearBit (unsigned char *Buffer, size_t BitNum) |
void | BufferAlign (unsigned char *Destination, size_t *CurrentBit) |
void | BufferAlignNumber (size_t *CurrentBit) |
void | AddBuffer (unsigned char *Destination, size_t *CurrentBit, unsigned char *Source, size_t BitsToProcess) |
void | AddBufferByte (unsigned char *Destination, size_t *CurrentBit, unsigned char Source, size_t BitsToProcess) |
void | GetBuffer (unsigned char *Source, size_t *CurrentBit, unsigned char *Destination, size_t BitsToProcess) |
void | GetBufferInt (unsigned char *Source, size_t *CurrentBit, int *integer, size_t BitsToProcess) |
void | GetBufferI (unsigned char *Source, size_t *CurrentBit, int *result, size_t BitsToProcess) |
void | EncodeUnicodeSpecialNOKIAChars (unsigned char *dest, const unsigned char *src, size_t len) |
void | DecodeUnicodeSpecialNOKIAChars (unsigned char *dest, const unsigned char *src, size_t len) |
gboolean | mywstrncasecmp (unsigned const char *a, unsigned const char *b, int num) |
gboolean | mywstrncmp (unsigned const char *a, unsigned const char *b, int num) |
gboolean | myiswspace (unsigned const char *src) |
unsigned char * | mywstrstr (const unsigned char *haystack, const unsigned char *needle) |
GSM_Error | MyGetLine (char *Buffer, size_t *Pos, char *OutBuffer, size_t MaxLen, size_t MaxOutLen, gboolean MergeLines) |
GSM_Error | GSM_GetVCSLine (char **OutBuffer, char *Buffer, size_t *Pos, size_t MaxLen, gboolean MergeLines) |
void | StringToDouble (char *text, double *d) |
int | EncodeWithUTF8Alphabet (unsigned long src, unsigned char *ret) |
gboolean | EncodeUTF8QuotedPrintable (char *dest, const unsigned char *src) |
gboolean | EncodeUTF8 (char *dest, const unsigned char *src) |
int | DecodeWithUTF8Alphabet (const unsigned char *src, wchar_t *dest, size_t len) |
void | DecodeISO88591QuotedPrintable (unsigned char *dest, const unsigned char *src, size_t len) |
void | DecodeUTF8QuotedPrintable (unsigned char *dest, const char *src, size_t len) |
void | DecodeUTF8 (unsigned char *dest, const char *src, size_t len) |
void | DecodeXMLUTF8 (unsigned char *dest, const char *src, size_t len) |
void | DecodeUTF7 (unsigned char *dest, const unsigned char *src, size_t len) |
static void | EncodeBASE64Block (const unsigned char in[3], char out[4], const size_t len) |
void | EncodeBASE64 (const unsigned char *Input, char *Output, const size_t Length) |
static void | DecodeBASE64Block (const char in[4], unsigned char out[3]) |
int | DecodeBASE64 (const char *Input, unsigned char *Output, const size_t Length) |
Variables | |
static unsigned char | GSM_DefaultAlphabetUnicode [128+1][2] |
static unsigned char | GSM_DefaultAlphabetCharsExtension [][3] |
static unsigned char | ConvertTable [] |
#define ByteMask ((1 << Bits) - 1) |
Definition at line 951 of file coding.c.
Referenced by GSM_UnpackEightBitsToSeven().
#define tolowerwchar | ( | x | ) | (towlower((wchar_t)( (((&(x))[0] & 0xff) << 8) | (((&(x))[1] & 0xff)) ))) |
Referenced by mywstrstr().
void AddBuffer | ( | unsigned char * | Destination, |
size_t * | CurrentBit, | ||
unsigned char * | Source, | ||
size_t | BitsToProcess | ||
) |
Definition at line 1286 of file coding.c.
References ClearBit(), GetBit(), and SetBit().
Referenced by AddBufferByte(), and GSM_EncodeNokiaRTTLRingtone().
void AddBufferByte | ( | unsigned char * | Destination, |
size_t * | CurrentBit, | ||
unsigned char | Source, | ||
size_t | BitsToProcess | ||
) |
Definition at line 1303 of file coding.c.
References AddBuffer().
Referenced by GSM_EncodeNokiaRTTLRingtone().
void BufferAlign | ( | unsigned char * | Destination, |
size_t * | CurrentBit | ||
) |
Definition at line 1263 of file coding.c.
References ClearBit().
Referenced by GSM_EncodeNokiaRTTLRingtone().
void BufferAlignNumber | ( | size_t * | CurrentBit | ) |
Definition at line 1275 of file coding.c.
Referenced by GSM_DecodeNokiaRTTLRingtone(), and GSM_EncodeNokiaRTTLRingtone().
int ClearBit | ( | unsigned char * | Buffer, |
size_t | BitNum | ||
) |
Definition at line 1258 of file coding.c.
Referenced by AddBuffer(), BufferAlign(), GetBuffer(), and GSM_ClearPointBitmap().
int DecodeBASE64 | ( | const char * | Input, |
unsigned char * | Output, | ||
const size_t | Length | ||
) |
Definition at line 2149 of file coding.c.
References DecodeBASE64Block(), and FALSE.
Referenced by DecodeUTF7(), and GSM_DecodeVCARD().
|
static |
Definition at line 2142 of file coding.c.
Referenced by DecodeBASE64().
void DecodeBCD | ( | unsigned char * | dest, |
const unsigned char * | src, | ||
size_t | len | ||
) |
Definition at line 328 of file coding.c.
Referenced by GSM_UnpackSemiOctetNumber(), and NOKIA_DecodeNetworkCode().
void DecodeDefault | ( | unsigned char * | dest, |
const unsigned char * | src, | ||
size_t | len, | ||
gboolean | UseExtensions, | ||
unsigned char * | ExtraAlphabet | ||
) |
Definition at line 498 of file coding.c.
References DumpMessageText(), GSM_DefaultAlphabetCharsExtension, GSM_DefaultAlphabetUnicode, GSM_global_debug, and UnicodeLength().
Referenced by GSM_DecodePDUFrame(), GSM_DecodeSMSFrameText(), and GSM_EncodeMultiPartSMS().
void DecodeISO88591 | ( | unsigned char * | dest, |
const char * | src, | ||
size_t | len | ||
) |
void DecodeISO88591QuotedPrintable | ( | unsigned char * | dest, |
const unsigned char * | src, | ||
size_t | len | ||
) |
Definition at line 1889 of file coding.c.
References DecodeWithHexBinAlphabet().
Referenced by ReadVCALText().
char* DecodeSpecialChars | ( | char * | dest, |
const char * | buffer | ||
) |
unsigned char* DecodeUnicodeSpecialChars | ( | unsigned char * | dest, |
const unsigned char * | buffer | ||
) |
void DecodeUnicodeSpecialNOKIAChars | ( | unsigned char * | dest, |
const unsigned char * | src, | ||
size_t | len | ||
) |
Definition at line 1401 of file coding.c.
Referenced by GSM_DecodeNokiaRTTLRingtone(), GSM_DecodePDUFrame(), and GSM_DecodeSMSFrameText().
void DecodeUTF7 | ( | unsigned char * | dest, |
const unsigned char * | src, | ||
size_t | len | ||
) |
Definition at line 2051 of file coding.c.
References DecodeBASE64(), and EncodeWithUnicodeAlphabet().
Referenced by ReadVCALText().
int DecodeWithBCDAlphabet | ( | unsigned char | value | ) |
Definition at line 323 of file coding.c.
Referenced by GSM_DecodeSMSDateTime().
int DecodeWithHexBinAlphabet | ( | unsigned char | mychar | ) |
Definition at line 361 of file coding.c.
Referenced by DecodeHexBin(), DecodeHexUnicode(), DecodeISO88591QuotedPrintable(), and DecodeUTF8QuotedPrintable().
int DecodeWithUnicodeAlphabet | ( | wchar_t | value, |
unsigned char * | dest | ||
) |
Converts single character from wchar_t to unicode.
Definition at line 210 of file coding.c.
Referenced by DecodeUnicode(), and myiswspace().
void DecodeXMLUTF8 | ( | unsigned char * | dest, |
const char * | src, | ||
size_t | len | ||
) |
Decodes UTF-8 text with XML entities to Unicode.
Definition at line 1966 of file coding.c.
References dbgprintf, DecodeUTF8(), and EncodeWithUTF8Alphabet().
void EncodeBASE64 | ( | const unsigned char * | Input, |
char * | Output, | ||
const size_t | Length | ||
) |
Definition at line 2118 of file coding.c.
References EncodeBASE64Block().
Referenced by VC_StoreBase64().
|
static |
Definition at line 2107 of file coding.c.
Referenced by EncodeBASE64().
void EncodeBCD | ( | unsigned char * | dest, |
const unsigned char * | src, | ||
size_t | len, | ||
gboolean | fill | ||
) |
Definition at line 342 of file coding.c.
Referenced by GSM_PackSemiOctetNumber(), and NOKIA_EncodeNetworkCode().
void EncodeDefault | ( | unsigned char * | dest, |
const unsigned char * | src, | ||
size_t * | len, | ||
gboolean | UseExtensions, | ||
unsigned char * | ExtraAlphabet | ||
) |
Definition at line 831 of file coding.c.
References ConvertTable, DumpMessageText(), FALSE, GSM_DefaultAlphabetCharsExtension, GSM_DefaultAlphabetUnicode, GSM_global_debug, and TRUE.
Referenced by GSM_EncodeAlcatelMultiPartSMS(), GSM_EncodeMultiPartSMS(), and GSM_EncodeSMSFrameText().
void EncodeHexBin | ( | char * | dest, |
const unsigned char * | src, | ||
size_t | len | ||
) |
Encodes text to hexadecimal binary representation.
Definition at line 426 of file coding.c.
References EncodeWithHexBinAlphabet().
Referenced by EncodeHexUnicode().
char* EncodeSpecialChars | ( | char * | dest, |
const char * | buffer | ||
) |
unsigned char* EncodeUnicodeSpecialChars | ( | unsigned char * | dest, |
const unsigned char * | buffer | ||
) |
void EncodeUnicodeSpecialNOKIAChars | ( | unsigned char * | dest, |
const unsigned char * | src, | ||
size_t | len | ||
) |
Definition at line 1367 of file coding.c.
Referenced by GSM_EncodeNokiaRTTLRingtone(), and GSM_EncodeSMSFrameText().
unsigned char EncodeWithBCDAlphabet | ( | int | value | ) |
Definition at line 315 of file coding.c.
Referenced by GSM_EncodeSMSDateTime().
char EncodeWithHexBinAlphabet | ( | int | digit | ) |
Definition at line 375 of file coding.c.
Referenced by EncodeHexBin().
int EncodeWithUnicodeAlphabet | ( | const unsigned char * | value, |
wchar_t * | dest | ||
) |
Converts single character from unicode to wchar_t.
Definition at line 198 of file coding.c.
Referenced by DecodeUTF7(), DecodeUTF8(), DecodeUTF8QuotedPrintable(), and EncodeUnicode().
void FindDefaultAlphabetLen | ( | const unsigned char * | src, |
size_t * | srclen, | ||
size_t * | smslen, | ||
size_t | maxlen | ||
) |
Definition at line 914 of file coding.c.
References FALSE, GSM_DefaultAlphabetCharsExtension, and TRUE.
Referenced by GSM_AddSMS_Text_UDH(), GSM_EncodeMultiPartSMS(), and GSM_Find_Free_Used_SMS2().
int GetBit | ( | unsigned char * | Buffer, |
size_t | BitNum | ||
) |
Definition at line 1248 of file coding.c.
Referenced by AddBuffer(), GetBuffer(), GetBufferI(), GetBufferInt(), and GSM_IsPointBitmap().
void GetBuffer | ( | unsigned char * | Source, |
size_t * | CurrentBit, | ||
unsigned char * | Destination, | ||
size_t | BitsToProcess | ||
) |
Definition at line 1311 of file coding.c.
References ClearBit(), GetBit(), and SetBit().
Referenced by GSM_DecodeNokiaRTTLRingtone().
void GetBufferI | ( | unsigned char * | Source, |
size_t * | CurrentBit, | ||
int * | result, | ||
size_t | BitsToProcess | ||
) |
void GetBufferInt | ( | unsigned char * | Source, |
size_t * | CurrentBit, | ||
int * | integer, | ||
size_t | BitsToProcess | ||
) |
Definition at line 1329 of file coding.c.
References GetBit().
Referenced by GSM_DecodeNokiaRTTLRingtone().
GSM_Error GSM_GetVCSLine | ( | char ** | OutBuffer, |
char * | Buffer, | ||
size_t * | Pos, | ||
size_t | MaxLen, | ||
gboolean | MergeLines | ||
) |
Gets VCS line from buffer.
MergeLines | Determine whether merge lines as vCard style continuation or quoted printable continutaion. |
Buffer | Data source to parse. |
Pos | Current position in data. |
OutBuffer | Pointer to buffer pointer, which will be allocated. |
MaxLen | Maximal length of data to process. |
Definition at line 1656 of file coding.c.
References ERR_MOREMEMORY, ERR_NONE, FALSE, and TRUE.
Referenced by GSM_DecodeVCARD().
int GSM_PackSemiOctetNumber | ( | const unsigned char * | Number, |
unsigned char * | Output, | ||
gboolean | semioctet | ||
) |
Packing some phone numbers (SMSC, SMS destination and others)
See GSM 03.40 9.1.1: 1 byte - length of number given in semioctets or bytes (when given in bytes, includes one byte for byte with number format). Returned by function (set semioctet to TRUE, if want result in semioctets). 1 byte - format of number (see GSM_NumberType in coding.h). Returned in unsigned char *Output. n bytes - 2n or 2n-1 semioctets with number. Returned in unsigned char *Output.
1 semioctet = 4 bits = half of byte
First byte is used for saving type of number. See GSM 03.40 section 9.1.2.5
Definition at line 1125 of file coding.c.
References DecodeUnicode(), EncodeBCD(), GSM_PackSevenBitsToEight(), NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN, NUMBER_INTERNATIONAL_NUMBERING_PLAN_ISDN, NUMBER_UNKNOWN_NUMBERING_PLAN_ISDN, TRUE, and UnicodeLength().
Referenced by GSM_EncodeSMSFrame(), and NOKIA_EncodeDateTime().
int GSM_PackSevenBitsToEight | ( | size_t | offset, |
const unsigned char * | input, | ||
unsigned char * | output, | ||
size_t | length | ||
) |
Definition at line 993 of file coding.c.
Referenced by GSM_EncodeAlcatelMultiPartSMS(), GSM_EncodeMultiPartSMS(), GSM_EncodeSMSFrameText(), and GSM_PackSemiOctetNumber().
int GSM_UnpackEightBitsToSeven | ( | size_t | offset, |
size_t | in_length, | ||
size_t | out_length, | ||
const unsigned char * | input, | ||
unsigned char * | output | ||
) |
Definition at line 953 of file coding.c.
References ByteMask.
Referenced by GSM_DecodePDUFrame(), GSM_DecodeSMSFrameText(), and GSM_UnpackSemiOctetNumber().
GSM_Error GSM_UnpackSemiOctetNumber | ( | GSM_Debug_Info * | di, |
unsigned char * | retval, | ||
const unsigned char * | Number, | ||
size_t * | pos, | ||
size_t | bufferlength, | ||
gboolean | semioctet | ||
) |
Definition at line 1028 of file coding.c.
References DecodeBCD(), EncodeUnicode(), ERR_NONE, ERR_UNKNOWN, GSM_MAX_NUMBER_LENGTH, GSM_UnpackEightBitsToSeven(), NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN, NUMBER_INTERNATIONAL_NUMBERING_PLAN_ISDN, and smfprintf().
Referenced by GSM_DecodePDUFrame(), GSM_DecodeSMSFrame(), and NOKIA_EncodeDateTime().
GSM_Error MyGetLine | ( | char * | Buffer, |
size_t * | Pos, | ||
char * | OutBuffer, | ||
size_t | MaxLen, | ||
size_t | MaxOutLen, | ||
gboolean | MergeLines | ||
) |
Gets line from buffer.
MergeLines | Determine whether merge lines as vCard style continuation or quoted printable continutaion. |
Buffer | Data source to parse. |
Pos | Current position in data. |
OutBuffer | Buffer where line will be written. |
MaxLen | Maximal length of data to process. |
MaxOutLen | Size of output buffer. |
Definition at line 1580 of file coding.c.
References ERR_MOREMEMORY, ERR_NONE, FALSE, and TRUE.
Referenced by GSM_DecodeVCALENDAR_VTODO(), GSM_DecodeVNOTE(), and GSM_JADFindLine().
gboolean myiswspace | ( | unsigned const char * | src | ) |
Definition at line 1470 of file coding.c.
References DecodeWithUnicodeAlphabet(), FALSE, and TRUE.
Referenced by INI_ReadFile().
void ReverseUnicodeString | ( | unsigned char * | String | ) |
int SetBit | ( | unsigned char * | Buffer, |
size_t | BitNum | ||
) |
Definition at line 1253 of file coding.c.
Referenced by AddBuffer(), GetBuffer(), and GSM_SetPointBitmap().
void StringToDouble | ( | char * | text, |
double * | d | ||
) |
|
static |
Definition at line 551 of file coding.c.
Referenced by EncodeDefault().
|
static |
Definition at line 483 of file coding.c.
Referenced by DecodeDefault(), EncodeDefault(), and FindDefaultAlphabetLen().
|
static |
Definition at line 438 of file coding.c.
Referenced by DecodeDefault(), and EncodeDefault().