Gammu internals  1.38.0
coding.h
Go to the documentation of this file.
1 /* (c) 2002-2004 by Marcin Wiacek and others */
2 
3 #ifndef __coding_h
4 #define __coding_h
5 
6 #if defined(_MSC_VER) && defined(__cplusplus)
7  extern "C" {
8 #endif
9 
10 #include <stdlib.h>
11 #ifdef HAVE_WCHAR_H
12 # include <wchar.h>
13 #endif
14 #ifdef HAVE_WCTYPE_H
15 # include <wctype.h>
16 #endif
17 
18 #include <gammu-unicode.h>
19 #include <gammu-error.h>
20 #include <gammu-debug.h>
21 
22 #ifndef HAVE_WCHAR_T
23 typedef int wchar_t;
24 #endif
25 
26 #ifndef HAVE_WINT_T
27 typedef int wint_t;
28 #endif
29 
30 /* ---------------------------- Unicode ------------------------------------ */
31 gboolean myiswspace (unsigned const char *src);
32 
33 
34 void ReverseUnicodeString (unsigned char *String);
35 
36 void DecodeUnicodeSpecialNOKIAChars (unsigned char *dest, const unsigned char *src, size_t len);
37 void EncodeUnicodeSpecialNOKIAChars (unsigned char *dest, const unsigned char *src, size_t len);
38 
39 unsigned char *EncodeUnicodeSpecialChars(unsigned char *dest, const unsigned char *buffer);
40 unsigned char *DecodeUnicodeSpecialChars(unsigned char *dest, const unsigned char *buffer);
41 
42 /* ------------------------------- BCD ------------------------------------- */
43 unsigned char EncodeWithBCDAlphabet (int value);
44 int DecodeWithBCDAlphabet (unsigned char value);
45 
46 void DecodeBCD (unsigned char *dest, const unsigned char *src, size_t len);
47 void EncodeBCD (unsigned char *dest, const unsigned char *src, size_t len, gboolean fill);
48 
49 /* ------------------------------ UTF7 ------------------------------------- */
50 void DecodeUTF7 (unsigned char *dest, const unsigned char *src, size_t len);
51 
52 
53 /* ---------------------------- ISO88591 ----------------------------------- */
54 void DecodeISO88591 (unsigned char *dest, const char *src, size_t len);
55 void DecodeISO88591QuotedPrintable (unsigned char *dest, const unsigned char *src, size_t len);
56 
60 void DecodeXMLUTF8(unsigned char *dest, const char *src, size_t len);
61 
62 /* ------------------------------- BASE64 ---------------------------------- */
63 void EncodeBASE64 (const unsigned char *Input, char *Output, const size_t Length);
64 int DecodeBASE64 (const char *Input, unsigned char *Output, const size_t Length);
65 
66 /* ---------------------- DefaultAlphabet for SMS -------------------------- */
67 void EncodeDefault (unsigned char *dest, const unsigned char *src, size_t *len, gboolean UseExtensions, unsigned char *ExtraAlphabet);
68 void DecodeDefault (unsigned char *dest, const unsigned char *src, size_t len, gboolean UseExtensions, unsigned char *ExtraAlphabet);
69 void FindDefaultAlphabetLen (const unsigned char *src, size_t *srclen, size_t *smslen, size_t maxlen);
70 
71 int GSM_PackSevenBitsToEight (size_t offset, const unsigned char *input, unsigned char *output, size_t length);
72 int GSM_UnpackEightBitsToSeven (size_t offset, size_t in_length, size_t out_length,
73  const unsigned char *input, unsigned char *output);
74 
75 /* ----------------- Phone numbers according to GSM specs ------------------ */
76 
81 typedef enum {
94 
95  /* specification give also other values */
97 
98 //int GSM_UnpackSemiOctetNumber(GSM_Debug_Info *di, unsigned char *retval, const unsigned char *Number, gboolean semioctet);
99 GSM_Error GSM_UnpackSemiOctetNumber(GSM_Debug_Info *di, unsigned char *retval, const unsigned char *Number, size_t *pos, size_t bufferlength, gboolean semioctet);
100 int GSM_PackSemiOctetNumber (const unsigned char *Number, unsigned char *Output, gboolean semioctet);
101 
102 /* ---------------------------- Bits --------------------------------------- */
103 
104 void BufferAlign (unsigned char *Destination, size_t *CurrentBit);
105 void BufferAlignNumber(size_t *CurrentBit);
106 
107 void AddBuffer (unsigned char *Destination, size_t *CurrentBit, unsigned char *Source, size_t BitsToProcess);
108 void AddBufferByte(unsigned char *Destination, size_t *CurrentBit, unsigned char Source, size_t BitsToProcess);
109 
110 void GetBuffer (unsigned char *Source, size_t *CurrentBit, unsigned char *Destination, size_t BitsToProcess);
111 void GetBufferInt (unsigned char *Source, size_t *CurrentBit, int *integer, size_t BitsToProcess);
112 void GetBufferI (unsigned char *Source, size_t *CurrentBit, int *result, size_t BitsToProcess);
113 
114 int GetBit (unsigned char *Buffer, size_t BitNum);
115 int SetBit (unsigned char *Buffer, size_t BitNum);
116 int ClearBit (unsigned char *Buffer, size_t BitNum);
117 
118 /* ---------------------------- Other -------------------------------------- */
119 
120 void StringToDouble (char *text, double *d);
121 
134 GSM_Error GSM_GetVCSLine(char **OutBuffer, char *Buffer, size_t *Pos, size_t MaxLen, gboolean MergeLines);
135 
149 GSM_Error MyGetLine(char *Buffer, size_t *Pos, char *OutBuffer, size_t MaxLen, size_t MaxOutLen, gboolean MergeLines);
150 
151 char *EncodeSpecialChars(char *dest, const char *buffer);
152 char *DecodeSpecialChars(char *dest, const char *buffer);
153 
154 #ifdef ICONV_FOUND
155 
156 gboolean IconvDecode(const char *charset, const char *input, const size_t inlen, unsigned char *output, size_t outlen);
157 gboolean IconvEncode(const char *charset, const unsigned char *input, const size_t inlen, char *output, size_t outlen);
158 #endif
159 
160 #if defined(_MSC_VER) && defined(__cplusplus)
161  }
162 #endif
163 
164 #endif
165 
166 /* How should editor hadle tabs in this file? Add editor commands here.
167  * vim: noexpandtab sw=8 ts=8 sts=8:
168  */
unsigned char EncodeWithBCDAlphabet(int value)
Definition: coding.c:315
int ClearBit(unsigned char *Buffer, size_t BitNum)
Definition: coding.c:1258
int SetBit(unsigned char *Buffer, size_t BitNum)
Definition: coding.c:1253
void AddBuffer(unsigned char *Destination, size_t *CurrentBit, unsigned char *Source, size_t BitsToProcess)
Definition: coding.c:1286
void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, size_t len)
Definition: coding.c:1367
void BufferAlignNumber(size_t *CurrentBit)
Definition: coding.c:1275
int DecodeWithBCDAlphabet(unsigned char value)
Definition: coding.c:323
GSM_Error
Definition: gammu-error.h:23
GSM_Error GSM_UnpackSemiOctetNumber(GSM_Debug_Info *di, unsigned char *retval, const unsigned char *Number, size_t *pos, size_t bufferlength, gboolean semioctet)
Definition: coding.c:1028
int wchar_t
Definition: coding.h:23
void AddBufferByte(unsigned char *Destination, size_t *CurrentBit, unsigned char Source, size_t BitsToProcess)
Definition: coding.c:1303
gboolean myiswspace(unsigned const char *src)
Definition: coding.c:1470
void GetBufferInt(unsigned char *Source, size_t *CurrentBit, int *integer, size_t BitsToProcess)
Definition: coding.c:1329
void GetBufferI(unsigned char *Source, size_t *CurrentBit, int *result, size_t BitsToProcess)
Definition: coding.c:1345
GSM_NumberType
Definition: coding.h:81
void DecodeXMLUTF8(unsigned char *dest, const char *src, size_t len)
Definition: coding.c:1966
int gboolean
Definition: gammu-types.h:23
void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, size_t len)
Definition: coding.c:1401
int GSM_UnpackEightBitsToSeven(size_t offset, size_t in_length, size_t out_length, const unsigned char *input, unsigned char *output)
Definition: coding.c:953
void EncodeDefault(unsigned char *dest, const unsigned char *src, size_t *len, gboolean UseExtensions, unsigned char *ExtraAlphabet)
Definition: coding.c:831
GSM_Error MyGetLine(char *Buffer, size_t *Pos, char *OutBuffer, size_t MaxLen, size_t MaxOutLen, gboolean MergeLines)
Definition: coding.c:1580
int GetBit(unsigned char *Buffer, size_t BitNum)
Definition: coding.c:1248
int wint_t
Definition: coding.h:27
void DecodeISO88591(unsigned char *dest, const char *src, size_t len)
Definition: coding.c:282
int DecodeBASE64(const char *Input, unsigned char *Output, const size_t Length)
Definition: coding.c:2149
char * DecodeSpecialChars(char *dest, const char *buffer)
Definition: coding.c:159
void BufferAlign(unsigned char *Destination, size_t *CurrentBit)
Definition: coding.c:1263
unsigned char * EncodeUnicodeSpecialChars(unsigned char *dest, const unsigned char *buffer)
Definition: coding.c:41
void DecodeBCD(unsigned char *dest, const unsigned char *src, size_t len)
Definition: coding.c:328
void EncodeBASE64(const unsigned char *Input, char *Output, const size_t Length)
Definition: coding.c:2118
void StringToDouble(char *text, double *d)
Definition: coding.c:1731
int GSM_PackSevenBitsToEight(size_t offset, const unsigned char *input, unsigned char *output, size_t length)
Definition: coding.c:993
void EncodeBCD(unsigned char *dest, const unsigned char *src, size_t len, gboolean fill)
Definition: coding.c:342
unsigned char * DecodeUnicodeSpecialChars(unsigned char *dest, const unsigned char *buffer)
Definition: coding.c:121
GSM_Error GSM_GetVCSLine(char **OutBuffer, char *Buffer, size_t *Pos, size_t MaxLen, gboolean MergeLines)
Definition: coding.c:1656
void DecodeISO88591QuotedPrintable(unsigned char *dest, const unsigned char *src, size_t len)
Definition: coding.c:1889
void FindDefaultAlphabetLen(const unsigned char *src, size_t *srclen, size_t *smslen, size_t maxlen)
Definition: coding.c:914
void GetBuffer(unsigned char *Source, size_t *CurrentBit, unsigned char *Destination, size_t BitsToProcess)
Definition: coding.c:1311
char * EncodeSpecialChars(char *dest, const char *buffer)
Definition: coding.c:94
void DecodeDefault(unsigned char *dest, const unsigned char *src, size_t len, gboolean UseExtensions, unsigned char *ExtraAlphabet)
Definition: coding.c:498
int GSM_PackSemiOctetNumber(const unsigned char *Number, unsigned char *Output, gboolean semioctet)
Definition: coding.c:1125
void DecodeUTF7(unsigned char *dest, const unsigned char *src, size_t len)
Definition: coding.c:2051
void ReverseUnicodeString(unsigned char *String)
Definition: coding.c:1209