33 # define WIN32_LEAN_AND_MEAN 37 #include "../../debug.h" 45 while (buffer[Pos*2]!=0x00 || buffer[Pos*2+1]!=0x00) {
46 if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == 10) {
48 dest[Pos2*2+1] =
'\\';
53 }
else if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == 13) {
55 dest[Pos2*2+1] =
'\\';
60 }
else if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] ==
'\\') {
62 dest[Pos2*2+1] =
'\\';
65 dest[Pos2*2+1] =
'\\';
67 }
else if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] ==
';') {
69 dest[Pos2*2+1] =
'\\';
74 }
else if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] ==
',') {
76 dest[Pos2*2+1] =
'\\';
82 dest[Pos2*2] = buffer[Pos*2];
83 dest[Pos2*2+1] = buffer[Pos*2+1];
98 while (buffer[Pos]!=0x00) {
99 switch (buffer[Pos]) {
113 dest[Pos2++] = buffer[Pos];
123 int Pos=0, Pos2=0, level=0;
125 while (buffer[Pos*2]!=0x00 || buffer[Pos*2+1]!=0x00) {
126 dest[Pos2*2] = buffer[Pos*2];
127 dest[Pos2*2+1] = buffer[Pos*2+1];
130 if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] ==
'\\') {
137 if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] ==
'n') {
141 if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] ==
'r') {
145 if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] ==
'\\') {
147 dest[Pos2*2+1] =
'\\';
161 int Pos=0, Pos2=0, level=0;
163 while (buffer[Pos]!=0x00) {
164 dest[Pos2] = buffer[Pos];
167 if (buffer[Pos] ==
'\\') {
174 if (buffer[Pos] ==
'n') dest[Pos2] = 10;
175 if (buffer[Pos] ==
'r') dest[Pos2] = 13;
176 if (buffer[Pos] ==
'\\') dest[Pos2] =
'\\';
190 if (str == NULL)
return 0;
192 while(str[len*2] != 0 || str[len*2+1] != 0) len++;
202 switch (retval = mbtowc(dest, src, MB_CUR_MAX)) {
205 default :
return retval;
214 switch (retval = wctomb(dest, src)) {
226 wchar_t value, second;
228 while (src[(2*i)+1]!=0x00 || src[2*i]!=0x00) {
229 value = src[i * 2] * 256 + src[i * 2 + 1];
231 if (value >= 0xD800 && value <= 0xDBFF) {
232 second = src[(i + 1) * 2] * 256 + src[(i + 1) * 2 + 1];
233 if (second >= 0xDC00 && second <= 0xDFFF) {
235 value = ((value - 0xD800) << 10) + (second - 0xDC00) + 0x010000;
247 static char dest[500];
258 static char dest[500];
271 setlocale(LC_ALL,
".OCP");
275 setlocale(LC_ALL,
".ACP");
286 for (i = 0; i < len; i++) {
288 if ((
unsigned char)src[i] == 0x80) {
290 dest[(2 * i) + 1] = 0xac;
293 dest[(2 * i) + 1] = src[i];
297 dest[(2 * i) + 1] = 0;
303 size_t i_len = 0, o_len;
306 for (o_len = 0; i_len < len; o_len++) {
308 dest[o_len*2] = (wc >> 8) & 0xff;
309 dest[(o_len*2)+1] = wc & 0xff;
312 dest[(o_len*2)+1] = 0;
319 division=div(value,10);
320 return ( ( (value-division.quot*10) & 0x0f) << 4) | (division.quot & 0xf);
325 return 10*(value & 0x0f)+(value >> 4);
328 void DecodeBCD (
unsigned char *dest,
const unsigned char *src,
size_t len)
333 for (i = 0; i < len; i++) {
335 if (digit<10) dest[current++]=digit +
'0';
337 if (digit<10) dest[current++]=digit +
'0';
346 for (i = 0; i < len; i++) {
348 dest[current]=dest[current] | ((src[i]-
'0') << 4);
351 dest[current]=src[i]-
'0';
358 if (fill && (len & 0x01)) dest[current]=dest[current] | 0xf0;
363 if (mychar >=
'A' && mychar <=
'F')
364 return mychar -
'A' + 10;
366 if (mychar >=
'a' && mychar <=
'f')
367 return mychar -
'a' + 10;
369 if (mychar >=
'0' && mychar <=
'9')
377 if (digit >= 0 && digit <= 9)
return '0'+(digit);
378 if (digit >=10 && digit <=15)
return 'A'+(digit-10);
384 size_t i, current = 0;
385 int val0, val1, val2, val3;
387 for (i = 0; i < len ; i += 4) {
393 if (val0 < 0 || val1 < 0 || val2 < 0 || val3 < 0) {
397 dest[current++] = (val0 << 4) + val1;
398 dest[current++] = (val2 << 4) + val3;
416 for (i = 0; i < len/2 ; i++) {
419 if (low < 0 || high < 0)
return FALSE;
420 dest[current++] = (high << 4) | low;
428 size_t i, outpos = 0;
430 for (i = 0; i < len; i++) {
440 {0x00,0x40},{0x00,0xa3},{0x00,0x24},{0x00,0xA5},
441 {0x00,0xE8},{0x00,0xE9},{0x00,0xF9},{0x00,0xEC},
442 {0x00,0xF2},{0x00,0xC7},{0x00,
'\n'},{0x00,0xD8},
443 {0x00,0xF8},{0x00,
'\r'},{0x00,0xC5},{0x00,0xE5},
444 {0x03,0x94},{0x00,0x5f},{0x03,0xA6},{0x03,0x93},
445 {0x03,0x9B},{0x03,0xA9},{0x03,0xA0},{0x03,0xA8},
446 {0x03,0xA3},{0x03,0x98},{0x03,0x9E},{0x00,0xb9},
447 {0x00,0xC6},{0x00,0xE6},{0x00,0xDF},{0x00,0xC9},
448 {0x00,
' ' },{0x00,
'!' },{0x00,
'\"'},{0x00,
'#' },
449 {0x00,0xA4},{0x00,
'%' },{0x00,
'&' },{0x00,
'\''},
450 {0x00,
'(' },{0x00,
')' },{0x00,
'*' },{0x00,
'+' },
451 {0x00,
',' },{0x00,
'-' },{0x00,
'.' },{0x00,
'/' },
452 {0x00,
'0' },{0x00,
'1' },{0x00,
'2' },{0x00,
'3' },
453 {0x00,
'4' },{0x00,
'5' },{0x00,
'6' },{0x00,
'7' },
454 {0x00,
'8' },{0x00,
'9' },{0x00,
':' },{0x00,
';' },
455 {0x00,
'<' },{0x00,
'=' },{0x00,
'>' },{0x00,
'?' },
456 {0x00,0xA1},{0x00,
'A' },{0x00,
'B' },{0x00,
'C' },
457 {0x00,
'D' },{0x00,
'E' },{0x00,
'F' },{0x00,
'G' },
458 {0x00,
'H' },{0x00,
'I' },{0x00,
'J' },{0x00,
'K' },
459 {0x00,
'L' },{0x00,
'M' },{0x00,
'N' },{0x00,
'O' },
460 {0x00,
'P' },{0x00,
'Q' },{0x00,
'R' },{0x00,
'S' },
461 {0x00,
'T' },{0x00,
'U' },{0x00,
'V' },{0x00,
'W' },
462 {0x00,
'X' },{0x00,
'Y' },{0x00,
'Z' },{0x00,0xC4},
463 {0x00,0xD6},{0x00,0xD1},{0x00,0xDC},{0x00,0xA7},
464 {0x00,0xBF},{0x00,
'a' },{0x00,
'b' },{0x00,
'c' },
465 {0x00,
'd' },{0x00,
'e' },{0x00,
'f' },{0x00,
'g' },
466 {0x00,
'h' },{0x00,
'i' },{0x00,
'j' },{0x00,
'k' },
467 {0x00,
'l' },{0x00,
'm' },{0x00,
'n' },{0x00,
'o' },
468 {0x00,
'p' },{0x00,
'q' },{0x00,
'r' },{0x00,
's' },
469 {0x00,
't' },{0x00,
'u' },{0x00,
'v' },{0x00,
'w' },
470 {0x00,
'x' },{0x00,
'y' },{0x00,
'z' },{0x00,0xE4},
471 {0x00,0xF6},{0x00,0xF1},{0x00,0xFC},{0x00,0xE0},
498 void DecodeDefault (
unsigned char *dest,
const unsigned char *src,
size_t len,
gboolean UseExtensions,
unsigned char *ExtraAlphabet)
500 size_t pos, current = 0, i;
506 for (pos = 0; pos < len; pos++) {
507 if ((pos < (len - 1)) && UseExtensions && src[pos] == 0x1b) {
521 if (ExtraAlphabet != NULL) {
522 for (i = 0; ExtraAlphabet[i] != 0x00; i += 3) {
523 if (ExtraAlphabet[i] == src[pos]) {
524 dest[current++] = ExtraAlphabet[i + 1];
525 dest[current++] = ExtraAlphabet[i + 2];
530 if (ExtraAlphabet[i] != 0x00) {
831 void EncodeDefault(
unsigned char *dest,
const unsigned char *src,
size_t *len,
gboolean UseExtensions,
unsigned char *ExtraAlphabet)
842 for (i = 0; i < *len; i++) {
843 FoundSpecial =
FALSE;
848 dest[current++] = 0x1b;
868 if (ExtraAlphabet!=NULL && !FoundNormal) {
870 while (ExtraAlphabet[j] != 0x00 || ExtraAlphabet[j+1] != 0x00 || ExtraAlphabet[j+2] != 0x00) {
871 if (ExtraAlphabet[j+1] == src[i*2] &&
872 ExtraAlphabet[j+2] == src[i*2 + 1]) {
873 ret = ExtraAlphabet[j];
880 if (!FoundNormal && !FoundSpecial) {
897 if (FoundNormal)
break;
916 size_t current=0,j,i;
920 while (src[i*2] != 0x00 || src[i*2+1] != 0x00) {
921 FoundSpecial =
FALSE;
927 if (current+2 > maxlen) {
938 if (current+1 > maxlen) {
951 #define ByteMask ((1 << Bits) - 1) 954 const unsigned char *input,
unsigned char *output)
958 unsigned char *output_pos = output;
959 const unsigned char *input_pos = input;
960 unsigned char Rest = 0x00;
963 Bits = offset ? offset : 7;
965 while ((
size_t)(input_pos - input) < in_length) {
967 *output_pos = ((*input_pos &
ByteMask) << (7 - Bits)) | Rest;
968 Rest = *input_pos >> Bits;
973 if ((input_pos != input) || (Bits == 7)) output_pos++;
976 if ((
size_t)(output_pos - output) >= out_length)
break;
990 return output_pos - output;
997 unsigned char *output_pos = output;
998 const unsigned char *input_pos = input;
1001 Bits = (7 + offset) % 8;
1010 while ((
size_t)(input_pos - input) < length) {
1011 unsigned char Byte = *input_pos;
1013 *output_pos = Byte >> (7 - Bits);
1017 *(output_pos-1) |= (Byte & ((1 << (7-Bits)) - 1)) << (Bits+1);
1021 if (Bits == -1) Bits = 7;
else output_pos++;
1025 return (output_pos - output);
1031 size_t length = Number[*pos];
1034 smfprintf(di,
"Number Length=%ld\n", (
long)length);
1042 strcpy(Buffer,
"<NOT DECODED>");
1044 if (length > bufferlength) {
1051 if (length % 2) length++;
1052 length=length / 2 + 1;
1065 smfprintf(di,
"Number type %02x (%d %d %d %d|%d %d %d %d)\n", Number[*pos + 1],
1066 Number[*pos + 1] & 0x80 ? 1 : 0,
1067 Number[*pos + 1] & 0x40 ? 1 : 0,
1068 Number[*pos + 1] & 0x20 ? 1 : 0,
1069 Number[*pos + 1] & 0x10 ? 1 : 0,
1070 Number[*pos + 1] & 0x08 ? 1 : 0,
1071 Number[*pos + 1] & 0x04 ? 1 : 0,
1072 Number[*pos + 1] & 0x02 ? 1 : 0,
1073 Number[*pos + 1] & 0x01 ? 1 : 0
1076 if ((Number[*pos + 1] & 0x80) == 0) {
1077 smfprintf(di,
"Numbering plan not supported!\n");
1082 switch ((Number[*pos + 1] & 0x70)) {
1084 if (length > 6) length++;
1085 smfprintf(di,
"Alphanumeric number, length %ld\n", (
long)length);
1090 smfprintf(di,
"International number\n");
1092 DecodeBCD(Buffer+1,Number+*pos+2, length);
1095 DecodeBCD (Buffer, Number+*pos+2, length);
1099 smfprintf(di,
"Len %ld\n", (
long)length);
1103 *pos += 2 + ((Number[*pos] + 1) / 2);
1105 *pos += 1 + Number[*pos];
1127 unsigned char format;
1128 int length, i, skip = 0;
1129 unsigned char *buffer;
1132 buffer = (
unsigned char*)malloc(length + 2);
1134 if (buffer == NULL) {
1141 if (buffer[0] ==
'+') {
1144 }
else if (buffer[0] ==
'0' && buffer[1] ==
'0') {
1147 }
else if (buffer[0] ==
'+' && buffer[1] ==
'0' && buffer[2] ==
'0') {
1154 for (i = 0; i < length; i++) {
1157 if (strchr(
"+0123456789*#pP", buffer[i]) == NULL) {
1172 if (strlen(buffer)==7) length--;
1185 if (semioctet)
return length;
1188 if (length % 2) length++;
1189 return length / 2 + 1;
1197 if (Dest == Source)
return;
1199 while (Source[j]!=0x00 || Source[j+1]!=0x00) {
1200 Dest[j] = Source[j];
1201 Dest[j+1] = Source[j+1];
1212 unsigned char byte1, byte2;
1214 while (String[j]!=0x00 || String[j+1]!=0x00) {
1216 byte2 = String[j+1];
1217 String[j+1] = byte1;
1229 int j = 0, current = 0;
1231 if (Source[0] == 0xFF && Source[1] == 0xFE) j = 2;
1232 if (Source[0] == 0xFE && Source[1] == 0xFF) j = 2;
1234 while (Source[j]!=0x00 || Source[j+1]!=0x00) {
1235 if (Source[0] == 0xFF) {
1236 Dest[current++] = Source[j+1];
1237 Dest[current++] = Source[j];
1239 Dest[current++] = Source[j];
1240 Dest[current++] = Source[j+1];
1244 Dest[current++] = 0;
1248 int GetBit(
unsigned char *Buffer,
size_t BitNum)
1250 return Buffer[BitNum / 8] & (1 << (7 - (BitNum % 8)));
1253 int SetBit(
unsigned char *Buffer,
size_t BitNum)
1255 return Buffer[BitNum / 8] |= 1 << (7 - (BitNum % 8));
1260 return Buffer[BitNum / 8] &= 255 - (1 << (7 - (BitNum % 8)));
1267 while(((*CurrentBit) + i) % 8 != 0) {
1268 ClearBit(Destination, (*CurrentBit)+i);
1272 (*CurrentBit) = (*CurrentBit) + i;
1279 while(((*CurrentBit) + i) % 8 != 0) {
1283 (*CurrentBit) = (*CurrentBit) + i;
1288 unsigned char *Source,
1289 size_t BitsToProcess)
1293 for (i = 0; i < BitsToProcess; i++) {
1295 SetBit(Destination, (*CurrentBit)+i);
1297 ClearBit(Destination, (*CurrentBit)+i);
1300 (*CurrentBit) = (*CurrentBit) + BitsToProcess;
1305 unsigned char Source,
1306 size_t BitsToProcess)
1308 AddBuffer(Destination, CurrentBit, &Source, BitsToProcess);
1313 unsigned char *Destination,
1314 size_t BitsToProcess)
1318 while (i!=BitsToProcess) {
1319 if (
GetBit(Source, (*CurrentBit)+i)) {
1326 (*CurrentBit) = (*CurrentBit) + BitsToProcess;
1332 size_t BitsToProcess)
1334 size_t l=0,z=128,i=0;
1336 while (i!=BitsToProcess) {
1337 if (
GetBit(Source, (*CurrentBit)+i)) l=l+z;
1342 (*CurrentBit) = (*CurrentBit) + i;
1348 size_t BitsToProcess)
1352 z = 1<<(BitsToProcess-1);
1354 while (i!=BitsToProcess) {
1355 if (
GetBit(Source, (*CurrentBit)+i)) l=l+z;
1360 (*CurrentBit) = (*CurrentBit) + i;
1369 size_t i,current = 0;
1372 for (i = 0; i < len; i++) {
1374 if (src[i*2] == 0x00 && src[i*2+1] ==
'~') {
1375 dest[current++] = 0x00;
1376 dest[current++] =
'~';
1378 dest[current++] = 0x00;
1379 dest[current++] = 0x01;
1380 dest[current++] = src[i*2];
1381 dest[current++] = src[i*2+1];
1385 if (src[i*2] == 0x00 && src[i*2+1] ==
'~') {
1388 dest[current++] = src[i*2];
1389 dest[current++] = src[i*2+1];
1394 dest[current++] = 0x00;
1395 dest[current++] = 0x01;
1397 dest[current++] = 0x00;
1398 dest[current] = 0x00;
1403 size_t i=0,current=0;
1405 for (i=0;i<len;i++) {
1408 switch (src[2*i+1]) {
1410 dest[current++] = 0x00;
1411 dest[current++] =
'~';
1414 dest[current++] = 0x00;
1415 dest[current++] =
'~';
1416 dest[current++] = 0x00;
1417 dest[current++] =
'~';
1420 dest[current++] = src[i*2];
1421 dest[current++] = src[i*2+1];
1425 dest[current++] = src[i*2];
1426 dest[current++] = src[i*2+1];
1429 dest[current++] = 0x00;
1430 dest[current] = 0x00;
1442 if (a == NULL || b == NULL)
return FALSE;
1444 if (num == 0) num = -1;
1446 for (i = 0; i != num; i++) {
1447 if ((a[i*2] == 0x00 && a[i*2+1] == 0x00) && (b[i*2] == 0x00 && b[i*2+1] == 0x00))
return TRUE;
1448 if ((a[i*2] == 0x00 && a[i*2+1] == 0x00) || (b[i*2] == 0x00 && b[i*2+1] == 0x00))
return FALSE;
1449 wc = a[i*2+1] | (a[i*2] << 8);
1450 wc2 = b[i*2+1] | (b[i*2] << 8);
1451 if (towlower(wc) != towlower(wc2))
return FALSE;
1462 if (a[i*2] != b[i*2] || a[i*2+1] != b[i*2+1])
return FALSE;
1463 if (a[i*2] == 0x00 && a[i*2+1] == 0x00)
return TRUE;
1465 if (num == i)
return TRUE;
1472 #ifndef HAVE_ISWSPACE 1474 unsigned char dest[10];
1478 wc = src[1] | (src[0] << 8);
1480 #ifndef HAVE_ISWSPACE 1483 if (isspace(((
int)dest[0]))!=0)
return TRUE;
1488 if (iswspace(wc))
return TRUE;
1508 unsigned char *
mywstrstr (
const unsigned char *haystack,
const unsigned char *needle)
1511 #define tolowerwchar(x) (towlower((wchar_t)( (((&(x))[0] & 0xff) << 8) | (((&(x))[1] & 0xff)) ))) 1513 register const unsigned char *rhaystack, *rneedle;
1550 rhaystack = haystack + 2;
1574 return (
unsigned char *)haystack;
1590 if (Buffer == NULL)
return ERR_NONE;
1591 for (; (*Pos) < MaxLen; (*Pos)++) {
1592 switch (Buffer[*Pos]) {
1598 if (Buffer[*Pos] == 0x0d) {
1599 if (was_cr && skip)
return ERR_NONE;
1602 if (was_lf && skip)
return ERR_NONE;
1608 if (quoted_printable && pos > 0 && OutBuffer[pos - 1] ==
'=') {
1612 was_cr = (Buffer[*Pos] == 0x0d);
1613 was_lf = (Buffer[*Pos] == 0x0a);
1618 if (Buffer[*Pos + 1] == 0x0a || Buffer[*Pos + 1] == 0x0d) {
1621 if (Buffer[tmp] ==
' ') {
1630 if (Buffer[*Pos] == 0x0d && (*Pos)+1 < MaxLen && Buffer[*Pos + 1] == 0x0a) {
1642 if (Buffer[*Pos] ==
':' &&
1643 strstr(OutBuffer,
";ENCODING=QUOTED-PRINTABLE") != NULL) {
1644 quoted_printable =
TRUE;
1647 OutBuffer[pos] = Buffer[*Pos];
1663 size_t OutLen = 200;
1665 *OutBuffer = (
char *)malloc(OutLen);
1667 (*OutBuffer)[0] = 0;
1669 if (Buffer == NULL)
return ERR_NONE;
1670 while ((*Pos) < MaxLen) {
1671 switch (Buffer[*Pos]) {
1677 if (Buffer[*Pos] == 0x0d) {
1678 if (was_cr && skip)
return ERR_NONE;
1681 if (was_lf && skip)
return ERR_NONE;
1685 if (pos != 0 && !skip) {
1688 if ((*OutBuffer)[pos - 1] ==
'=' && quoted_printable) {
1690 (*OutBuffer)[pos] = 0;
1692 was_cr = (Buffer[*Pos] == 0x0d);
1693 was_lf = (Buffer[*Pos] == 0x0a);
1698 if (Buffer[*Pos + 1] == 0x0a || Buffer[*Pos + 1] == 0x0d) {
1701 if (Buffer[tmp] ==
' ') {
1711 if (Buffer[*Pos] ==
':' &&
1712 strstr(*OutBuffer,
";ENCODING=QUOTED-PRINTABLE") != NULL) {
1713 quoted_printable =
TRUE;
1716 (*OutBuffer)[pos] = Buffer[*Pos];
1718 (*OutBuffer)[pos] = 0;
1719 if (pos + 2 >= OutLen) {
1721 *OutBuffer = (
char *)realloc(*OutBuffer, OutLen);
1734 double multiply = 1;
1738 for (i=0;i<strlen(text);i++) {
1739 if (isdigit((
int)text[i])) {
1741 (*d)=(*d)*10+(text[i]-
'0');
1743 multiply=multiply*0.1;
1744 (*d)=(*d)+(text[i]-
'0')*multiply;
1747 if (text[i]==
'.' || text[i]==
',') before=
FALSE;
1757 }
else if (src < 0x800) {
1758 ret[0] = 192 + (src / 64);
1759 ret[1] = 128 + (src % 64);
1761 }
else if (src < 0x10000) {
1762 ret[0] = 224 + (src / (64 * 64));
1763 ret[1] = 128 + ((src / 64) % 64);
1764 ret[2] = 128 + (src % 64);
1766 }
else if (src < 0x200000) {
1767 ret[0] = 240 + (src / (64 * 64 * 64));
1768 ret[1] = 128 + ((src / (64 * 64)) % 64);
1769 ret[2] = 128 + ((src / 64) % 64);
1770 ret[3] = 128 + (src % 64);
1772 }
else if (src < 0x4000000) {
1773 ret[0] = 248 + (src / (64 * 64 * 64 * 64));
1774 ret[1] = 128 + ((src / (64 * 64 * 64)) % 64);
1775 ret[2] = 128 + ((src / (64 * 64)) % 64);
1776 ret[3] = 128 + ((src / 64) % 64);
1777 ret[4] = 128 + (src % 64);
1779 }
else if (src < 0x80000000L) {
1780 ret[0] = 252 + (src / (64 * 64 * 64 * 64 * 64));
1781 ret[1] = 128 + ((src / (64 * 64 * 64 * 64)) % 64);
1782 ret[2] = 128 + ((src / (64 * 64 * 64)) % 64);
1783 ret[3] = 128 + ((src / (64 * 64)) % 64);
1784 ret[4] = 128 + ((src / 64) % 64);
1785 ret[5] = 128 + (src % 64);
1796 size_t i, j=0, z, w, len;
1797 unsigned char mychar[8];
1799 unsigned long value, second;
1803 for (i = 0; i < len; i++) {
1804 value = src[i * 2] * 256 + src[i * 2 + 1];
1806 if (value >= 0xD800 && value <= 0xDBFF && (i + 1) < len) {
1807 second = src[(i + 1) * 2] * 256 + src[(i + 1) * 2 + 1];
1808 if (second >= 0xDC00 && second <= 0xDFFF) {
1809 value = ((value - 0xD800) << 10) + (second - 0xDC00) + 0x010000;
1813 if (z == 1 && mychar[0] < 32) {
1815 sprintf(dest + j,
"=%02X", mychar[0]);
1817 }
else if (z == 1) {
1818 memcpy(dest + j, mychar, z);
1822 for (w = 0; w < z; w++) {
1823 sprintf(dest + j,
"=%02X", mychar[w]);
1837 size_t i, j=0, z, len;
1838 unsigned char mychar[8];
1840 unsigned long value, second;
1844 for (i = 0; i < len; i++) {
1845 value = src[i * 2] * 256 + src[i * 2 + 1];
1847 if (value >= 0xD800 && value <= 0xDBFF && (i + 1) < len) {
1848 second = src[(i + 1) * 2] * 256 + src[(i + 1) * 2 + 1];
1849 if (second >= 0xDC00 && second <= 0xDFFF) {
1851 value = ((value - 0xD800) << 10) + (second - 0xDC00) + 0x010000;
1855 memcpy(dest + j, mychar, z);
1868 if (len < 1)
return 0;
1873 if (src[0] < 194)
return 0;
1875 if (len < 2)
return 0;
1876 (*dest) = (src[0]-192)*64 + (src[1]-128);
1880 if (len < 3)
return 0;
1881 (*dest) = (src[0]-224)*4096 + (src[1]-128)*64 + (src[2]-128);
1891 size_t i = 0, j = 0;
1894 if (src[i] ==
'=' && i + 2 < len
1915 unsigned char mychar[10];
1918 for (i = 0; i<=len; ) {
1921 if (src[z*3+i] !=
'=' || z*3+i+3>len ||
1929 if (z == 1 && mychar[0] < 194)
break;
1940 dest[j++] = (ret >> 8) & 0xff;
1941 dest[j++] = ret & 0xff;
1947 void DecodeUTF8(
unsigned char *dest,
const char *src,
size_t len)
1959 dest[j++] = (ret >> 8) & 0xff;
1960 dest[j++] = ret & 0xff;
1969 char *pos, *pos_end;
1970 const char *lastpos;
1972 unsigned long long int c;
1976 tmp = (
char *)calloc(2 * len,
sizeof(
char));
1990 while ((*lastpos != 0) && ((pos = strchr(lastpos,
'&')) != NULL)) {
1992 strncat(tmp, lastpos, pos - lastpos);
1997 if (*pos == 0)
break;
1999 pos_end = strchr(pos,
';');
2000 if (pos_end - pos > 6 || pos_end == NULL) {
2001 if (pos_end == NULL) {
2002 dbgprintf(NULL,
"No entity end found, ignoring!\n");
2004 dbgprintf(NULL,
"Too long html entity, ignoring!\n");
2006 strncat(tmp, lastpos, 1);
2012 entity = strdup(pos);
2013 if (entity == NULL)
break;
2014 entity[pos_end - pos] = 0;
2015 dbgprintf(NULL,
"Found XML entity: %s\n", entity);
2016 if (entity[0] ==
'#') {
2017 if (entity[1] ==
'x' || entity[1] ==
'X') {
2018 c = strtoull(entity + 2, NULL, 16);
2020 c = strtoull(entity + 1, NULL, 10);
2022 dbgprintf(NULL,
"Unicode char 0x%04llx\n", c);
2023 tmplen = strlen(tmp);
2026 }
else if (strcmp(entity,
"amp") == 0) {
2028 }
else if (strcmp(entity,
"apos") == 0) {
2030 }
else if (strcmp(entity,
"gt") == 0) {
2032 }
else if (strcmp(entity,
"lt") == 0) {
2034 }
else if (strcmp(entity,
"quot") == 0) {
2037 dbgprintf(NULL,
"Could not decode XML entity!\n");
2038 strncat(tmp, lastpos, pos_end - pos + 1);
2042 lastpos = pos_end + 1;
2045 strcat(tmp, lastpos);
2051 void DecodeUTF7(
unsigned char *dest,
const unsigned char *src,
size_t len)
2058 if (src[i] ==
'+') {
2060 while (src[z+i+1] !=
'-' && z+i+1<len) z++;
2067 dest[j++] = (ret >> 8) & 0xff;
2068 dest[j++] = ret & 0xff;
2072 dest[j++] = (ret >> 8) & 0xff;
2073 dest[j++] = ret & 0xff;
2110 unsigned char cb64[]=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2112 out[0] = cb64[ in[0] >> 2 ];
2113 out[1] = cb64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ];
2114 out[2] = (
unsigned char) (len > 1 ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] :
'=');
2115 out[3] = (
unsigned char) (len > 2 ? cb64[ in[2] & 0x3f ] :
'=');
2118 void EncodeBASE64(
const unsigned char *Input,
char *Output,
const size_t Length)
2120 unsigned char in[3], out[4];
2121 size_t i, pos = 0, len, outpos = 0;
2123 while (pos < Length) {
2125 for (i = 0; i < 3; i++) {
2135 for (i = 0; i < 4; i++) Output[outpos++] = out[i];
2144 out[0] = (
unsigned char) ((in[0] << 2) | (in[1] >> 4));
2145 out[1] = (
unsigned char) ((in[1] << 4) | (in[2] >> 2));
2146 out[2] = (
unsigned char) (((in[2] << 6) & 0xc0) | in[3]);
2149 int DecodeBASE64(
const char *Input,
unsigned char *Output,
const size_t Length)
2151 unsigned char cd64[]=
"|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq";
2152 unsigned char in[4], out[3], v;
2153 size_t i, len, pos = 0, outpos = 0;
2155 while (pos < Length) {
2157 for(i = 0; i < 4; i++) {
2160 if (pos >= Length)
break;
2161 v = (
unsigned char) Input[pos++];
2162 v = (
unsigned char) ((v < 43 || v > 122) ? 0 : cd64[ v - 43 ]);
2163 if (v) v = (
unsigned char) ((v ==
'$') ? 0 : v - 61);
2168 in[i] = (
unsigned char) (v - 1);
2174 for(i = 0; i < len - 1; i++) Output[outpos++] = out[i];
2185 #ifdef ICONV_SECOND_ARGUMENT_IS_CONST 2186 # define SECOND_ICONV_ARG const char * 2188 # define SECOND_ICONV_ARG char * 2191 gboolean IconvDecode(
const char *charset,
const char *input,
const size_t inlen,
unsigned char *output,
size_t outlen)
2196 size_t rest = inlen + 1;
2197 SECOND_ICONV_ARG in;
2200 ic = iconv_open(
"UCS-2BE", charset);
2201 if (ic == (iconv_t)(-1))
return FALSE;
2204 in = (SECOND_ICONV_ARG)input;
2206 iconv(ic, &in, &rest, &out, &outlen);
2213 gboolean IconvEncode(
const char *charset,
const unsigned char *input,
const size_t inlen,
char *output,
size_t outlen)
2216 size_t rest = inlen;
2217 SECOND_ICONV_ARG in;
2220 ic = iconv_open(charset,
"UCS-2BE");
2221 if (ic == (iconv_t)(-1))
return FALSE;
2224 in = (SECOND_ICONV_ARG)input;
2226 iconv(ic, &in, &rest, &out, &outlen);
void DecodeBCD(unsigned char *dest, const unsigned char *src, size_t len)
char * DecodeUnicodeConsole(const unsigned char *src)
char * DecodeUnicodeString(const unsigned char *src)
void EncodeBCD(unsigned char *dest, const unsigned char *src, size_t len, gboolean fill)
unsigned char * DecodeUnicodeSpecialChars(unsigned char *dest, const unsigned char *buffer)
void CopyUnicodeString(unsigned char *Dest, const unsigned char *Source)
static unsigned char ConvertTable[]
void DecodeDefault(unsigned char *dest, const unsigned char *src, size_t len, gboolean UseExtensions, unsigned char *ExtraAlphabet)
GSM_Error GSM_GetVCSLine(char **OutBuffer, char *Buffer, size_t *Pos, size_t MaxLen, gboolean MergeLines)
void DecodeISO88591QuotedPrintable(unsigned char *dest, const unsigned char *src, size_t len)
void FindDefaultAlphabetLen(const unsigned char *src, size_t *srclen, size_t *smslen, size_t maxlen)
int GSM_PackSemiOctetNumber(const unsigned char *Number, unsigned char *Output, gboolean semioctet)
void AddBufferByte(unsigned char *Destination, size_t *CurrentBit, unsigned char Source, size_t BitsToProcess)
void DecodeUTF7(unsigned char *dest, const unsigned char *src, size_t len)
void BufferAlign(unsigned char *Destination, size_t *CurrentBit)
#define GSM_MAX_NUMBER_LENGTH
gboolean EncodeUTF8QuotedPrintable(char *dest, const unsigned char *src)
void GetBufferInt(unsigned char *Source, size_t *CurrentBit, int *integer, size_t BitsToProcess)
void EncodeBASE64(const unsigned char *Input, char *Output, const size_t Length)
int DecodeWithUTF8Alphabet(const unsigned char *src, wchar_t *dest, size_t len)
void GetBufferI(unsigned char *Source, size_t *CurrentBit, int *result, size_t BitsToProcess)
void DumpMessageText(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
static unsigned char GSM_DefaultAlphabetUnicode[128+1][2]
int ClearBit(unsigned char *Buffer, size_t BitNum)
int GSM_PackSevenBitsToEight(size_t offset, const unsigned char *input, unsigned char *output, size_t length)
gboolean mywstrncasecmp(unsigned const char *a, unsigned const char *b, int num)
size_t UnicodeLength(const unsigned char *str)
void DecodeISO88591(unsigned char *dest, const char *src, size_t len)
void EncodeHexUnicode(char *dest, const unsigned char *src, size_t len)
char EncodeWithHexBinAlphabet(int digit)
void StringToDouble(char *text, double *d)
unsigned char EncodeWithBCDAlphabet(int value)
void BufferAlignNumber(size_t *CurrentBit)
gboolean DecodeHexUnicode(unsigned char *dest, const char *src, size_t len)
void DecodeUTF8QuotedPrintable(unsigned char *dest, const char *src, size_t len)
GSM_Debug_Info GSM_global_debug
void GetBuffer(unsigned char *Source, size_t *CurrentBit, unsigned char *Destination, size_t BitsToProcess)
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
static void EncodeBASE64Block(const unsigned char in[3], char out[4], const size_t len)
void ReverseUnicodeString(unsigned char *String)
char * EncodeSpecialChars(char *dest, const char *buffer)
void DecodeUTF8(unsigned char *dest, const char *src, size_t len)
int DecodeWithBCDAlphabet(unsigned char value)
gboolean mywstrncmp(unsigned const char *a, unsigned const char *b, int num)
int SetBit(unsigned char *Buffer, size_t BitNum)
int EncodeWithUnicodeAlphabet(const unsigned char *src, wchar_t *dest)
void AddBuffer(unsigned char *Destination, size_t *CurrentBit, unsigned char *Source, size_t BitsToProcess)
void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, size_t len)
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_UnpackEightBitsToSeven(size_t offset, size_t in_length, size_t out_length, const unsigned char *input, unsigned char *output)
void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, size_t len)
unsigned char * mywstrstr(const unsigned char *haystack, const unsigned char *needle)
gboolean DecodeHexBin(unsigned char *dest, const unsigned char *src, size_t len)
void EncodeHexBin(char *dest, const unsigned char *src, size_t len)
int smfprintf(GSM_Debug_Info *d, const char *format,...)
char * DecodeSpecialChars(char *dest, const char *buffer)
void DecodeUnicode(const unsigned char *src, char *dest)
unsigned char * EncodeUnicodeSpecialChars(unsigned char *dest, const unsigned char *buffer)
gboolean EncodeUTF8(char *dest, const unsigned char *src)
void ReadUnicodeFile(unsigned char *Dest, const unsigned char *Source)
int EncodeWithUTF8Alphabet(unsigned long src, unsigned char *ret)
void DecodeXMLUTF8(unsigned char *dest, const char *src, size_t len)
void EncodeDefault(unsigned char *dest, const unsigned char *src, size_t *len, gboolean UseExtensions, unsigned char *ExtraAlphabet)
GSM_Error MyGetLine(char *Buffer, size_t *Pos, char *OutBuffer, size_t MaxLen, size_t MaxOutLen, gboolean MergeLines)
int DecodeWithHexBinAlphabet(unsigned char mychar)
int DecodeWithUnicodeAlphabet(wchar_t src, unsigned char *dest)
int GetBit(unsigned char *Buffer, size_t BitNum)
static void DecodeBASE64Block(const char in[4], unsigned char out[3])
static unsigned char GSM_DefaultAlphabetCharsExtension[][3]
gboolean myiswspace(unsigned const char *src)
int DecodeBASE64(const char *Input, unsigned char *Output, const size_t Length)