summaryrefslogtreecommitdiffabout
path: root/gammu/emb/common/misc
Unidiff
Diffstat (limited to 'gammu/emb/common/misc') (more/less context) (show whitespace changes)
-rw-r--r--gammu/emb/common/misc/coding/coding.c177
-rw-r--r--gammu/emb/common/misc/coding/coding.h23
-rw-r--r--gammu/emb/common/misc/coding/md5.c2
-rw-r--r--gammu/emb/common/misc/misc.c15
-rw-r--r--gammu/emb/common/misc/misc.h8
5 files changed, 205 insertions, 20 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,42 +1,195 @@
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>
9#ifndef __OpenBSD__ 13#ifndef __OpenBSD__
10# include <wctype.h> 14# include <wctype.h>
11#endif 15#endif
12#ifdef WIN32 16#ifdef WIN32
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 */
24char *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 */
64char *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
92char *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
131char *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
159char *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
19unsigned int UnicodeLength(const unsigned char *str) 172unsigned 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
25 while(str[len*2] != 0 || str[len*2+1] != 0) len++; 178 while(str[len*2] != 0 || str[len*2+1] != 0) len++;
26 179
27 return len; 180 return len;
28} 181}
29 182
30/* Convert Unicode char saved in src to dest */ 183/* Convert Unicode char saved in src to dest */
31unsigned int EncodeWithUnicodeAlphabet(const unsigned char *src, wchar_t *dest) 184unsigned int EncodeWithUnicodeAlphabet(const unsigned char *src, wchar_t *dest)
32{ 185{
33 char retval; 186 char retval;
34 187
35 switch (retval = mbtowc(dest, src, MB_CUR_MAX)) { 188 switch (retval = mbtowc(dest, src, MB_CUR_MAX)) {
36 case -1 : 189 case -1 :
37 case 0 : return 1; 190 case 0 : return 1;
38 default : return retval; 191 default : return retval;
39 } 192 }
40} 193}
41 194
42/* Convert Unicode char saved in src to dest */ 195/* Convert Unicode char saved in src to dest */
@@ -565,117 +718,117 @@ int GSM_PackSevenBitsToEight(int offset, unsigned char *input, unsigned char *ou
565 if (Bits == -1) Bits = 7; else OUTPUT++; 718 if (Bits == -1) Bits = 7; else OUTPUT++;
566 719
567 INPUT++; 720 INPUT++;
568 } 721 }
569 return (OUTPUT - output); 722 return (OUTPUT - output);
570#else 723#else
571 return 0; 724 return 0;
572#endif 725#endif
573} 726}
574 727
575void GSM_UnpackSemiOctetNumber(unsigned char *retval, unsigned char *Number, bool semioctet) 728void GSM_UnpackSemiOctetNumber(unsigned char *retval, unsigned char *Number, bool semioctet)
576{ 729{
577 unsigned char Buffer[50]= ""; 730 unsigned char Buffer[50]= "";
578 int length = Number[0]; 731 int length = Number[0];
579 732
580 if (semioctet) { 733 if (semioctet) {
581 /* Convert number of semioctets to number of chars */ 734 /* Convert number of semioctets to number of chars */
582 if (length % 2) length++; 735 if (length % 2) length++;
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]);
603 DecodeBCD (Buffer, Number+2, length); 756 DecodeBCD (Buffer, Number+2, length);
604 break; 757 break;
605 } 758 }
606 759
607 EncodeUnicode(retval,Buffer,strlen(Buffer)); 760 EncodeUnicode(retval,Buffer,strlen(Buffer));
608} 761}
609 762
610/** 763/**
611 * Packing some phone numbers (SMSC, SMS destination and others) 764 * Packing some phone numbers (SMSC, SMS destination and others)
612 * 765 *
613 * See GSM 03.40 9.1.1: 766 * See GSM 03.40 9.1.1:
614 * 1 byte - length of number given in semioctets or bytes (when given in 767 * 1 byte - length of number given in semioctets or bytes (when given in
615 * bytes, includes one byte for byte with number format). 768 * bytes, includes one byte for byte with number format).
616 * Returned by function (set semioctet to true, if want result 769 * Returned by function (set semioctet to true, if want result
617 * in semioctets). 770 * in semioctets).
618 * 1 byte - format of number (see GSM_NumberType in coding.h). Returned 771 * 1 byte - format of number (see GSM_NumberType in coding.h). Returned
619 * in unsigned char *Output. 772 * in unsigned char *Output.
620 * n bytes - 2n or 2n-1 semioctets with number. Returned in unsigned char 773 * n bytes - 2n or 2n-1 semioctets with number. Returned in unsigned char
621 * *Output. 774 * *Output.
622 * 775 *
623 * 1 semioctet = 4 bits = half of byte 776 * 1 semioctet = 4 bits = half of byte
624 */ 777 */
625int GSM_PackSemiOctetNumber(unsigned char *Number, unsigned char *Output, bool semioctet) 778int GSM_PackSemiOctetNumber(unsigned char *Number, unsigned char *Output, bool semioctet)
626{ 779{
627 unsigned charformat, buffer[50]; 780 unsigned charformat, buffer[50];
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;
664 } 817 }
665 818
666 if (semioctet) return length; 819 if (semioctet) return length;
667 820
668 /* Convert number of semioctets to number of chars */ 821 /* Convert number of semioctets to number of chars */
669 if (length % 2) length++; 822 if (length % 2) length++;
670 return length / 2 + 1; 823 return length / 2 + 1;
671} 824}
672 825
673void CopyUnicodeString(unsigned char *Dest, unsigned char *Source) 826void CopyUnicodeString(unsigned char *Dest, unsigned char *Source)
674{ 827{
675 int j = 0; 828 int j = 0;
676 829
677 while (Source[j]!=0x00 || Source[j+1]!=0x00) { 830 while (Source[j]!=0x00 || Source[j+1]!=0x00) {
678 Dest[j] = Source[j]; 831 Dest[j] = Source[j];
679 Dest[j+1]= Source[j+1]; 832 Dest[j+1]= Source[j+1];
680 j=j+2; 833 j=j+2;
681 } 834 }
@@ -898,69 +1051,69 @@ void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *sr
898 dest[current++] = '~'; 1051 dest[current++] = '~';
899 dest[current++] = 0x00; 1052 dest[current++] = 0x00;
900 dest[current++] = '~'; 1053 dest[current++] = '~';
901 break; 1054 break;
902 default: 1055 default:
903 dest[current++] = src[i*2]; 1056 dest[current++] = src[i*2];
904 dest[current++] = src[i*2+1]; 1057 dest[current++] = src[i*2+1];
905 } 1058 }
906 break; 1059 break;
907 default: 1060 default:
908 dest[current++] = src[i*2]; 1061 dest[current++] = src[i*2];
909 dest[current++] = src[i*2+1]; 1062 dest[current++] = src[i*2+1];
910 } 1063 }
911 } 1064 }
912 dest[current++] = 0x00; 1065 dest[current++] = 0x00;
913 dest[current++] = 0x00; 1066 dest[current++] = 0x00;
914} 1067}
915 1068
916bool mystrncasecmp(unsigned const char *a, unsigned const char *b, int num) 1069bool 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 }
929 return true; 1082 return true;
930} 1083}
931 1084
932/* Compares two Unicode strings without regarding to case. 1085/* Compares two Unicode strings without regarding to case.
933 * Return true, when they're equal 1086 * Return true, when they're equal
934 */ 1087 */
935bool mywstrncasecmp(unsigned const char *a, unsigned const char *b, int num) 1088bool 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);
949 if (mytowlower(wc) != mytowlower(wc2)) return false; 1102 if (mytowlower(wc) != mytowlower(wc2)) return false;
950 } 1103 }
951 return true; 1104 return true;
952} 1105}
953 1106
954/* wcscmp in Mandrake 9.0 is wrong */ 1107/* wcscmp in Mandrake 9.0 is wrong */
955bool mywstrncmp(unsigned const char *a, unsigned const char *b, int num) 1108bool mywstrncmp(unsigned const char *a, unsigned const char *b, int num)
956{ 1109{
957 int i=0; 1110 int i=0;
958 1111
959 while (1) { 1112 while (1) {
960 if (a[i*2] != b[i*2] || a[i*2+1] != b[i*2+1]) return false; 1113 if (a[i*2] != b[i*2] || a[i*2+1] != b[i*2+1]) return false;
961 if (a[i*2] == 0x00 && a[i*2+1] == 0x00) return true; 1114 if (a[i*2] == 0x00 && a[i*2+1] == 0x00) return true;
962 i++; 1115 i++;
963 if (num == i) return true; 1116 if (num == i) return true;
964 } 1117 }
965} 1118}
966 1119
@@ -994,49 +1147,49 @@ int mytowlower(wchar_t c)
994 unsigned char dest[10]; 1147 unsigned char dest[10];
995 1148
996 DecodeWithUnicodeAlphabet(c, dest); 1149 DecodeWithUnicodeAlphabet(c, dest);
997 return tolower(dest[0]); 1150 return tolower(dest[0]);
998#else 1151#else
999 return towlower(c); 1152 return towlower(c);
1000#endif 1153#endif
1001} 1154}
1002 1155
1003/* 1156/*
1004 * Following code is based on wcsstr from the GNU C Library, original 1157 * Following code is based on wcsstr from the GNU C Library, original
1005 * comment follows: 1158 * comment follows:
1006 */ 1159 */
1007/* 1160/*
1008 * The original strstr() file contains the following comment: 1161 * The original strstr() file contains the following comment:
1009 * 1162 *
1010 * My personal strstr() implementation that beats most other algorithms. 1163 * My personal strstr() implementation that beats most other algorithms.
1011 * Until someone tells me otherwise, I assume that this is the 1164 * Until someone tells me otherwise, I assume that this is the
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
1018unsigned char *mystrstr (const unsigned char *haystack, const unsigned char *needle) 1171unsigned 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') {
1025 haystack -= 2; /* possible ANSI violation */ 1178 haystack -= 2; /* possible ANSI violation */
1026 do { 1179 do {
1027 haystack += 2; 1180 haystack += 2;
1028 if ((c = tolowerwchar(*haystack)) == L'\0') 1181 if ((c = tolowerwchar(*haystack)) == L'\0')
1029 goto ret0; 1182 goto ret0;
1030 } while (c != b); 1183 } while (c != b);
1031 1184
1032 needle += 2; 1185 needle += 2;
1033 if ((c = tolowerwchar(*needle)) == L'\0') 1186 if ((c = tolowerwchar(*needle)) == L'\0')
1034 goto foundneedle; 1187 goto foundneedle;
1035 needle += 2; 1188 needle += 2;
1036 goto jin; 1189 goto jin;
1037 1190
1038 for (;;) { 1191 for (;;) {
1039 register wchar_t a; 1192 register wchar_t a;
1040 register const unsigned char *rhaystack, *rneedle; 1193 register const unsigned char *rhaystack, *rneedle;
1041 1194
1042 do { 1195 do {
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,61 +1,68 @@
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);
23 27
24 unsigned int UnicodeLength (const unsigned char *str); 28 unsigned int UnicodeLength (const unsigned char *str);
25 unsigned char *DecodeUnicodeString (const unsigned char *src); 29 unsigned char *DecodeUnicodeString (const unsigned char *src);
26 unsigned char *DecodeUnicodeConsole (const unsigned char *src); 30 unsigned char *DecodeUnicodeConsole (const unsigned char *src);
27 void DecodeUnicode (const unsigned char *src, unsigned char *dest); 31 void DecodeUnicode (const unsigned char *src, unsigned char *dest);
28 void EncodeUnicode (unsigned char *dest, const unsigned char *src, int len); 32 void EncodeUnicode (unsigned char *dest, const unsigned char *src, int len);
29 33
30 void CopyUnicodeString (unsigned char *Dest, unsigned char *Source); 34 void CopyUnicodeString (unsigned char *Dest, unsigned char *Source);
31 void ReverseUnicodeString (unsigned char *String); 35 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);
44 51
45/* ------------------------------ UTF7 ------------------------------------- */ 52/* ------------------------------ UTF7 ------------------------------------- */
46 void DecodeUTF7 (unsigned char *dest, const unsigned char *src, int len); 53 void DecodeUTF7 (unsigned char *dest, const unsigned char *src, int len);
47 54
48/* ------------------------------ UTF8 ------------------------------------- */ 55/* ------------------------------ UTF8 ------------------------------------- */
49 wchar_t DecodeWithUTF8Alphabet (unsigned char mychar3, unsigned char mychar4); 56 wchar_t DecodeWithUTF8Alphabet (unsigned char mychar3, unsigned char mychar4);
50 bool EncodeWithUTF8Alphabet (unsigned char mychar1, unsigned char mychar2, unsigned char *ret1, unsigned char *ret2); 57 bool EncodeWithUTF8Alphabet (unsigned char mychar1, unsigned char mychar2, unsigned char *ret1, unsigned char *ret2);
51 58
52 bool EncodeUTF8QuotedPrintable(unsigned char *dest, const unsigned char *src); 59 bool EncodeUTF8QuotedPrintable(unsigned char *dest, const unsigned char *src);
53 void DecodeUTF8QuotedPrintable(unsigned char *dest, const unsigned char *src, int len); 60 void DecodeUTF8QuotedPrintable(unsigned char *dest, const unsigned char *src, int len);
54 61
55 bool EncodeUTF8 (unsigned char *dest, const unsigned char *src); 62 bool EncodeUTF8 (unsigned char *dest, const unsigned char *src);
56 void DecodeUTF8 (unsigned char *dest, const unsigned char *src, int len); 63 void DecodeUTF8 (unsigned char *dest, const unsigned char *src, int len);
57 64
58/* ------------------------------- BASE64 ---------------------------------- */ 65/* ------------------------------- BASE64 ---------------------------------- */
59 void EncodeBASE64 (const unsigned char *Input, unsigned char *Output, int Length); 66 void EncodeBASE64 (const unsigned char *Input, unsigned char *Output, int Length);
60 int DecodeBASE64 (const unsigned char *Input, unsigned char *Output, int Length); 67 int DecodeBASE64 (const unsigned char *Input, unsigned char *Output, int Length);
61 68
@@ -65,69 +72,77 @@ void EncodeHexBin (unsigned char *dest, const unsigned char *src, int len);
65 72
66/* ----------------------------- HexUnicode -------------------------------- */ 73/* ----------------------------- HexUnicode -------------------------------- */
67 void DecodeHexUnicode (unsigned char *dest, const unsigned char *src, int len); 74 void DecodeHexUnicode (unsigned char *dest, const unsigned char *src, int len);
68 void EncodeHexUnicode (unsigned char *dest, const unsigned char *src, int len); 75 void EncodeHexUnicode (unsigned char *dest, const unsigned char *src, int len);
69 76
70/* ---------------------- DefaultAlphabet for SMS -------------------------- */ 77/* ---------------------- DefaultAlphabet for SMS -------------------------- */
71 void EncodeDefault (unsigned char *dest, const unsigned char *src, int *len, bool UseExtensions, unsigned char *ExtraAlphabet); 78 void EncodeDefault (unsigned char *dest, const unsigned char *src, int *len, bool UseExtensions, unsigned char *ExtraAlphabet);
72 void DecodeDefault (unsigned char *dest, const unsigned char *src, int len, bool UseExtensions, unsigned char *ExtraAlphabet); 79 void DecodeDefault (unsigned char *dest, const unsigned char *src, int len, bool UseExtensions, unsigned char *ExtraAlphabet);
73 void FindDefaultAlphabetLen (const unsigned char *src, int *srclen, int *smslen, int maxlen); 80 void FindDefaultAlphabetLen (const unsigned char *src, int *srclen, int *smslen, int maxlen);
74 81
75 int GSM_PackSevenBitsToEight(int offset, unsigned char *input, unsigned char *output, int length); 82 int GSM_PackSevenBitsToEight(int offset, unsigned char *input, unsigned char *output, int length);
76 int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length, 83 int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length,
77 unsigned char *input, unsigned char *output); 84 unsigned char *input, unsigned char *output);
78 85
79/* ----------------- Phone numbers according to GSM specs ------------------ */ 86/* ----------------- Phone numbers according to GSM specs ------------------ */
80 87
81/** 88/**
82 * Enum to handle types of phones numbers like 89 * Enum to handle types of phones numbers like
83 * specified in GSM 03.40 section 9.1.2.5 90 * specified in GSM 03.40 section 9.1.2.5
84 */ 91 */
85typedef enum { 92typedef 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);
104 111
105/* ---------------------------- Bits --------------------------------------- */ 112/* ---------------------------- Bits --------------------------------------- */
106 113
107void BufferAlign (unsigned char *Destination, int *CurrentBit); 114void BufferAlign (unsigned char *Destination, int *CurrentBit);
108void BufferAlignNumber(int *CurrentBit); 115void BufferAlignNumber(int *CurrentBit);
109 116
110 void AddBuffer (unsigned char *Destination, int *CurrentBit, unsigned char *Source, int BitsToProcess); 117 void AddBuffer (unsigned char *Destination, int *CurrentBit, unsigned char *Source, int BitsToProcess);
111void AddBufferByte(unsigned char *Destination, int *CurrentBit, unsigned char Source, int BitsToProcess); 118void AddBufferByte(unsigned char *Destination, int *CurrentBit, unsigned char Source, int BitsToProcess);
112 119
113void GetBuffer (unsigned char *Source, int *CurrentBit, unsigned char *Destination, int BitsToProcess); 120void GetBuffer (unsigned char *Source, int *CurrentBit, unsigned char *Destination, int BitsToProcess);
114void GetBufferInt (unsigned char *Source, int *CurrentBit, int *integer, int BitsToProcess); 121void GetBufferInt (unsigned char *Source, int *CurrentBit, int *integer, int BitsToProcess);
115void GetBufferI (unsigned char *Source, int *CurrentBit, int *result, int BitsToProcess); 122void GetBufferI (unsigned char *Source, int *CurrentBit, int *result, int BitsToProcess);
116 123
117int GetBit (unsigned char *Buffer, int BitNum); 124int GetBit (unsigned char *Buffer, int BitNum);
118int SetBit (unsigned char *Buffer, int BitNum); 125int SetBit (unsigned char *Buffer, int BitNum);
119int ClearBit (unsigned char *Buffer, int BitNum); 126int 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
125bool mystrncasecmp (unsigned const char *a, unsigned const char *b, int num); 132bool mystrncasecmp (unsigned const char *a, unsigned const char *b, int num);
133 char *mystrcasestr (unsigned const char *a, unsigned const char *b);
126 134
127void MyGetLine(unsigned char *Buffer, int *Pos, unsigned char *OutBuffer, int MaxLen); 135void MyGetLine(unsigned char *Buffer, int *Pos, unsigned char *OutBuffer, int MaxLen);
128 136
137char *EncodeSpecialChars(unsigned char *buffer);
138char *DecodeSpecialChars(unsigned char *buffer);
139
140#if defined(_MSC_VER) && defined(__cplusplus)
141 }
142#endif
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,25 +1,25 @@
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 **********************************************************************
8 ** MD5.cpp ** 8 ** MD5.cpp **
9 ** ** 9 ** **
10 ** - Style modified by Tony Ray, January 2001 ** 10 ** - Style modified by Tony Ray, January 2001 **
11 ** Added support for randomizing initialization constants ** 11 ** Added support for randomizing initialization constants **
12 ** - Style modified by Dominik Reichl, April 2003 ** 12 ** - Style modified by Dominik Reichl, April 2003 **
13 ** Optimized code ** 13 ** Optimized code **
14 ** ** 14 ** **
15 ** MD5.c ** 15 ** MD5.c **
16 ** RSA Data Security, Inc. MD5 Message Digest Algorithm ** 16 ** RSA Data Security, Inc. MD5 Message Digest Algorithm **
17 ** Created: 2/17/90 RLR ** 17 ** Created: 2/17/90 RLR **
18 ** Revised: 1/91 SRD,AJ,BSK,JT Reference C Version ** 18 ** Revised: 1/91 SRD,AJ,BSK,JT Reference C Version **
19 ********************************************************************** 19 **********************************************************************
20 */ 20 */
21 21
22/* 22/*
23 ********************************************************************** 23 **********************************************************************
24 ** MD5.h -- Header file for implementation of MD5 ** 24 ** MD5.h -- Header file for implementation of MD5 **
25 ** RSA Data Security, Inc. MD5 Message Digest Algorithm ** 25 ** RSA Data Security, Inc. MD5 Message Digest Algorithm **
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
@@ -1,37 +1,40 @@
1/* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */ 1/* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */
2/* Checking used compiler (c) 2002 by Michal Cihar */ 2/* Checking used compiler (c) 2002 by Michal Cihar */
3 3
4#include <string.h> 4#include <string.h>
5#include <ctype.h> 5#include <ctype.h>
6#include <time.h> 6#include <time.h>
7#include <stdarg.h> 7#include <stdarg.h>
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
20 */ 23 */
21char *DayOfWeek (int year, int month, int day) 24char *DayOfWeek (int year, int month, int day)
22{ 25{
23 int p,q,r,w; 26 int p,q,r,w;
24 static char DayOfWeekChar[10]; 27 static char DayOfWeekChar[10];
25 28
26 p=(14-month) / 12; 29 p=(14-month) / 12;
27 q=month+12*p-2; 30 q=month+12*p-2;
28 r=year-p; 31 r=year-p;
29 w=(day+(31*q) / 12 + r + r / 4 - r / 100 + r / 400) % 7; 32 w=(day+(31*q) / 12 + r + r / 4 - r / 100 + r / 400) % 7;
30 strcpy(DayOfWeekChar,""); 33 strcpy(DayOfWeekChar,"");
31 switch (w) { 34 switch (w) {
32 case 0: strcpy(DayOfWeekChar,"Sun"); break; 35 case 0: strcpy(DayOfWeekChar,"Sun"); break;
33 case 1: strcpy(DayOfWeekChar,"Mon"); break; 36 case 1: strcpy(DayOfWeekChar,"Mon"); break;
34 case 2: strcpy(DayOfWeekChar,"Tue"); break; 37 case 2: strcpy(DayOfWeekChar,"Tue"); break;
35 case 3: strcpy(DayOfWeekChar,"Wed"); break; 38 case 3: strcpy(DayOfWeekChar,"Wed"); break;
36 case 4: strcpy(DayOfWeekChar,"Thu"); break; 39 case 4: strcpy(DayOfWeekChar,"Thu"); break;
37 case 5: strcpy(DayOfWeekChar,"Fri"); break; 40 case 5: strcpy(DayOfWeekChar,"Fri"); break;
@@ -210,52 +213,54 @@ char *OSDate (GSM_DateTime dt)
210#else 213#else
211 strftime(retval2, 200, "%x", &timeptr); 214 strftime(retval2, 200, "%x", &timeptr);
212#endif 215#endif
213 /* If don't have weekday name, include it */ 216 /* If don't have weekday name, include it */
214 strftime(retval, 200, "%A", &timeptr); 217 strftime(retval, 200, "%A", &timeptr);
215 if (strstr(retval2,retval)==NULL) { 218 if (strstr(retval2,retval)==NULL) {
216 /* Check also for short name */ 219 /* Check also for short name */
217 strftime(retval, 200, "%a", &timeptr); 220 strftime(retval, 200, "%a", &timeptr);
218 if (strstr(retval2,retval)==NULL) { 221 if (strstr(retval2,retval)==NULL) {
219 strcat(retval2," ("); 222 strcat(retval2," (");
220 strcat(retval2,retval); 223 strcat(retval2,retval);
221 strcat(retval2,")"); 224 strcat(retval2,")");
222 } 225 }
223 } 226 }
224 227
225#ifdef WIN32 228#ifdef WIN32
226 setlocale(LC_ALL, ".ACP"); 229 setlocale(LC_ALL, ".ACP");
227#endif 230#endif
228 231
229 return retval2; 232 return retval2;
230} 233}
231 234
232bool CheckDate(GSM_DateTime *date) 235bool 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
240bool CheckTime(GSM_DateTime *date) 245bool 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 &&
244 date->Second <= 59 && date->Second >= 0; 249 date->Second <= 59 && date->Second >= 0;
245} 250}
246 251
247int GetLine(FILE *File, char *Line, int count) 252int GetLine(FILE *File, char *Line, int count)
248{ 253{
249 int num; 254 int num;
250 255
251 if (fgets(Line, count, File) != NULL) { 256 if (fgets(Line, count, File) != NULL) {
252 num = strlen(Line) - 1; 257 num = strlen(Line) - 1;
253 while(1) { 258 while(1) {
254 if (Line[num] != '\n' && Line[num] != '\r') break; 259 if (Line[num] != '\n' && Line[num] != '\r') break;
255 if (num == 0) break; 260 if (num == 0) break;
256 Line[num--] = 0; 261 Line[num--] = 0;
257 } 262 }
258 return strlen(Line); 263 return strlen(Line);
259 } 264 }
260 return -1; 265 return -1;
261} 266}
@@ -430,48 +435,51 @@ void DumpMessage(FILE *df, Debug_Level dl, const unsigned char *message, int mes
430 if (j != len-1) buffer[j*4+2] = message[i]; 435 if (j != len-1) buffer[j*4+2] = message[i];
431 buffer[(len-1)*4+j+3] = message[i]; 436 buffer[(len-1)*4+j+3] = message[i];
432 } else { 437 } else {
433 buffer[(len-1)*4+j+3] = '.'; 438 buffer[(len-1)*4+j+3] = '.';
434 } 439 }
435 if (j != len-1 && i != messagesize-1) buffer[j*4+3] = '|'; 440 if (j != len-1 && i != messagesize-1) buffer[j*4+3] = '|';
436 if (j == len-1) { 441 if (j == len-1) {
437 smfprintf(df, dl, "%s\n", buffer); 442 smfprintf(df, dl, "%s\n", buffer);
438 memset(buffer,0x20,sizeof(buffer)); 443 memset(buffer,0x20,sizeof(buffer));
439 buffer[len*5-1]=0; 444 buffer[len*5-1]=0;
440 j = 0; 445 j = 0;
441 } else { 446 } else {
442 j++; 447 j++;
443 } 448 }
444 } 449 }
445 if (j != 0) smfprintf(df, dl, "%s\n", buffer); 450 if (j != 0) smfprintf(df, dl, "%s\n", buffer);
446} 451}
447 452
448char *GetOS(void) 453char *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
460 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) { 468 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
461 Extended = false; 469 Extended = false;
462 Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 470 Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
463 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) { 471 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
464//#ifdef _MSC_VER 472//#ifdef _MSC_VER
465 // Ver.dwMajorVersion = _winmajor; 473 // Ver.dwMajorVersion = _winmajor;
466 // Ver.dwMinorVersion = _winminor; 474 // Ver.dwMinorVersion = _winminor;
467 // Ver.dwBuildNumber = _osver; 475 // Ver.dwBuildNumber = _osver;
468//#else 476//#else
469 sprintf(Buffer, "Windows"); 477 sprintf(Buffer, "Windows");
470 return Buffer; 478 return Buffer;
471//#endif 479//#endif
472 } 480 }
473 } 481 }
474 482
475 /* ----------------- 9x family ------------------ */ 483 /* ----------------- 9x family ------------------ */
476 484
477 /* no info about Win95 SP1, Win95 OSR2.1, Win95 OSR2.5.... */ 485 /* no info about Win95 SP1, Win95 OSR2.1, Win95 OSR2.5.... */
@@ -499,49 +507,50 @@ char *GetOS(void)
499 507
500 } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 1 && Ver.dwBuildNumber == 2600) { 508 } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 1 && Ver.dwBuildNumber == 2600) {
501 sprintf(Buffer,"Win XP"); 509 sprintf(Buffer,"Win XP");
502#if _MSC_VER > 1200 //6.0 has it undeclared 510#if _MSC_VER > 1200 //6.0 has it undeclared
503 if (Extended) { 511 if (Extended) {
504 if (Ver.wSuiteMask & VER_SUITE_PERSONAL) { 512 if (Ver.wSuiteMask & VER_SUITE_PERSONAL) {
505 sprintf(Buffer+strlen(Buffer)," Home"); 513 sprintf(Buffer+strlen(Buffer)," Home");
506 } else { 514 } else {
507 sprintf(Buffer+strlen(Buffer)," Pro"); 515 sprintf(Buffer+strlen(Buffer)," Pro");
508 } 516 }
509 } 517 }
510#endif 518#endif
511 519
512 } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 2) { 520 } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 2) {
513 sprintf(Buffer,"Win 2003"); 521 sprintf(Buffer,"Win 2003");
514 522
515 } else { 523 } else {
516 sprintf(Buffer, "Windows %i.%i.%i",Ver.dwMajorVersion,Ver.dwMinorVersion,Ver.dwBuildNumber); 524 sprintf(Buffer, "Windows %i.%i.%i",Ver.dwMajorVersion,Ver.dwMinorVersion,Ver.dwBuildNumber);
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");
530#elif defined(__GNU__) 539#elif defined(__GNU__)
531 sprintf(Buffer, "GNU/Hurd"); 540 sprintf(Buffer, "GNU/Hurd");
532#elif defined(sun) || defined(__sun) || defined(__sun__) 541#elif defined(sun) || defined(__sun) || defined(__sun__)
533# ifdef __SVR4 542# ifdef __SVR4
534 sprintf(Buffer, "Sun Solaris"); 543 sprintf(Buffer, "Sun Solaris");
535# else 544# else
536 sprintf(Buffer, "SunOS"); 545 sprintf(Buffer, "SunOS");
537# endif 546# endif
538#elif defined(hpux) || defined(__hpux) || defined(__hpux__) 547#elif defined(hpux) || defined(__hpux) || defined(__hpux__)
539 sprintf(Buffer, "HP-UX"); 548 sprintf(Buffer, "HP-UX");
540#elif defined(ultrix) || defined(__ultrix) || defined(__ultrix__) 549#elif defined(ultrix) || defined(__ultrix) || defined(__ultrix__)
541 sprintf(Buffer, "DEC Ultrix"); 550 sprintf(Buffer, "DEC Ultrix");
542#elif defined(sgi) || defined(__sgi) 551#elif defined(sgi) || defined(__sgi)
543 sprintf(Buffer, "SGI Irix"); 552 sprintf(Buffer, "SGI Irix");
544#elif defined(__osf__) 553#elif defined(__osf__)
545 sprintf(Buffer, "OSF Unix"); 554 sprintf(Buffer, "OSF Unix");
546#elif defined(bsdi) || defined(__bsdi__) 555#elif defined(bsdi) || defined(__bsdi__)
547 sprintf(Buffer, "BSDI Unix"); 556 sprintf(Buffer, "BSDI Unix");
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,29 +1,33 @@
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
12#include "../config.h" 16#include "../config.h"
13 17
14#ifndef __cplusplus 18#ifndef __cplusplus
15#ifndef false 19#ifndef false
16# define false 0 20# define false 0
17#endif 21#endif
18#ifndef true 22#ifndef true
19 # define true !0 23 # define true !0
20#endif 24#endif
21#ifndef bool 25#ifndef bool
22 # define boolchar 26 # define boolchar
23#endif 27#endif
24#endif /* __cplusplus */ 28#endif /* __cplusplus */
25 29
26#ifdef WIN32 30#ifdef WIN32
27# define my_sleep(x) ((x)<1000 ? Sleep(1) : Sleep((x)/1000)) 31# define my_sleep(x) ((x)<1000 ? Sleep(1) : Sleep((x)/1000))
28#else 32#else
29# define my_sleep(x) usleep(x) 33# define my_sleep(x) usleep(x)
@@ -109,29 +113,33 @@ typedef struct {
109 unsigned int Day; 113 unsigned int Day;
110 /** 114 /**
111 * January = 1, February = 2, etc. 115 * January = 1, February = 2, etc.
112 */ 116 */
113 unsigned int Month; 117 unsigned int Month;
114 /** 118 /**
115 * Complete year number. Not 03, but 2003 119 * Complete year number. Not 03, but 2003
116 */ 120 */
117 unsigned int Year; 121 unsigned int Year;
118} GSM_DateTime; 122} GSM_DateTime;
119 123
120 void GSM_GetCurrentDateTime (GSM_DateTime *Date); 124 void GSM_GetCurrentDateTime (GSM_DateTime *Date);
121 char *OSDateTime (GSM_DateTime dt, bool TimeZone); 125 char *OSDateTime (GSM_DateTime dt, bool TimeZone);
122 char *OSDate (GSM_DateTime dt); 126 char *OSDate (GSM_DateTime dt);
123 char *DayOfWeek (int year, int month, int day); 127 char *DayOfWeek (int year, int month, int day);
124 time_t Fill_Time_T (GSM_DateTime DT, int TZ); 128 time_t Fill_Time_T (GSM_DateTime DT, int TZ);
125 void GetTimeDifference (unsigned long diff, GSM_DateTime *DT, bool Plus, int multi); 129 void GetTimeDifference (unsigned long diff, GSM_DateTime *DT, bool Plus, int multi);
126 void Fill_GSM_DateTime (GSM_DateTime *Date, time_t timet); 130 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 */