-rw-r--r-- | gammu/emb/common/misc/coding/coding.c | 177 | ||||
-rw-r--r-- | gammu/emb/common/misc/coding/coding.h | 27 | ||||
-rw-r--r-- | gammu/emb/common/misc/coding/md5.c | 2 | ||||
-rw-r--r-- | gammu/emb/common/misc/misc.c | 19 | ||||
-rw-r--r-- | gammu/emb/common/misc/misc.h | 8 |
5 files changed, 209 insertions, 24 deletions
diff --git a/gammu/emb/common/misc/coding/coding.c b/gammu/emb/common/misc/coding/coding.c index 62543ac..b30b645 100644 --- a/gammu/emb/common/misc/coding/coding.c +++ b/gammu/emb/common/misc/coding/coding.c | |||
@@ -1,8 +1,12 @@ | |||
1 | /* (c) 2002-2004 by Marcin Wiacek, Michal Cihar and others */ | 1 | /* (c) 2002-2004 by Marcin Wiacek, Michal Cihar and others */ |
2 | /* based on some work from MyGnokii and Gnokii */ | 2 | /* based on some work from MyGnokii (www.mwiacek.com) */ |
3 | /* based on some work from Gnokii (www.gnokii.org) | ||
4 | * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot | ||
5 | * GNU GPL version 2 or later | ||
6 | */ | ||
3 | 7 | ||
4 | #include <stdio.h> | 8 | #include <stdio.h> |
5 | #include <stdlib.h> | 9 | #include <stdlib.h> |
6 | #include <string.h> | 10 | #include <string.h> |
7 | #include <ctype.h> | 11 | #include <ctype.h> |
8 | #include <locale.h> | 12 | #include <locale.h> |
@@ -13,12 +17,161 @@ | |||
13 | # include "windows.h" | 17 | # include "windows.h" |
14 | #endif | 18 | #endif |
15 | 19 | ||
16 | #include "../misc.h" | 20 | #include "../misc.h" |
17 | #include "coding.h" | 21 | #include "coding.h" |
18 | 22 | ||
23 | /* function changes #10 #13 chars to \n \r */ | ||
24 | char *EncodeUnicodeSpecialChars(unsigned char *buffer) | ||
25 | { | ||
26 | int Pos=0, Pos2=0; | ||
27 | static unsigned charBuf[20000]; | ||
28 | |||
29 | while (buffer[Pos*2]!=0x00 || buffer[Pos*2+1]!=0x00) { | ||
30 | if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == 10) { | ||
31 | Buf[Pos2*2] = 0x00; | ||
32 | Buf[Pos2*2+1] = '\\'; | ||
33 | Pos2++; | ||
34 | Buf[Pos2*2] = 0x00; | ||
35 | Buf[Pos2*2+1] = 'n'; | ||
36 | Pos2++; | ||
37 | } else if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == 13) { | ||
38 | Buf[Pos2*2] = 0x00; | ||
39 | Buf[Pos2*2+1] = '\\'; | ||
40 | Pos2++; | ||
41 | Buf[Pos2*2] = 0x00; | ||
42 | Buf[Pos2*2+1] = 'r'; | ||
43 | Pos2++; | ||
44 | } else if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == '\\') { | ||
45 | Buf[Pos2*2] = 0x00; | ||
46 | Buf[Pos2*2+1] = '\\'; | ||
47 | Pos2++; | ||
48 | Buf[Pos2*2] = 0x00; | ||
49 | Buf[Pos2*2+1] = '\\'; | ||
50 | Pos2++; | ||
51 | } else { | ||
52 | Buf[Pos2*2] = buffer[Pos*2]; | ||
53 | Buf[Pos2*2+1] = buffer[Pos*2+1]; | ||
54 | Pos2++; | ||
55 | } | ||
56 | Pos++; | ||
57 | } | ||
58 | Buf[Pos2*2] = 0; | ||
59 | Buf[Pos2*2+1] = 0; | ||
60 | return Buf; | ||
61 | } | ||
62 | |||
63 | /* function changes #10 #13 chars to \n \r */ | ||
64 | char *EncodeSpecialChars(unsigned char *buffer) | ||
65 | { | ||
66 | int Pos=0, Pos2=0; | ||
67 | static unsigned charBuf[10000]; | ||
68 | |||
69 | while (buffer[Pos]!=0x00) { | ||
70 | switch (buffer[Pos]) { | ||
71 | case 10: | ||
72 | Buf[Pos2++] = '\\'; | ||
73 | Buf[Pos2++] = 'n'; | ||
74 | break; | ||
75 | case 13: | ||
76 | Buf[Pos2++] = '\\'; | ||
77 | Buf[Pos2++] = 'r'; | ||
78 | break; | ||
79 | case '\\': | ||
80 | Buf[Pos2++] = '\\'; | ||
81 | Buf[Pos2++] = '\\'; | ||
82 | break; | ||
83 | default: | ||
84 | Buf[Pos2++] = buffer[Pos]; | ||
85 | } | ||
86 | Pos++; | ||
87 | } | ||
88 | Buf[Pos2] = 0; | ||
89 | return Buf; | ||
90 | } | ||
91 | |||
92 | char *DecodeUnicodeSpecialChars(unsigned char *buffer) | ||
93 | { | ||
94 | int Pos=0, Pos2=0, level=0; | ||
95 | static unsigned charBuf[10000]; | ||
96 | |||
97 | while (buffer[Pos*2]!=0x00 || buffer[Pos*2+1]!=0x00) { | ||
98 | Buf[Pos2*2] = buffer[Pos*2]; | ||
99 | Buf[Pos2*2+1] = buffer[Pos*2+1]; | ||
100 | switch (level) { | ||
101 | case 0: | ||
102 | if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == '\\') { | ||
103 | level = 1; | ||
104 | } else { | ||
105 | Pos2++; | ||
106 | } | ||
107 | break; | ||
108 | case 1: | ||
109 | if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == 'n') { | ||
110 | Buf[Pos2*2] = 0; | ||
111 | Buf[Pos2*2+1] = 10; | ||
112 | } | ||
113 | if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == 'r') { | ||
114 | Buf[Pos2*2] = 0; | ||
115 | Buf[Pos2*2+1] = 13; | ||
116 | } | ||
117 | if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == '\\') { | ||
118 | Buf[Pos2*2] = 0; | ||
119 | Buf[Pos2*2+1] = '\\'; | ||
120 | } | ||
121 | Pos2++; | ||
122 | level = 0; | ||
123 | } | ||
124 | Pos++; | ||
125 | } | ||
126 | Buf[Pos2*2] = 0; | ||
127 | Buf[Pos2*2+1] = 0; | ||
128 | return Buf; | ||
129 | } | ||
130 | |||
131 | char *DecodeSpecialChars(unsigned char *buffer) | ||
132 | { | ||
133 | int Pos=0, Pos2=0, level=0; | ||
134 | static unsigned charBuf[10000]; | ||
135 | |||
136 | while (buffer[Pos]!=0x00) { | ||
137 | Buf[Pos2] = buffer[Pos]; | ||
138 | switch (level) { | ||
139 | case 0: | ||
140 | if (buffer[Pos] == '\\') { | ||
141 | level = 1; | ||
142 | } else { | ||
143 | Pos2++; | ||
144 | } | ||
145 | break; | ||
146 | case 1: | ||
147 | if (buffer[Pos] == 'n') Buf[Pos2] = 10; | ||
148 | if (buffer[Pos] == 'r') Buf[Pos2] = 13; | ||
149 | if (buffer[Pos] == '\\') Buf[Pos2] = '\\'; | ||
150 | Pos2++; | ||
151 | level = 0; | ||
152 | } | ||
153 | Pos++; | ||
154 | } | ||
155 | Buf[Pos2] = 0; | ||
156 | return Buf; | ||
157 | } | ||
158 | |||
159 | char *mystrcasestr(unsigned const char *a, unsigned const char *b) | ||
160 | { | ||
161 | unsigned char A[2000], B[200]; | ||
162 | int i; | ||
163 | |||
164 | memset(A,0,sizeof(A)); | ||
165 | memset(B,0,sizeof(B)); | ||
166 | for (i=0;i<(int)strlen(a);i++) A[i] = tolower(a[i]); | ||
167 | for (i=0;i<(int)strlen(b);i++) B[i] = tolower(b[i]); | ||
168 | |||
169 | return strstr(A,B); | ||
170 | } | ||
171 | |||
19 | unsigned int UnicodeLength(const unsigned char *str) | 172 | unsigned int UnicodeLength(const unsigned char *str) |
20 | { | 173 | { |
21 | unsigned int len = 0; | 174 | unsigned int len = 0; |
22 | 175 | ||
23 | if (str == NULL) return 0; | 176 | if (str == NULL) return 0; |
24 | 177 | ||
@@ -583,20 +736,20 @@ void GSM_UnpackSemiOctetNumber(unsigned char *retval, unsigned char *Number, boo | |||
583 | length=length / 2 + 1; | 736 | length=length / 2 + 1; |
584 | } | 737 | } |
585 | 738 | ||
586 | /*without leading byte with format of number*/ | 739 | /*without leading byte with format of number*/ |
587 | length--; | 740 | length--; |
588 | 741 | ||
589 | switch (Number[1]) { | 742 | switch ((Number[1] & 112)) { |
590 | case NUMBER_ALPHANUMERIC: | 743 | case (NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN & 112): |
591 | if (length > 6) length++; | 744 | if (length > 6) length++; |
592 | dbgprintf("Alphanumeric number, length %i\n",length); | 745 | dbgprintf("Alphanumeric number, length %i\n",length); |
593 | GSM_UnpackEightBitsToSeven(0, length, length, Number+2, Buffer); | 746 | GSM_UnpackEightBitsToSeven(0, length, length, Number+2, Buffer); |
594 | Buffer[length]=0; | 747 | Buffer[length]=0; |
595 | break; | 748 | break; |
596 | case NUMBER_INTERNATIONAL: | 749 | case (NUMBER_INTERNATIONAL_NUMBERING_PLAN_ISDN & 112): |
597 | dbgprintf("International number\n"); | 750 | dbgprintf("International number\n"); |
598 | Buffer[0]='+'; | 751 | Buffer[0]='+'; |
599 | DecodeBCD(Buffer+1,Number+2, length); | 752 | DecodeBCD(Buffer+1,Number+2, length); |
600 | break; | 753 | break; |
601 | default: | 754 | default: |
602 | dbgprintf("Default number %02x\n",Number[1]); | 755 | dbgprintf("Default number %02x\n",Number[1]); |
@@ -628,36 +781,36 @@ int GSM_PackSemiOctetNumber(unsigned char *Number, unsigned char *Output, bool s | |||
628 | int length, i; | 781 | int length, i; |
629 | 782 | ||
630 | length=UnicodeLength(Number); | 783 | length=UnicodeLength(Number); |
631 | memcpy(buffer,DecodeUnicodeString(Number),length+1); | 784 | memcpy(buffer,DecodeUnicodeString(Number),length+1); |
632 | 785 | ||
633 | /* Checking for format number */ | 786 | /* Checking for format number */ |
634 | format = NUMBER_UNKNOWN; | 787 | format = NUMBER_UNKNOWN_NUMBERING_PLAN_ISDN; |
635 | for (i=0;i<length;i++) { | 788 | for (i=0;i<length;i++) { |
636 | /* first byte is '+'. Number can be international */ | 789 | /* first byte is '+'. Number can be international */ |
637 | if (i==0 && buffer[i]=='+') { | 790 | if (i==0 && buffer[i]=='+') { |
638 | format=NUMBER_INTERNATIONAL; | 791 | format=NUMBER_INTERNATIONAL_NUMBERING_PLAN_ISDN; |
639 | } else { | 792 | } else { |
640 | /*char is not number. It must be alphanumeric*/ | 793 | /*char is not number. It must be alphanumeric*/ |
641 | if (!isdigit(buffer[i])) format=NUMBER_ALPHANUMERIC; | 794 | if (!isdigit(buffer[i])) format=NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN; |
642 | } | 795 | } |
643 | } | 796 | } |
644 | 797 | ||
645 | /** | 798 | /** |
646 | * First byte is used for saving type of number. See GSM 03.40 | 799 | * First byte is used for saving type of number. See GSM 03.40 |
647 | * section 9.1.2.5 | 800 | * section 9.1.2.5 |
648 | */ | 801 | */ |
649 | Output[0]=format; | 802 | Output[0]=format; |
650 | 803 | ||
651 | /* After number type we will have number. GSM 03.40 section 9.1.2 */ | 804 | /* After number type we will have number. GSM 03.40 section 9.1.2 */ |
652 | switch (format) { | 805 | switch (format) { |
653 | case NUMBER_ALPHANUMERIC: | 806 | case NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN: |
654 | length=GSM_PackSevenBitsToEight(0, buffer, Output+1, strlen(buffer))*2; | 807 | length=GSM_PackSevenBitsToEight(0, buffer, Output+1, strlen(buffer))*2; |
655 | if (strlen(buffer)==7) length--; | 808 | if (strlen(buffer)==7) length--; |
656 | break; | 809 | break; |
657 | case NUMBER_INTERNATIONAL: | 810 | case NUMBER_INTERNATIONAL_NUMBERING_PLAN_ISDN: |
658 | length--; | 811 | length--; |
659 | EncodeBCD (Output+1, buffer+1, length, true); | 812 | EncodeBCD (Output+1, buffer+1, length, true); |
660 | break; | 813 | break; |
661 | default: | 814 | default: |
662 | EncodeBCD (Output+1, buffer, length, true); | 815 | EncodeBCD (Output+1, buffer, length, true); |
663 | break; | 816 | break; |
@@ -916,13 +1069,13 @@ void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *sr | |||
916 | bool mystrncasecmp(unsigned const char *a, unsigned const char *b, int num) | 1069 | bool mystrncasecmp(unsigned const char *a, unsigned const char *b, int num) |
917 | { | 1070 | { |
918 | int i; | 1071 | int i; |
919 | 1072 | ||
920 | if (a == NULL || b == NULL) return false; | 1073 | if (a == NULL || b == NULL) return false; |
921 | 1074 | ||
922 | num--; | 1075 | if (num == 0) num = -1; |
923 | 1076 | ||
924 | for (i = 0; i != num; i++) { | 1077 | for (i = 0; i != num; i++) { |
925 | if (a[i] == 0x00 && b[i] == 0x00) return true; | 1078 | if (a[i] == 0x00 && b[i] == 0x00) return true; |
926 | if (a[i] == 0x00 || b[i] == 0x00) return false; | 1079 | if (a[i] == 0x00 || b[i] == 0x00) return false; |
927 | if (tolower(a[i]) != tolower(b[i])) return false; | 1080 | if (tolower(a[i]) != tolower(b[i])) return false; |
928 | } | 1081 | } |
@@ -936,13 +1089,13 @@ bool mywstrncasecmp(unsigned const char *a, unsigned const char *b, int num) | |||
936 | { | 1089 | { |
937 | int i; | 1090 | int i; |
938 | wchar_t wc,wc2; | 1091 | wchar_t wc,wc2; |
939 | 1092 | ||
940 | if (a == NULL || b == NULL) return false; | 1093 | if (a == NULL || b == NULL) return false; |
941 | 1094 | ||
942 | num--; | 1095 | if (num == 0) num = -1; |
943 | 1096 | ||
944 | for (i = 0; i != num; i++) { | 1097 | for (i = 0; i != num; i++) { |
945 | if ((a[i*2] == 0x00 && a[i*2+1] == 0x00) && (b[i*2] == 0x00 && b[i*2+1] == 0x00)) return true; | 1098 | if ((a[i*2] == 0x00 && a[i*2+1] == 0x00) && (b[i*2] == 0x00 && b[i*2+1] == 0x00)) return true; |
946 | if ((a[i*2] == 0x00 && a[i*2+1] == 0x00) || (b[i*2] == 0x00 && b[i*2+1] == 0x00)) return false; | 1099 | if ((a[i*2] == 0x00 && a[i*2+1] == 0x00) || (b[i*2] == 0x00 && b[i*2+1] == 0x00)) return false; |
947 | wc = a[i*2+1] | (a[i*2] << 8); | 1100 | wc = a[i*2+1] | (a[i*2] << 8); |
948 | wc2 = b[i*2+1] | (b[i*2] << 8); | 1101 | wc2 = b[i*2+1] | (b[i*2] << 8); |
@@ -1012,13 +1165,13 @@ int mytowlower(wchar_t c) | |||
1012 | * fastest implementation of strstr() in C. | 1165 | * fastest implementation of strstr() in C. |
1013 | * I deliberately chose not to comment it. You should have at least | 1166 | * I deliberately chose not to comment it. You should have at least |
1014 | * as much fun trying to understand it, as I had to write it :-). | 1167 | * as much fun trying to understand it, as I had to write it :-). |
1015 | * | 1168 | * |
1016 | * Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */ | 1169 | * Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */ |
1017 | 1170 | ||
1018 | unsigned char *mystrstr (const unsigned char *haystack, const unsigned char *needle) | 1171 | unsigned char *mywstrstr (const unsigned char *haystack, const unsigned char *needle) |
1019 | { | 1172 | { |
1020 | /* One crazy define to convert unicode used in Gammu to standard wchar_t */ | 1173 | /* One crazy define to convert unicode used in Gammu to standard wchar_t */ |
1021 | #define tolowerwchar(x) (mytowlower((wchar_t)( (((&(x))[0] & 0xff) << 8) | (((&(x))[1] & 0xff)) ))) | 1174 | #define tolowerwchar(x) (mytowlower((wchar_t)( (((&(x))[0] & 0xff) << 8) | (((&(x))[1] & 0xff)) ))) |
1022 | register wchar_t b, c; | 1175 | register wchar_t b, c; |
1023 | 1176 | ||
1024 | if ((b = tolowerwchar(*needle)) != L'\0') { | 1177 | if ((b = tolowerwchar(*needle)) != L'\0') { |
diff --git a/gammu/emb/common/misc/coding/coding.h b/gammu/emb/common/misc/coding/coding.h index d0c334d..4cf0038 100644 --- a/gammu/emb/common/misc/coding/coding.h +++ b/gammu/emb/common/misc/coding/coding.h | |||
@@ -1,22 +1,26 @@ | |||
1 | /* (c) 2002-2004 by Marcin Wiacek and others */ | 1 | /* (c) 2002-2004 by Marcin Wiacek and others */ |
2 | 2 | ||
3 | #ifndef __coding_h | 3 | #ifndef __coding_h |
4 | #define __coding_h | 4 | #define __coding_h |
5 | 5 | ||
6 | #if defined(_MSC_VER) && defined(__cplusplus) | ||
7 | extern "C" { | ||
8 | #endif | ||
9 | |||
6 | #include <stdlib.h> | 10 | #include <stdlib.h> |
7 | 11 | ||
8 | #include "../misc.h" | 12 | #include "../misc.h" |
9 | 13 | ||
10 | #ifdef __OpenBSD__ | 14 | #ifdef __OpenBSD__ |
11 | typedef int wint_t; | 15 | typedef int wint_t; |
12 | #endif | 16 | #endif |
13 | 17 | ||
14 | /* ---------------------------- Unicode ------------------------------------ */ | 18 | /* ---------------------------- Unicode ------------------------------------ */ |
15 | bool mywstrncasecmp (unsigned const char *a, unsigned const char *b, int num); | 19 | bool mywstrncasecmp (unsigned const char *a, unsigned const char *b, int num); |
16 | unsigned char *mystrstr (unsigned const char *haystack, unsigned const char *needle); | 20 | unsigned char *mywstrstr (unsigned const char *haystack, unsigned const char *needle); |
17 | bool mywstrncmp (unsigned const char *a, unsigned const char *b, int num); | 21 | bool mywstrncmp (unsigned const char *a, unsigned const char *b, int num); |
18 | bool myiswspace (unsigned const char *src); | 22 | bool myiswspace (unsigned const char *src); |
19 | int mytowlower (wchar_t c); | 23 | int mytowlower (wchar_t c); |
20 | 24 | ||
21 | unsigned int EncodeWithUnicodeAlphabet(const unsigned char *value, wchar_t *dest); | 25 | unsigned int EncodeWithUnicodeAlphabet(const unsigned char *value, wchar_t *dest); |
22 | unsigned int DecodeWithUnicodeAlphabet(wchar_t value, unsigned char *dest); | 26 | unsigned int DecodeWithUnicodeAlphabet(wchar_t value, unsigned char *dest); |
@@ -32,12 +36,15 @@ void ReverseUnicodeString (unsigned char *String); | |||
32 | 36 | ||
33 | void ReadUnicodeFile (unsigned char *Dest, unsigned char *Source); | 37 | void ReadUnicodeFile (unsigned char *Dest, unsigned char *Source); |
34 | 38 | ||
35 | void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len); | 39 | void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len); |
36 | void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len); | 40 | void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len); |
37 | 41 | ||
42 | char *EncodeUnicodeSpecialChars(unsigned char *buffer); | ||
43 | char *DecodeUnicodeSpecialChars(unsigned char *buffer); | ||
44 | |||
38 | /* ------------------------------- BCD ------------------------------------- */ | 45 | /* ------------------------------- BCD ------------------------------------- */ |
39 | unsigned char EncodeWithBCDAlphabet (int value); | 46 | unsigned char EncodeWithBCDAlphabet (int value); |
40 | int DecodeWithBCDAlphabet (unsigned char value); | 47 | int DecodeWithBCDAlphabet (unsigned char value); |
41 | 48 | ||
42 | void DecodeBCD (unsigned char *dest, const unsigned char *src, int len); | 49 | void DecodeBCD (unsigned char *dest, const unsigned char *src, int len); |
43 | void EncodeBCD (unsigned char *dest, const unsigned char *src, int len, bool fill); | 50 | void EncodeBCD (unsigned char *dest, const unsigned char *src, int len, bool fill); |
@@ -83,21 +90,21 @@ int GSM_UnpackEightBitsToSeven (int offset, int in_length, int out_length, | |||
83 | * specified in GSM 03.40 section 9.1.2.5 | 90 | * specified in GSM 03.40 section 9.1.2.5 |
84 | */ | 91 | */ |
85 | typedef enum { | 92 | typedef enum { |
86 | /** | 93 | /** |
87 | * Unknown number type | 94 | * Unknown number type |
88 | */ | 95 | */ |
89 | NUMBER_UNKNOWN = 0x81, | 96 | NUMBER_UNKNOWN_NUMBERING_PLAN_ISDN = 0x81, |
90 | /** | 97 | /** |
91 | * International number (full number with code of country) | 98 | * International number (full number with code of country) |
92 | */ | 99 | */ |
93 | NUMBER_INTERNATIONAL= 0x91, | 100 | NUMBER_INTERNATIONAL_NUMBERING_PLAN_ISDN= 0x91, |
94 | /** | 101 | /** |
95 | * Alphanumeric number (with chars too) | 102 | * Alphanumeric number (with chars too) |
96 | */ | 103 | */ |
97 | NUMBER_ALPHANUMERIC= 0xD0 | 104 | NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN= 0xD0 |
98 | 105 | ||
99 | /* specification give also other values */ | 106 | /* specification give also other values */ |
100 | } GSM_NumberType; | 107 | } GSM_NumberType; |
101 | 108 | ||
102 | void GSM_UnpackSemiOctetNumber(unsigned char *retval, unsigned char *Number, bool semioctet); | 109 | void GSM_UnpackSemiOctetNumber(unsigned char *retval, unsigned char *Number, bool semioctet); |
103 | int GSM_PackSemiOctetNumber (unsigned char *Number, unsigned char *Output, bool semioctet); | 110 | int GSM_PackSemiOctetNumber (unsigned char *Number, unsigned char *Output, bool semioctet); |
@@ -119,15 +126,23 @@ int SetBit (unsigned char *Buffer, int BitNum); | |||
119 | int ClearBit (unsigned char *Buffer, int BitNum); | 126 | int ClearBit (unsigned char *Buffer, int BitNum); |
120 | 127 | ||
121 | /* ---------------------------- Other -------------------------------------- */ | 128 | /* ---------------------------- Other -------------------------------------- */ |
122 | 129 | ||
123 | void StringToDouble(char *text, double *d); | 130 | void StringToDouble(char *text, double *d); |
124 | 131 | ||
125 | bool mystrncasecmp (unsigned const char *a, unsigned const char *b, int num); | 132 | bool mystrncasecmp (unsigned const char *a, unsigned const char *b, int num); |
133 | char *mystrcasestr (unsigned const char *a, unsigned const char *b); | ||
126 | 134 | ||
127 | void MyGetLine(unsigned char *Buffer, int *Pos, unsigned char *OutBuffer, int MaxLen); | 135 | void MyGetLine (unsigned char *Buffer, int *Pos, unsigned char *OutBuffer, int MaxLen); |
136 | |||
137 | char *EncodeSpecialChars(unsigned char *buffer); | ||
138 | char *DecodeSpecialChars(unsigned char *buffer); | ||
139 | |||
140 | #if defined(_MSC_VER) && defined(__cplusplus) | ||
141 | } | ||
142 | #endif | ||
128 | 143 | ||
129 | #endif | 144 | #endif |
130 | 145 | ||
131 | /* How should editor hadle tabs in this file? Add editor commands here. | 146 | /* How should editor hadle tabs in this file? Add editor commands here. |
132 | * vim: noexpandtab sw=8 ts=8 sts=8: | 147 | * vim: noexpandtab sw=8 ts=8 sts=8: |
133 | */ | 148 | */ |
diff --git a/gammu/emb/common/misc/coding/md5.c b/gammu/emb/common/misc/coding/md5.c index 30fe33f..abb61be 100644 --- a/gammu/emb/common/misc/coding/md5.c +++ b/gammu/emb/common/misc/coding/md5.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* Taken from ReHash (see http://www.reichlsoft.de.vu/) and released | 1 | /* Taken from ReHash (www.reichlsoft.de.vu) and released |
2 | * under GPL/LGPL with permission from ReHash author | 2 | * under GPL/LGPL with permission from ReHash author |
3 | * Dominik Reichl <dominik.reichl@t-online.de>, Germany | 3 | * Dominik Reichl <dominik.reichl@t-online.de>, Germany |
4 | */ | 4 | */ |
5 | 5 | ||
6 | /* | 6 | /* |
7 | ********************************************************************** | 7 | ********************************************************************** |
diff --git a/gammu/emb/common/misc/misc.c b/gammu/emb/common/misc/misc.c index c2f09e4..7227e7b 100644 --- a/gammu/emb/common/misc/misc.c +++ b/gammu/emb/common/misc/misc.c | |||
@@ -8,12 +8,15 @@ | |||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <locale.h> | 9 | #include <locale.h> |
10 | #include <sys/timeb.h> | 10 | #include <sys/timeb.h> |
11 | #ifdef WIN32 | 11 | #ifdef WIN32 |
12 | # include "windows.h" | 12 | # include "windows.h" |
13 | #endif | 13 | #endif |
14 | #if defined(linux) || defined(__linux) || defined(__linux__) | ||
15 | # include <sys/utsname.h> | ||
16 | #endif | ||
14 | 17 | ||
15 | #include "../gsmstate.h" | 18 | #include "../gsmstate.h" |
16 | #include "misc.h" | 19 | #include "misc.h" |
17 | 20 | ||
18 | /* Based on article in Polish PC-Kurier 8/1998 page 104 | 21 | /* Based on article in Polish PC-Kurier 8/1998 page 104 |
19 | * Archive on http://www.pckurier.pl | 22 | * Archive on http://www.pckurier.pl |
@@ -227,17 +230,19 @@ char *OSDate (GSM_DateTime dt) | |||
227 | #endif | 230 | #endif |
228 | 231 | ||
229 | return retval2; | 232 | return retval2; |
230 | } | 233 | } |
231 | 234 | ||
232 | bool CheckDate(GSM_DateTime *date) | 235 | bool CheckDate(GSM_DateTime *date) |
233 | { | 236 | { |
234 | /* FIXME: This could also check if day is correct for selected month */ | 237 | const unsigned int days[]={31,29,31,30,31,30,31,31,30,31,30,31}; |
238 | |||
239 | /* FIXME: This could also check for leap years */ | ||
235 | return date->Year != 0 && | 240 | return date->Year != 0 && |
236 | date->Month >= 1 && date->Month <= 12 && | 241 | date->Month >= 1 && date->Month <= 12 && |
237 | date->Day >= 1 && date->Day <= 31; | 242 | date->Day >= 1 && date->Day <= days[date->Month]; |
238 | } | 243 | } |
239 | 244 | ||
240 | bool CheckTime(GSM_DateTime *date) | 245 | bool CheckTime(GSM_DateTime *date) |
241 | { | 246 | { |
242 | return date->Hour <= 23 && date->Hour >= 0 && | 247 | return date->Hour <= 23 && date->Hour >= 0 && |
243 | date->Minute <= 59 && date->Minute >= 0 && | 248 | date->Minute <= 59 && date->Minute >= 0 && |
@@ -448,12 +453,15 @@ void DumpMessage(FILE *df, Debug_Level dl, const unsigned char *message, int mes | |||
448 | char *GetOS(void) | 453 | char *GetOS(void) |
449 | { | 454 | { |
450 | #ifdef WIN32 | 455 | #ifdef WIN32 |
451 | OSVERSIONINFOEX Ver; | 456 | OSVERSIONINFOEX Ver; |
452 | bool Extended = true; | 457 | bool Extended = true; |
453 | #endif | 458 | #endif |
459 | #if defined(linux) || defined(__linux) || defined(__linux__) | ||
460 | struct utsnameVer; | ||
461 | #endif | ||
454 | static char Buffer[100] = {0x00}; | 462 | static char Buffer[100] = {0x00}; |
455 | 463 | ||
456 | #ifdef WIN32 | 464 | #ifdef WIN32 |
457 | memset(&Ver,sizeof(OSVERSIONINFOEX),0); | 465 | memset(&Ver,sizeof(OSVERSIONINFOEX),0); |
458 | Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); | 466 | Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
459 | 467 | ||
@@ -517,13 +525,14 @@ char *GetOS(void) | |||
517 | } | 525 | } |
518 | 526 | ||
519 | if (Extended && Ver.wServicePackMajor != 0) { | 527 | if (Extended && Ver.wServicePackMajor != 0) { |
520 | sprintf(Buffer+strlen(Buffer)," SP%i",Ver.wServicePackMajor); | 528 | sprintf(Buffer+strlen(Buffer)," SP%i",Ver.wServicePackMajor); |
521 | } | 529 | } |
522 | #elif defined(linux) || defined(__linux) || defined(__linux__) | 530 | #elif defined(linux) || defined(__linux) || defined(__linux__) |
523 | sprintf(Buffer, "Linux"); | 531 | uname(&Ver); |
532 | sprintf(Buffer, "Linux, kernel %s",Ver.release); | ||
524 | #elif defined(__FreeBSD__) | 533 | #elif defined(__FreeBSD__) |
525 | sprintf(Buffer, "FreeBSD"); | 534 | sprintf(Buffer, "FreeBSD"); |
526 | #elif defined(__NetBSD__) | 535 | #elif defined(__NetBSD__) |
527 | sprintf(Buffer, "NetBSD"); | 536 | sprintf(Buffer, "NetBSD"); |
528 | #elif defined(__OpenBSD__) | 537 | #elif defined(__OpenBSD__) |
529 | sprintf(Buffer, "OpenBSD"); | 538 | sprintf(Buffer, "OpenBSD"); |
diff --git a/gammu/emb/common/misc/misc.h b/gammu/emb/common/misc/misc.h index 8b46170..c461001 100644 --- a/gammu/emb/common/misc/misc.h +++ b/gammu/emb/common/misc/misc.h | |||
@@ -1,11 +1,15 @@ | |||
1 | /* (c) 2002-2004 by Marcin Wiacek */ | 1 | /* (c) 2002-2004 by Marcin Wiacek */ |
2 | 2 | ||
3 | #ifndef __misc_h | 3 | #ifndef __misc_h |
4 | #define __misc_h | 4 | #define __misc_h |
5 | 5 | ||
6 | #if defined(_MSC_VER) && defined(__cplusplus) | ||
7 | extern "C" { | ||
8 | #endif | ||
9 | |||
6 | #include <stdio.h> | 10 | #include <stdio.h> |
7 | #include <time.h> | 11 | #include <time.h> |
8 | #ifdef WIN32 | 12 | #ifdef WIN32 |
9 | # include <windows.h> | 13 | # include <windows.h> |
10 | #endif | 14 | #endif |
11 | 15 | ||
@@ -127,11 +131,15 @@ void Fill_GSM_DateTime (GSM_DateTime *Date, time_t timet); | |||
127 | bool CheckDate (GSM_DateTime *date); | 131 | bool CheckDate (GSM_DateTime *date); |
128 | bool CheckTime (GSM_DateTime *date); | 132 | bool CheckTime (GSM_DateTime *date); |
129 | 133 | ||
130 | char *GetCompiler(void); | 134 | char *GetCompiler(void); |
131 | char *GetOS(void); | 135 | char *GetOS(void); |
132 | 136 | ||
137 | #if defined(_MSC_VER) && defined(__cplusplus) | ||
138 | } | ||
139 | #endif | ||
140 | |||
133 | #endif | 141 | #endif |
134 | 142 | ||
135 | /* How should editor hadle tabs in this file? Add editor commands here. | 143 | /* How should editor hadle tabs in this file? Add editor commands here. |
136 | * vim: noexpandtab sw=8 ts=8 sts=8: | 144 | * vim: noexpandtab sw=8 ts=8 sts=8: |
137 | */ | 145 | */ |