Gammu internals  1.38.0
backtext.c
Go to the documentation of this file.
1 /* (c) 2002-2005 by Marcin Wiacek, Walek and Michal Cihar */
2 
3 #include <string.h>
4 #include <ctype.h>
5 #include <stdlib.h>
6 
7 #include <gammu-config.h>
8 #include <gammu-inifile.h>
9 #include <gammu-backup.h>
10 #include <gammu-unicode.h>
11 
12 #include "../../service/gsmcal.h"
13 #include "../../service/gsmlogo.h"
14 #include "../../service/gsmmisc.h"
15 #include "../../misc/coding/coding.h"
16 #include "../../misc/coding/md5.h"
17 #include "../../misc/misc.h"
18 #include "../../debug.h"
19 #include "backtext.h"
20 
21 #include "../../../helper/string.h"
22 
23 #ifdef GSM_ENABLE_BACKUP
24 
28 #define chk_fwrite(data, size, count, file) \
29  if (fwrite(data, size, count, file) != count) goto fail;
30 
31 GSM_Error FindBackupChecksum(const char *FileName, gboolean UseUnicode, char *checksum)
32 {
33  INI_Section *file_info, *h;
34  INI_Entry *e;
35  char *buffer = NULL,buff[100]={0};
36  int len=0;
37  GSM_Error error;
38 
39  error = INI_ReadFile(FileName, UseUnicode, &file_info);
40  if (error != ERR_NONE) {
41  return error;
42  }
43 
44  if (UseUnicode) {
45  for (h = file_info; h != NULL; h = h->Next) {
46  EncodeUnicode(buff,"Checksum",8);
47  if (mywstrncasecmp(buff, h->SectionName, 8)) continue;
48 
49  buffer = (unsigned char *)realloc(buffer,len+UnicodeLength(h->SectionName)*2+2);
50  CopyUnicodeString(buffer+len,h->SectionName);
51  len+=UnicodeLength(h->SectionName)*2;
52 
53  for (e = h->SubEntries; e != NULL; e = e->Next) {
54  buffer = (unsigned char *)realloc(buffer,len+UnicodeLength(e->EntryName)*2+2);
55  CopyUnicodeString(buffer+len,e->EntryName);
56  len+=UnicodeLength(e->EntryName)*2;
57  buffer = (unsigned char *)realloc(buffer,len+UnicodeLength(e->EntryValue)*2+2);
58  CopyUnicodeString(buffer+len,e->EntryValue);
59  len+=UnicodeLength(e->EntryValue)*2;
60  }
61  }
62  } else {
63  for (h = file_info; h != NULL; h = h->Next) {
64  if (strncasecmp("Checksum", h->SectionName, 8) == 0) continue;
65 
66  buffer = (unsigned char *)realloc(buffer,len+strlen(h->SectionName)+1);
67  strcpy(buffer+len,h->SectionName);
68  len+=strlen(h->SectionName);
69 
70  for (e = h->SubEntries; e != NULL; e = e->Next) {
71  buffer = (unsigned char *)realloc(buffer,len+strlen(e->EntryName)+1);
72  strcpy(buffer+len,e->EntryName);
73  len+=strlen(e->EntryName);
74  buffer = (unsigned char *)realloc(buffer,len+strlen(e->EntryValue)+1);
75  strcpy(buffer+len,e->EntryValue);
76  len+=strlen(e->EntryValue);
77  }
78  }
79  }
80 
81  CalculateMD5(buffer, len, checksum);
82  free(buffer);
83  buffer=NULL;
84  INI_Free(file_info);
85  return ERR_NONE;
86 }
87 
88 static unsigned char *ReadCFGText(INI_Section *cfg, const unsigned char *section, const unsigned char *key, const gboolean Unicode)
89 {
90  unsigned char unicode_key[500],*retval;
91 
92  if (Unicode) {
93  EncodeUnicode(unicode_key,key,strlen(key));
94  retval = INI_GetValue(cfg,section,unicode_key,Unicode);
95  if (retval != NULL) return DecodeUnicodeString(retval);
96  return NULL;
97  } else {
98  return INI_GetValue(cfg,section,key,Unicode);
99  }
100 }
101 
102 static GSM_Error SaveLinkedBackupText(FILE *file, const char *myname, const char *myvalue, const gboolean UseUnicode)
103 {
104  int w,current;
105  unsigned char buffer2[1000],buffer3[1000];
106 
107  current = strlen(myvalue); w = 0;
108  while (TRUE) {
109  if (current > 200) {
110  memcpy(buffer2,myvalue+(strlen(myvalue)-current),200);
111  buffer2[200] = 0;
112  current = current - 200;
113  } else {
114  memcpy(buffer2,myvalue+(strlen(myvalue)-current),current);
115  buffer2[current] = 0;
116  current = 0;
117  }
118  if (UseUnicode) {
119  sprintf(buffer3,"%s%02i = %s%c%c",myname,w,buffer2,13,10);
120  EncodeUnicode(buffer2,buffer3,strlen(buffer3));
121  chk_fwrite(buffer2,1,strlen(buffer3)*2,file);
122  } else {
123  fprintf(file,"%s%02i = %s%c%c",myname,w,buffer2,13,10);
124  }
125  if (current == 0) break;
126  w++;
127  }
128  return ERR_NONE;
129 fail:
130  return ERR_WRITING_FILE;
131 }
132 
133 char *ReadLinkedBackupText(INI_Section *file_info, const char *section, const char *myname, const gboolean UseUnicode)
134 {
135  char buffer2[300];
136  char *readvalue;
137  int i;
138  char *result = NULL;
139  size_t len, cursize = 0, pos = 0;
140 
141  i=0;
142  while (TRUE) {
143  sprintf(buffer2, "%s%02i", myname, i);
144  readvalue = ReadCFGText(file_info, section, buffer2, UseUnicode);
145  if (readvalue == NULL) {
146  break;
147  }
148  len = strlen(readvalue);
149  if (pos + len + 1 >= cursize) {
150  cursize += len + 100;
151  result = (char *)realloc(result, cursize);
152  if (result == NULL) return NULL;
153  }
154 
155  strcpy(result + pos, readvalue);
156  pos += len;
157 
158  i++;
159  }
160  return result;
161 }
162 
163 static GSM_Error SaveBackupText(FILE *file, const char *myname, const char *myvalue, const gboolean UseUnicode)
164 {
165  char buffer[10000]={0};
166  unsigned char buffer2[10000]={0};
167 
168  if (myname[0] == 0x00) {
169  if (UseUnicode) {
170  EncodeUnicode(buffer,myvalue,strlen(myvalue));
171  chk_fwrite(buffer,1,strlen(myvalue)*2,file);
172  } else fprintf(file,"%s",myvalue);
173  } else {
174  if (UseUnicode) {
175  sprintf(buffer, "%s = \"", myname);
176  EncodeUnicode(buffer2, buffer, strlen(buffer));
177  chk_fwrite(buffer2, 1, UnicodeLength(buffer2) * 2, file);
178 
179  EncodeUnicodeSpecialChars(buffer2, myvalue);
180  chk_fwrite(buffer2, 1, UnicodeLength(buffer2) * 2, file);
181 
182  sprintf(buffer,"\"%c%c",13,10);
183  EncodeUnicode(buffer2, buffer, strlen(buffer));
184  chk_fwrite(buffer2, 1, UnicodeLength(buffer2) * 2, file);
185 
186  } else {
187  EncodeSpecialChars(buffer, DecodeUnicodeString(myvalue));
188  fprintf(file, "%s = \"%s\"%c%c", myname, buffer, 13, 10);
189  EncodeHexBin(buffer, myvalue, UnicodeLength(myvalue) * 2);
190  fprintf(file, "%sUnicode = %s%c%c", myname, buffer, 13, 10);
191  }
192  }
193  return ERR_NONE;
194 fail:
195  return ERR_WRITING_FILE;
196 }
197 
198 static GSM_Error SaveBackupBase64(FILE *file, char *myname, unsigned char *data, size_t length, gboolean UseUnicode)
199 {
200  char *buffer=NULL;
201  unsigned char *unicode_buffer=NULL;
202  GSM_Error error;
203 
204  /*
205  * Need to be big enough to store base64 (what is *4/3, but *2 is safer
206  * and we don't have to care about rounding and padding).
207  */
208  buffer = (char *)malloc(length * 2);
209  if (buffer == NULL) {
210  return ERR_MOREMEMORY;
211  }
212  unicode_buffer = (unsigned char *)malloc(length * 4);
213  if (unicode_buffer == NULL) {
214  free(buffer);
215  buffer=NULL;
216  return ERR_MOREMEMORY;
217  }
218 
219  EncodeBASE64(data, buffer, length);
220 
221  error = SaveLinkedBackupText(file, myname, buffer, UseUnicode);
222 
223  free(buffer);
224  buffer=NULL;
225  free(unicode_buffer);
226  unicode_buffer=NULL;
227  return error;
228 }
229 
230 #define ReadBackupText(file_info, section, myname, myvalue, UseUnicode) ReadBackupTextLen(file_info, section, myname, myvalue, sizeof(myvalue), UseUnicode)
231 
232 static gboolean ReadBackupTextLen(INI_Section *file_info, const char *section, const char *myname, char *myvalue, const size_t maxlen, const gboolean UseUnicode)
233 {
234  unsigned char paramname[10000],*readvalue, decodedvalue[10000];
235  gboolean ret = TRUE;
236 
237  if (UseUnicode) {
238  EncodeUnicode(paramname,myname,strlen(myname));
239  readvalue = INI_GetValue(file_info, section, paramname, UseUnicode);
240  if (readvalue!=NULL) {
241  DecodeUnicodeSpecialChars(decodedvalue, readvalue+2);
242  if ((UnicodeLength(decodedvalue) + 1) * 2 >= maxlen) {
243  decodedvalue[maxlen - 1] = 0;
244  decodedvalue[maxlen - 2] = 0;
245  dbgprintf(NULL, "String too long!\n");
246  ret = FALSE;
247  }
248  CopyUnicodeString(myvalue, decodedvalue);
249  myvalue[UnicodeLength(myvalue)*2-2]=0;
250  myvalue[UnicodeLength(myvalue)*2-1]=0;
251 
252  dbgprintf(NULL, "Cfg read: %s\n",DecodeUnicodeString(readvalue));
253  } else {
254  myvalue[0]=0;
255  myvalue[1]=0;
256  ret = FALSE;
257  }
258  } else {
259  strcpy(paramname,myname);
260  strcat(paramname,"Unicode");
261  readvalue = ReadCFGText(file_info, section, paramname, UseUnicode);
262  if (readvalue!=NULL) {
263  dbgprintf(NULL, "Cfg read: %s %ld\n",readvalue,(long)strlen(readvalue));
264  if (strlen(readvalue) >= maxlen - 1) {
265  ret = FALSE;
266  dbgprintf(NULL, "String too long!\n");
267  }
268  DecodeHexBin (myvalue, readvalue, MIN(strlen(readvalue), maxlen - 1));
269  myvalue[strlen(readvalue)/2]=0;
270  myvalue[strlen(readvalue)/2+1]=0;
271  dbgprintf(NULL, "Cfg decoded: %s\n",DecodeUnicodeString(myvalue));
272  } else {
273  strcpy(paramname,myname);
274  readvalue = ReadCFGText(file_info, section, paramname, UseUnicode);
275  if (readvalue!=NULL) {
276  DecodeSpecialChars(decodedvalue, readvalue + 1);
277  EncodeUnicode(myvalue, decodedvalue, strlen(decodedvalue) - 1);
278  } else {
279  myvalue[0]=0;
280  myvalue[1]=0;
281  ret = FALSE;
282  }
283  }
284  }
285  return ret;
286 }
287 
288 static GSM_Error SaveVCalDateTime(FILE *file, GSM_DateTime *dt, gboolean UseUnicode)
289 {
290  unsigned char buffer[100];
291  size_t Length = 3;
292  GSM_Error error;
293 
294  sprintf(buffer, " = ");
295  error = VC_StoreDateTime(buffer, sizeof(buffer), &Length, dt, NULL);
296  if (error != ERR_NONE) return error;
297  return SaveBackupText(file, "", buffer, UseUnicode);
298 }
299 
300 static GSM_Error SaveVCalDate(FILE *file, GSM_DateTime *dt, gboolean UseUnicode)
301 {
302  unsigned char buffer[100];
303 
304  sprintf(buffer, " = %04d%02d%02d%c%c", dt->Year, dt->Month, dt->Day,13,10);
305  return SaveBackupText(file, "", buffer, UseUnicode);
306 }
307 
308 /* ---------------------- backup files ------------------------------------- */
309 
310 static GSM_Error SavePbkEntry(FILE *file, GSM_MemoryEntry *Pbk, gboolean UseUnicode)
311 {
312  gboolean text;
313  char buffer[1000]={0};
314  int j, i;
315  GSM_Error error;
316 
317  sprintf(buffer,"Location = %03i%c%c",Pbk->Location,13,10);
318  error = SaveBackupText(file, "", buffer, UseUnicode);
319  if (error != ERR_NONE) return error;
320  for (j=0;j<Pbk->EntriesNum;j++) {
321  text = TRUE;
322  switch (Pbk->Entries[j].Location) {
323  case PBK_Location_Home:
324  sprintf(buffer,"Entry%02iLocation = Home%c%c",j,13,10);
325  error = SaveBackupText(file, "", buffer, UseUnicode);
326  if (error != ERR_NONE) return error;
327  break;
328  case PBK_Location_Work:
329  sprintf(buffer,"Entry%02iLocation = Work%c%c",j,13,10);
330  error = SaveBackupText(file, "", buffer, UseUnicode);
331  if (error != ERR_NONE) return error;
332  break;
334  break;
335  }
336  switch (Pbk->Entries[j].EntryType) {
337  case PBK_Number_General:
338  sprintf(buffer,"Entry%02iType = NumberGeneral%c%c",j,13,10);
339  error = SaveBackupText(file, "", buffer, UseUnicode);
340  if (error != ERR_NONE) return error;
341  break;
342  case PBK_Number_Video:
343  sprintf(buffer,"Entry%02iType = NumberVideo%c%c",j,13,10);
344  error = SaveBackupText(file, "", buffer, UseUnicode);
345  if (error != ERR_NONE) return error;
346  break;
347  case PBK_Number_Mobile:
348  sprintf(buffer,"Entry%02iType = NumberMobile%c%c",j,13,10);
349  error = SaveBackupText(file, "", buffer, UseUnicode);
350  if (error != ERR_NONE) return error;
351  break;
352  case PBK_Number_Fax:
353  sprintf(buffer,"Entry%02iType = NumberFax%c%c",j,13,10);
354  error = SaveBackupText(file, "", buffer, UseUnicode);
355  if (error != ERR_NONE) return error;
356  break;
357  case PBK_Number_Pager:
358  sprintf(buffer,"Entry%02iType = NumberPager%c%c",j,13,10);
359  error = SaveBackupText(file, "", buffer, UseUnicode);
360  if (error != ERR_NONE) return error;
361  break;
362  case PBK_Number_Other:
363  sprintf(buffer,"Entry%02iType = NumberOther%c%c",j,13,10);
364  error = SaveBackupText(file, "", buffer, UseUnicode);
365  if (error != ERR_NONE) return error;
366  break;
368  sprintf(buffer,"Entry%02iType = NumberMessaging%c%c",j,13,10);
369  error = SaveBackupText(file, "", buffer, UseUnicode);
370  if (error != ERR_NONE) return error;
371  break;
372  case PBK_Text_Note:
373  sprintf(buffer,"Entry%02iType = Note%c%c",j,13,10);
374  error = SaveBackupText(file, "", buffer, UseUnicode);
375  if (error != ERR_NONE) return error;
376  break;
377  case PBK_Text_Postal:
378  sprintf(buffer,"Entry%02iType = Postal%c%c",j,13,10);
379  error = SaveBackupText(file, "", buffer, UseUnicode);
380  if (error != ERR_NONE) return error;
381  break;
382  case PBK_Text_Email:
383  sprintf(buffer,"Entry%02iType = Email%c%c",j,13,10);
384  error = SaveBackupText(file, "", buffer, UseUnicode);
385  if (error != ERR_NONE) return error;
386  break;
387  case PBK_Text_Email2:
388  sprintf(buffer,"Entry%02iType = Email2%c%c",j,13,10);
389  error = SaveBackupText(file, "", buffer, UseUnicode);
390  if (error != ERR_NONE) return error;
391  break;
392  case PBK_Text_URL:
393  sprintf(buffer,"Entry%02iType = URL%c%c",j,13,10);
394  error = SaveBackupText(file, "", buffer, UseUnicode);
395  if (error != ERR_NONE) return error;
396  break;
397  case PBK_Text_Name:
398  sprintf(buffer,"Entry%02iType = Name%c%c",j,13,10);
399  error = SaveBackupText(file, "", buffer, UseUnicode);
400  if (error != ERR_NONE) return error;
401  break;
402  case PBK_Caller_Group:
403  sprintf(buffer,"Entry%02iType = CallerGroup%c%c",j,13,10);
404  error = SaveBackupText(file, "", buffer, UseUnicode);
405  if (error != ERR_NONE) return error;
406  sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
407  error = SaveBackupText(file, "", buffer, UseUnicode);
408  if (error != ERR_NONE) return error;
409  text = FALSE;
410  break;
411  case PBK_RingtoneID:
412  sprintf(buffer,"Entry%02iType = RingtoneID%c%c",j,13,10);
413  error = SaveBackupText(file, "", buffer, UseUnicode);
414  if (error != ERR_NONE) return error;
415  sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
416  error = SaveBackupText(file, "", buffer, UseUnicode);
417  if (error != ERR_NONE) return error;
418  text = FALSE;
419  break;
420  case PBK_PictureID:
421  sprintf(buffer,"Entry%02iType = PictureID%c%c",j,13,10);
422  error = SaveBackupText(file, "", buffer, UseUnicode);
423  if (error != ERR_NONE) return error;
424  sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
425  error = SaveBackupText(file, "", buffer, UseUnicode);
426  if (error != ERR_NONE) return error;
427  text = FALSE;
428  break;
430  sprintf(buffer,"Entry%02iType = PictureName%c%c",j,13,10);
431  error = SaveBackupText(file, "", buffer, UseUnicode);
432  if (error != ERR_NONE) return error;
433  break;
434  case PBK_Text_UserID:
435  sprintf(buffer,"Entry%02iType = UserID%c%c",j,13,10);
436  error = SaveBackupText(file, "", buffer, UseUnicode);
437  if (error != ERR_NONE) return error;
438  break;
439  case PBK_Category:
440  sprintf(buffer,"Entry%02iType = Category%c%c",j,13,10);
441  error = SaveBackupText(file, "", buffer, UseUnicode);
442  if (error != ERR_NONE) return error;
443  if (Pbk->Entries[j].Number != -1) {
444  sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
445  error = SaveBackupText(file, "", buffer, UseUnicode);
446  if (error != ERR_NONE) return error;
447  text = FALSE;
448  }
449  break;
450  case PBK_Private:
451  sprintf(buffer,"Entry%02iType = Private%c%c",j,13,10);
452  error = SaveBackupText(file, "", buffer, UseUnicode);
453  if (error != ERR_NONE) return error;
454  sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
455  error = SaveBackupText(file, "", buffer, UseUnicode);
456  if (error != ERR_NONE) return error;
457  text = FALSE;
458  break;
459  case PBK_Text_LastName:
460  sprintf(buffer,"Entry%02iType = LastName%c%c",j,13,10);
461  error = SaveBackupText(file, "", buffer, UseUnicode);
462  if (error != ERR_NONE) return error;
463  break;
464  case PBK_Text_FirstName:
465  sprintf(buffer,"Entry%02iType = FirstName%c%c",j,13,10);
466  error = SaveBackupText(file, "", buffer, UseUnicode);
467  if (error != ERR_NONE) return error;
468  break;
469  case PBK_Text_SecondName:
470  sprintf(buffer,"Entry%02iType = SecondName%c%c",j,13,10);
471  error = SaveBackupText(file, "", buffer, UseUnicode);
472  if (error != ERR_NONE) return error;
473  break;
474  case PBK_Text_NickName:
475  sprintf(buffer,"Entry%02iType = NickName%c%c",j,13,10);
476  error = SaveBackupText(file, "", buffer, UseUnicode);
477  if (error != ERR_NONE) return error;
478  break;
479  case PBK_Text_FormalName:
480  sprintf(buffer,"Entry%02iType = FormalName%c%c",j,13,10);
481  error = SaveBackupText(file, "", buffer, UseUnicode);
482  if (error != ERR_NONE) return error;
483  break;
484  case PBK_Text_NamePrefix:
485  sprintf(buffer,"Entry%02iType = NamePrefix%c%c",j,13,10);
486  error = SaveBackupText(file, "", buffer, UseUnicode);
487  if (error != ERR_NONE) return error;
488  break;
489  case PBK_Text_NameSuffix:
490  sprintf(buffer,"Entry%02iType = NameSuffix%c%c",j,13,10);
491  error = SaveBackupText(file, "", buffer, UseUnicode);
492  if (error != ERR_NONE) return error;
493  break;
494  case PBK_Text_Company:
495  sprintf(buffer,"Entry%02iType = Company%c%c",j,13,10);
496  error = SaveBackupText(file, "", buffer, UseUnicode);
497  if (error != ERR_NONE) return error;
498  break;
499  case PBK_Text_JobTitle:
500  sprintf(buffer,"Entry%02iType = JobTitle%c%c",j,13,10);
501  error = SaveBackupText(file, "", buffer, UseUnicode);
502  if (error != ERR_NONE) return error;
503  break;
505  sprintf(buffer,"Entry%02iType = Address%c%c",j,13,10);
506  error = SaveBackupText(file, "", buffer, UseUnicode);
507  if (error != ERR_NONE) return error;
508  break;
509  case PBK_Text_City:
510  sprintf(buffer,"Entry%02iType = City%c%c",j,13,10);
511  error = SaveBackupText(file, "", buffer, UseUnicode);
512  if (error != ERR_NONE) return error;
513  break;
514  case PBK_Text_State:
515  sprintf(buffer,"Entry%02iType = State%c%c",j,13,10);
516  error = SaveBackupText(file, "", buffer, UseUnicode);
517  if (error != ERR_NONE) return error;
518  break;
519  case PBK_Text_Zip:
520  sprintf(buffer,"Entry%02iType = Zip%c%c",j,13,10);
521  error = SaveBackupText(file, "", buffer, UseUnicode);
522  if (error != ERR_NONE) return error;
523  break;
524  case PBK_Text_Country:
525  sprintf(buffer,"Entry%02iType = Country%c%c",j,13,10);
526  error = SaveBackupText(file, "", buffer, UseUnicode);
527  if (error != ERR_NONE) return error;
528  break;
529  case PBK_Text_Custom1:
530  sprintf(buffer,"Entry%02iType = Custom1%c%c",j,13,10);
531  error = SaveBackupText(file, "", buffer, UseUnicode);
532  if (error != ERR_NONE) return error;
533  break;
534  case PBK_Text_Custom2:
535  sprintf(buffer,"Entry%02iType = Custom2%c%c",j,13,10);
536  error = SaveBackupText(file, "", buffer, UseUnicode);
537  if (error != ERR_NONE) return error;
538  break;
539  case PBK_Text_Custom3:
540  sprintf(buffer,"Entry%02iType = Custom3%c%c",j,13,10);
541  error = SaveBackupText(file, "", buffer, UseUnicode);
542  if (error != ERR_NONE) return error;
543  break;
544  case PBK_Text_Custom4:
545  sprintf(buffer,"Entry%02iType = Custom4%c%c",j,13,10);
546  error = SaveBackupText(file, "", buffer, UseUnicode);
547  if (error != ERR_NONE) return error;
548  break;
549  case PBK_Text_LUID:
550  sprintf(buffer,"Entry%02iType = LUID%c%c",j,13,10);
551  error = SaveBackupText(file, "", buffer, UseUnicode);
552  if (error != ERR_NONE) return error;
553  break;
554  case PBK_Text_VOIP:
555  sprintf(buffer,"Entry%02iType = VOIP%c%c",j,13,10);
556  error = SaveBackupText(file, "", buffer, UseUnicode);
557  if (error != ERR_NONE) return error;
558  break;
559  case PBK_Text_WVID:
560  sprintf(buffer,"Entry%02iType = WVID%c%c",j,13,10);
561  error = SaveBackupText(file, "", buffer, UseUnicode);
562  if (error != ERR_NONE) return error;
563  break;
564  case PBK_Text_SWIS:
565  sprintf(buffer,"Entry%02iType = SWIS%c%c",j,13,10);
566  error = SaveBackupText(file, "", buffer, UseUnicode);
567  if (error != ERR_NONE) return error;
568  break;
569  case PBK_Text_SIP:
570  sprintf(buffer,"Entry%02iType = SIP%c%c",j,13,10);
571  error = SaveBackupText(file, "", buffer, UseUnicode);
572  if (error != ERR_NONE) return error;
573  break;
574  case PBK_Text_DTMF:
575  sprintf(buffer,"Entry%02iType = DTMF%c%c",j,13,10);
576  error = SaveBackupText(file, "", buffer, UseUnicode);
577  if (error != ERR_NONE) return error;
578  break;
579  case PBK_Date:
580  sprintf(buffer,"Entry%02iType = Date%c%cEntry%02iText",j,13,10, j);
581  error = SaveBackupText(file, "", buffer, UseUnicode);
582  if (error != ERR_NONE) return error;
583  error = SaveVCalDate(file, &Pbk->Entries[j].Date, UseUnicode);
584  if (error != ERR_NONE) return error;
585  text = FALSE;
586  break;
587  case PBK_LastModified:
588  sprintf(buffer,"Entry%02iType = LastModified%c%cEntry%02iText",j,13,10, j);
589  error = SaveBackupText(file, "", buffer, UseUnicode);
590  if (error != ERR_NONE) return error;
591  error = SaveVCalDateTime(file, &Pbk->Entries[j].Date, UseUnicode);
592  if (error != ERR_NONE) return error;
593  text = FALSE;
594  break;
595  case PBK_CallLength:
596  text = FALSE;
597  break;
598  case PBK_PushToTalkID:
599  sprintf(buffer,"Entry%02iType = PushToTalkID%c%c",j,13,10);
600  error = SaveBackupText(file, "", buffer, UseUnicode);
601  if (error != ERR_NONE) return error;
602  break;
603  case PBK_Photo:
604  switch (Pbk->Entries[j].Picture.Type) {
605  case PICTURE_BMP:
606  sprintf(buffer,"Entry%02iType = BMPPhoto%c%c",j,13,10);
607  break;
608  case PICTURE_GIF:
609  sprintf(buffer,"Entry%02iType = GIFPhoto%c%c",j,13,10);
610  break;
611  case PICTURE_JPG:
612  sprintf(buffer,"Entry%02iType = JPEGPhoto%c%c",j,13,10);
613  break;
614  case PICTURE_ICN:
615  sprintf(buffer,"Entry%02iType = ICOPhoto%c%c",j,13,10);
616  break;
617  case PICTURE_PNG:
618  sprintf(buffer,"Entry%02iType = PNGPhoto%c%c",j,13,10);
619  break;
620  default:
621  dbgprintf(NULL, "Unknown picture format: %d\n", Pbk->Entries[j].Picture.Type);
622  sprintf(buffer,"Entry%02iType = Photo%c%c",j,13,10);
623  break;
624  }
625  error = SaveBackupText(file, "", buffer, UseUnicode);
626  if (error != ERR_NONE) return error;
627  sprintf(buffer, "Entry%02iData", j);
628  error = SaveBackupBase64(file, buffer, Pbk->Entries[j].Picture.Buffer, Pbk->Entries[j].Picture.Length, UseUnicode);
629  if (error != ERR_NONE) return error;
630  text = FALSE;
631  break;
632  }
633  if (text) {
634  sprintf(buffer,"Entry%02iText",j);
635  error = SaveBackupText(file,buffer,Pbk->Entries[j].Text, UseUnicode);
636  if (error != ERR_NONE) return error;
637  }
638  switch (Pbk->Entries[j].EntryType) {
639  case PBK_Number_General:
640  case PBK_Number_Video:
641  case PBK_Number_Mobile:
642  case PBK_Number_Fax:
643  case PBK_Number_Other:
644  case PBK_Number_Pager:
645  if (Pbk->Entries[j].VoiceTag!=0) {
646  sprintf(buffer,"Entry%02iVoiceTag = %i%c%c",j,Pbk->Entries[j].VoiceTag,13,10);
647  error = SaveBackupText(file, "", buffer, UseUnicode);
648  if (error != ERR_NONE) return error;
649  }
650  i = 0;
651  while (Pbk->Entries[j].SMSList[i]!=0) {
652  sprintf(buffer,"Entry%02iSMSList%02i = %i%c%c",j,i,Pbk->Entries[j].SMSList[i],13,10);
653  error = SaveBackupText(file, "", buffer, UseUnicode);
654  if (error != ERR_NONE) return error;
655  i++;
656  }
657  break;
658  default:
659  break;
660  }
661  }
662  sprintf(buffer,"%c%c",13,10);
663  error = SaveBackupText(file, "", buffer, UseUnicode);
664  if (error != ERR_NONE) return error;
665 
666  return ERR_NONE;
667 }
668 
669 static GSM_Error SaveNoteEntry(FILE *file, GSM_NoteEntry *Note, gboolean UseUnicode)
670 {
671  char buffer[1000]={0};
672  GSM_Error error;
673 
674  sprintf(buffer,"Location = %d%c%c", Note->Location,13,10);
675  error = SaveBackupText(file, "", buffer, UseUnicode);
676  if (error != ERR_NONE) return error;
677  error = SaveBackupText(file, "Text", Note->Text, UseUnicode);
678  if (error != ERR_NONE) return error;
679  sprintf(buffer, "%c%c",13,10);
680  error = SaveBackupText(file, "", buffer, UseUnicode);
681  if (error != ERR_NONE) return error;
682 
683  return ERR_NONE;
684 }
685 
686 static GSM_Error SaveCalendarType(FILE *file, GSM_CalendarNoteType Type, gboolean UseUnicode)
687 {
688  char buffer[1000]={0};
689  GSM_Error error;
690 
691  error = SaveBackupText(file, "", "Type = ", UseUnicode);
692  if (error != ERR_NONE) return error;
693  sprintf(buffer,"0%c%c",13,10);
694  switch (Type) {
695  case GSM_CAL_REMINDER : sprintf(buffer,"Reminder%c%c", 13,10); break;
696  case GSM_CAL_CALL : sprintf(buffer,"Call%c%c", 13,10); break;
697  case GSM_CAL_MEETING : sprintf(buffer,"Meeting%c%c", 13,10); break;
698  case GSM_CAL_BIRTHDAY : sprintf(buffer,"Birthday%c%c", 13,10); break;
699  case GSM_CAL_TRAVEL : sprintf(buffer,"Travel%c%c", 13,10); break;
700  case GSM_CAL_VACATION : sprintf(buffer,"Vacation%c%c", 13,10); break;
701  case GSM_CAL_MEMO : sprintf(buffer,"Memo%c%c", 13,10); break;
702  case GSM_CAL_SHOPPING : sprintf(buffer,"Shopping%c%c", 13,10); break;
703  case GSM_CAL_ALARM : sprintf(buffer,"Alarm%c%c", 13,10); break;
704  case GSM_CAL_DAILY_ALARM: sprintf(buffer,"DailyAlarm%c%c", 13,10); break;
705  case GSM_CAL_T_ATHL : sprintf(buffer,"Training/Athletism%c%c", 13,10); break;
706  case GSM_CAL_T_BALL : sprintf(buffer,"Training/BallGames%c%c", 13,10); break;
707  case GSM_CAL_T_CYCL : sprintf(buffer,"Training/Cycling%c%c", 13,10); break;
708  case GSM_CAL_T_BUDO : sprintf(buffer,"Training/Budo%c%c", 13,10); break;
709  case GSM_CAL_T_DANC : sprintf(buffer,"Training/Dance%c%c", 13,10); break;
710  case GSM_CAL_T_EXTR : sprintf(buffer,"Training/ExtremeSports%c%c", 13,10); break;
711  case GSM_CAL_T_FOOT : sprintf(buffer,"Training/Football%c%c", 13,10); break;
712  case GSM_CAL_T_GOLF : sprintf(buffer,"Training/Golf%c%c", 13,10); break;
713  case GSM_CAL_T_GYM : sprintf(buffer,"Training/Gym%c%c", 13,10); break;
714  case GSM_CAL_T_HORS : sprintf(buffer,"Training/HorseRaces%c%c", 13,10); break;
715  case GSM_CAL_T_HOCK : sprintf(buffer,"Training/Hockey%c%c", 13,10); break;
716  case GSM_CAL_T_RACE : sprintf(buffer,"Training/Races%c%c", 13,10); break;
717  case GSM_CAL_T_RUGB : sprintf(buffer,"Training/Rugby%c%c", 13,10); break;
718  case GSM_CAL_T_SAIL : sprintf(buffer,"Training/Sailing%c%c", 13,10); break;
719  case GSM_CAL_T_STRE : sprintf(buffer,"Training/StreetGames%c%c", 13,10); break;
720  case GSM_CAL_T_SWIM : sprintf(buffer,"Training/Swimming%c%c", 13,10); break;
721  case GSM_CAL_T_TENN : sprintf(buffer,"Training/Tennis%c%c", 13,10); break;
722  case GSM_CAL_T_TRAV : sprintf(buffer,"Training/Travels%c%c", 13,10); break;
723  case GSM_CAL_T_WINT : sprintf(buffer,"Training/WinterGames%c%c", 13,10); break;
724  }
725  error = SaveBackupText(file, "", buffer, UseUnicode);
726  if (error != ERR_NONE) return error;
727 
728  return ERR_NONE;
729 }
730 
731 static GSM_Error SaveCalendarEntry(FILE *file, GSM_CalendarEntry *Note, gboolean UseUnicode)
732 {
733  int i;
734  char buffer[1000]={0};
735  GSM_Error error;
736 
737  sprintf(buffer,"Location = %d%c%c", Note->Location,13,10);
738  error = SaveBackupText(file, "", buffer, UseUnicode);
739  if (error != ERR_NONE) return error;
740  error = SaveCalendarType(file, Note->Type, UseUnicode);
741  if (error != ERR_NONE) return error;
742  for (i=0;i<Note->EntriesNum;i++) {
743  switch (Note->Entries[i].EntryType) {
744  case CAL_START_DATETIME:
745  error = SaveBackupText(file, "", "StartTime", UseUnicode);
746  if (error != ERR_NONE) return error;
747  error = SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode);
748  if (error != ERR_NONE) return error;
749  break;
750  case CAL_END_DATETIME:
751  error = SaveBackupText(file, "", "StopTime", UseUnicode);
752  if (error != ERR_NONE) return error;
753  error = SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode);
754  if (error != ERR_NONE) return error;
755  break;
757  error = SaveBackupText(file, "", "ToneAlarm", UseUnicode);
758  if (error != ERR_NONE) return error;
759  error = SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode);
760  if (error != ERR_NONE) return error;
761  break;
763  error = SaveBackupText(file, "", "SilentAlarm", UseUnicode);
764  if (error != ERR_NONE) return error;
765  error = SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode);
766  if (error != ERR_NONE) return error;
767  break;
768  case CAL_LAST_MODIFIED:
769  error = SaveBackupText(file, "", "LastModified", UseUnicode);
770  if (error != ERR_NONE) return error;
771  error = SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode);
772  if (error != ERR_NONE) return error;
773  break;
774  case CAL_PRIVATE:
775  sprintf(buffer, "Private = %d%c%c",Note->Entries[i].Number,13,10);
776  error = SaveBackupText(file, "", buffer, UseUnicode);
777  if (error != ERR_NONE) return error;
778  break;
779  case CAL_LOCATION:
780  error = SaveBackupText(file, "EventLocation", Note->Entries[i].Text, UseUnicode);
781  if (error != ERR_NONE) return error;
782  break;
783  case CAL_CONTACTID:
784  sprintf(buffer, "ContactID = %d%c%c",Note->Entries[i].Number,13,10);
785  error = SaveBackupText(file, "", buffer, UseUnicode);
786  if (error != ERR_NONE) return error;
787  break;
788  case CAL_TEXT:
789  error = SaveBackupText(file, "Text", Note->Entries[i].Text, UseUnicode);
790  if (error != ERR_NONE) return error;
791  break;
792  case CAL_DESCRIPTION:
793  error = SaveBackupText(file, "Description", Note->Entries[i].Text, UseUnicode);
794  if (error != ERR_NONE) return error;
795  break;
796  case CAL_LUID:
797  error = SaveBackupText(file, "LUID", Note->Entries[i].Text, UseUnicode);
798  if (error != ERR_NONE) return error;
799  break;
800  case CAL_PHONE:
801  error = SaveBackupText(file, "Phone", Note->Entries[i].Text, UseUnicode);
802  if (error != ERR_NONE) return error;
803  break;
804  case CAL_REPEAT_STOPDATE:
805  error = SaveBackupText(file, "", "RepeatStopDate", UseUnicode);
806  if (error != ERR_NONE) return error;
807  error = SaveVCalDate(file, &Note->Entries[i].Date, UseUnicode);
808  if (error != ERR_NONE) return error;
809  break;
811  error = SaveBackupText(file, "", "RepeatStartDate", UseUnicode);
812  if (error != ERR_NONE) return error;
813  error = SaveVCalDate(file, &Note->Entries[i].Date, UseUnicode);
814  if (error != ERR_NONE) return error;
815  break;
817  sprintf(buffer, "RepeatDayOfWeek = %d%c%c",Note->Entries[i].Number,13,10);
818  error = SaveBackupText(file, "", buffer, UseUnicode);
819  if (error != ERR_NONE) return error;
820  break;
821  case CAL_REPEAT_DAY:
822  sprintf(buffer, "RepeatDay = %d%c%c",Note->Entries[i].Number,13,10);
823  error = SaveBackupText(file, "", buffer, UseUnicode);
824  if (error != ERR_NONE) return error;
825  break;
827  sprintf(buffer, "RepeatWeekOfMonth = %d%c%c",Note->Entries[i].Number,13,10);
828  error = SaveBackupText(file, "", buffer, UseUnicode);
829  if (error != ERR_NONE) return error;
830  break;
831  case CAL_REPEAT_MONTH:
832  sprintf(buffer, "RepeatMonth = %d%c%c",Note->Entries[i].Number,13,10);
833  error = SaveBackupText(file, "", buffer, UseUnicode);
834  if (error != ERR_NONE) return error;
835  break;
837  sprintf(buffer, "RepeatFrequency = %d%c%c",Note->Entries[i].Number,13,10);
838  error = SaveBackupText(file, "", buffer, UseUnicode);
839  if (error != ERR_NONE) return error;
840  break;
841  case CAL_REPEAT_COUNT:
842  sprintf(buffer, "RepeatCount = %d%c%c",Note->Entries[i].Number,13,10);
843  error = SaveBackupText(file, "", buffer, UseUnicode);
844  if (error != ERR_NONE) return error;
845  break;
847  sprintf(buffer, "RepeatDayOfYear = %d%c%c",Note->Entries[i].Number,13,10);
848  error = SaveBackupText(file, "", buffer, UseUnicode);
849  if (error != ERR_NONE) return error;
850  break;
851  }
852  }
853  sprintf(buffer, "%c%c",13,10);
854  error = SaveBackupText(file, "", buffer, UseUnicode);
855  if (error != ERR_NONE) return error;
856 
857  return ERR_NONE;
858 }
859 
860 static GSM_Error SaveWAPSettingsEntry(FILE *file, GSM_MultiWAPSettings *settings, gboolean UseUnicode)
861 {
862  int i;
863  char buffer[10000]={0};
864  GSM_Error error;
865 
866  if (settings->Active) {
867  sprintf(buffer,"Active = Yes%c%c",13,10);
868  error = SaveBackupText(file, "", buffer, UseUnicode);
869  if (error != ERR_NONE) return error;
870  }
871  switch (settings->ActiveBearer) {
872  case WAPSETTINGS_BEARER_SMS : sprintf(buffer,"Bearer = SMS%c%c",13,10); break;
873  case WAPSETTINGS_BEARER_GPRS: sprintf(buffer,"Bearer = GPRS%c%c",13,10); break;
874  case WAPSETTINGS_BEARER_DATA: sprintf(buffer,"Bearer = Data%c%c",13,10); break;
875  case WAPSETTINGS_BEARER_USSD: sprintf(buffer,"Bearer = USSD%c%c",13,10);
876  }
877  error = SaveBackupText(file, "", buffer, UseUnicode);
878  if (error != ERR_NONE) return error;
879  if (settings->ReadOnly) {
880  sprintf(buffer,"ReadOnly = Yes%c%c",13,10);
881  error = SaveBackupText(file, "", buffer, UseUnicode);
882  if (error != ERR_NONE) return error;
883  }
884  sprintf(buffer,"Proxy");
885  error = SaveBackupText(file, buffer, settings->Proxy, UseUnicode);
886  if (error != ERR_NONE) return error;
887  sprintf(buffer,"ProxyPort = %i%c%c",settings->ProxyPort,13,10);
888  error = SaveBackupText(file, "", buffer, UseUnicode);
889  if (error != ERR_NONE) return error;
890  sprintf(buffer,"Proxy2");
891  error = SaveBackupText(file, buffer, settings->Proxy2, UseUnicode);
892  if (error != ERR_NONE) return error;
893  sprintf(buffer,"Proxy2Port = %i%c%c",settings->Proxy2Port,13,10);
894  error = SaveBackupText(file, "", buffer, UseUnicode);
895  if (error != ERR_NONE) return error;
896  sprintf(buffer,"%c%c",13,10);
897  error = SaveBackupText(file, "", buffer, UseUnicode);
898  if (error != ERR_NONE) return error;
899  for (i=0;i<settings->Number;i++) {
900  sprintf(buffer,"Title%02i",i);
901  error = SaveBackupText(file, buffer, settings->Settings[i].Title, UseUnicode);
902  if (error != ERR_NONE) return error;
903  sprintf(buffer,"HomePage%02i",i);
904  error = SaveBackupText(file, buffer, settings->Settings[i].HomePage, UseUnicode);
905  if (error != ERR_NONE) return error;
906  if (settings->Settings[i].IsContinuous) {
907  sprintf(buffer,"Type%02i = Continuous%c%c",i,13,10);
908  } else {
909  sprintf(buffer,"Type%02i = Temporary%c%c",i,13,10);
910  }
911  error = SaveBackupText(file, "", buffer, UseUnicode);
912  if (error != ERR_NONE) return error;
913  if (settings->Settings[i].IsSecurity) {
914  sprintf(buffer,"Security%02i = On%c%c",i,13,10);
915  } else {
916  sprintf(buffer,"Security%02i = Off%c%c",i,13,10);
917  }
918  error = SaveBackupText(file, "", buffer, UseUnicode);
919  if (error != ERR_NONE) return error;
920  switch (settings->Settings[i].Bearer) {
922  sprintf(buffer,"Bearer%02i = SMS%c%c",i,13,10);
923  error = SaveBackupText(file, "", buffer, UseUnicode);
924  if (error != ERR_NONE) return error;
925  sprintf(buffer,"Server%02i",i);
926  error = SaveBackupText(file, buffer, settings->Settings[i].Server, UseUnicode);
927  if (error != ERR_NONE) return error;
928  sprintf(buffer,"Service%02i",i);
929  error = SaveBackupText(file, buffer, settings->Settings[i].Service, UseUnicode);
930  if (error != ERR_NONE) return error;
931  break;
933  sprintf(buffer,"Bearer%02i = GPRS%c%c",i,13,10);
934  error = SaveBackupText(file, "", buffer, UseUnicode);
935  if (error != ERR_NONE) return error;
936  sprintf(buffer,"IP%02i",i);
937  error = SaveBackupText(file, buffer, settings->Settings[i].IPAddress, UseUnicode);
938  if (error != ERR_NONE) return error;
940  if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_DATA) {
941  sprintf(buffer,"Bearer%02i = Data%c%c",i,13,10);
942  error = SaveBackupText(file, "", buffer, UseUnicode);
943  if (error != ERR_NONE) return error;
944  if (settings->Settings[i].IsISDNCall) {
945  sprintf(buffer,"CallType%02i = ISDN%c%c",i,13,10);
946  } else {
947  sprintf(buffer,"CallType%02i = Analogue%c%c",i,13,10);
948  }
949  error = SaveBackupText(file, "", buffer, UseUnicode);
950  if (error != ERR_NONE) return error;
951  sprintf(buffer,"IP%02i",i);
952  error = SaveBackupText(file, buffer, settings->Settings[i].IPAddress, UseUnicode);
953  if (error != ERR_NONE) return error;
954  }
955  sprintf(buffer,"Number%02i",i);
956  error = SaveBackupText(file, buffer, settings->Settings[i].DialUp, UseUnicode);
957  if (error != ERR_NONE) return error;
958  if (settings->Settings[i].ManualLogin) {
959  sprintf(buffer,"Login%02i = Manual%c%c",i,13,10);
960  } else {
961  sprintf(buffer,"Login%02i = Automatic%c%c",i,13,10);
962  }
963  error = SaveBackupText(file, "", buffer, UseUnicode);
964  if (error != ERR_NONE) return error;
965  if (settings->Settings[i].IsNormalAuthentication) {
966  sprintf(buffer,"Authentication%02i = Normal%c%c",i,13,10);
967  } else {
968  sprintf(buffer,"Authentication%02i = Secure%c%c",i,13,10);
969  }
970  error = SaveBackupText(file, "", buffer, UseUnicode);
971  if (error != ERR_NONE) return error;
972  switch (settings->Settings[i].Speed) {
973  case WAPSETTINGS_SPEED_9600 : sprintf(buffer,"CallSpeed%02i = 9600%c%c" ,i,13,10); break;
974  case WAPSETTINGS_SPEED_14400: sprintf(buffer,"CallSpeed%02i = 14400%c%c",i,13,10); break;
975  case WAPSETTINGS_SPEED_AUTO : sprintf(buffer,"CallSpeed%02i = auto%c%c" ,i,13,10); break;
976  }
977  switch (settings->Settings[i].Speed) {
981  error = SaveBackupText(file, "", buffer, UseUnicode);
982  if (error != ERR_NONE) return error;
983  default:
984  break;
985  }
986  sprintf(buffer,"User%02i",i);
987  error = SaveBackupText(file, buffer, settings->Settings[i].User, UseUnicode);
988  if (error != ERR_NONE) return error;
989  sprintf(buffer,"Password%02i",i);
990  error = SaveBackupText(file, buffer, settings->Settings[i].Password, UseUnicode);
991  if (error != ERR_NONE) return error;
992  break;
994  sprintf(buffer,"Bearer%02i = USSD%c%c",i,13,10);
995  error = SaveBackupText(file, "", buffer, UseUnicode);
996  if (error != ERR_NONE) return error;
997  sprintf(buffer,"ServiceCode%02i",i);
998  error = SaveBackupText(file, buffer, settings->Settings[i].Code, UseUnicode);
999  if (error != ERR_NONE) return error;
1000  if (settings->Settings[i].IsIP) {
1001  sprintf(buffer,"IP%02i",i);
1002  } else {
1003  sprintf(buffer,"Number%02i",i);
1004  }
1005  error = SaveBackupText(file, buffer, settings->Settings[i].Service, UseUnicode);
1006  if (error != ERR_NONE) return error;
1007  }
1008  sprintf(buffer,"%c%c",13,10);
1009  error = SaveBackupText(file, "", buffer, UseUnicode);
1010  if (error != ERR_NONE) return error;
1011  }
1012  return ERR_NONE;
1013 }
1014 
1015 static GSM_Error SaveChatSettingsEntry(FILE *file, GSM_ChatSettings *settings, gboolean UseUnicode)
1016 {
1017  char buffer[10000]={0};
1018  GSM_Error error;
1019 
1020  sprintf(buffer,"HomePage");
1021  error = SaveBackupText(file, buffer, settings->HomePage, UseUnicode);
1022  if (error != ERR_NONE) return error;
1023  sprintf(buffer,"User");
1024  error = SaveBackupText(file, buffer, settings->User, UseUnicode);
1025  if (error != ERR_NONE) return error;
1026  sprintf(buffer,"Password");
1027  error = SaveBackupText(file, buffer, settings->Password, UseUnicode);
1028  if (error != ERR_NONE) return error;
1029  error = SaveWAPSettingsEntry(file, &settings->Connection, UseUnicode);
1030  if (error != ERR_NONE) return error;
1031  return ERR_NONE;
1032 }
1033 
1034 static GSM_Error SaveSyncMLSettingsEntry(FILE *file, GSM_SyncMLSettings *settings, gboolean UseUnicode)
1035 {
1036  char buffer[10000]={0};
1037  GSM_Error error;
1038 
1039  sprintf(buffer,"User");
1040  error = SaveBackupText(file, buffer, settings->User, UseUnicode);
1041  if (error != ERR_NONE) return error;
1042  sprintf(buffer,"Password");
1043  error = SaveBackupText(file, buffer, settings->Password, UseUnicode);
1044  if (error != ERR_NONE) return error;
1045  sprintf(buffer,"PhonebookDB");
1046  error = SaveBackupText(file, buffer, settings->PhonebookDataBase, UseUnicode);
1047  if (error != ERR_NONE) return error;
1048  sprintf(buffer,"CalendarDB");
1049  error = SaveBackupText(file, buffer, settings->CalendarDataBase, UseUnicode);
1050  if (error != ERR_NONE) return error;
1051  sprintf(buffer,"Server");
1052  error = SaveBackupText(file, buffer, settings->Server, UseUnicode);
1053  if (error != ERR_NONE) return error;
1054  if (settings->SyncPhonebook) {
1055  sprintf(buffer,"SyncPhonebook = True%c%c",13,10);
1056  } else {
1057  sprintf(buffer,"SyncPhonebook = False%c%c",13,10);
1058  }
1059  error = SaveBackupText(file, "", buffer, UseUnicode);
1060  if (error != ERR_NONE) return error;
1061  if (settings->SyncCalendar) {
1062  sprintf(buffer,"SyncCalendar = True%c%c",13,10);
1063  } else {
1064  sprintf(buffer,"SyncCalendar = False%c%c",13,10);
1065  }
1066  error = SaveBackupText(file, "", buffer, UseUnicode);
1067  if (error != ERR_NONE) return error;
1068  error = SaveWAPSettingsEntry(file, &settings->Connection, UseUnicode);
1069  if (error != ERR_NONE) return error;
1070  return ERR_NONE;
1071 }
1072 
1073 static GSM_Error SaveBitmapEntry(FILE *file, GSM_Bitmap *bitmap, gboolean UseUnicode)
1074 {
1075  unsigned char buffer[10000]={0},buffer2[10000]={0};
1076  size_t x,y;
1077  GSM_Error error;
1078 
1079  sprintf(buffer,"Width = %ld%c%c", (long)bitmap->BitmapWidth,13,10);
1080  error = SaveBackupText(file, "", buffer, UseUnicode);
1081  if (error != ERR_NONE) return error;
1082  sprintf(buffer,"Height = %ld%c%c", (long)bitmap->BitmapHeight,13,10);
1083  error = SaveBackupText(file, "", buffer, UseUnicode);
1084  if (error != ERR_NONE) return error;
1085  for (y=0;y<bitmap->BitmapHeight;y++) {
1086  for (x=0;x<bitmap->BitmapWidth;x++) {
1087  buffer[x] = ' ';
1088  if (GSM_IsPointBitmap(bitmap,x,y)) buffer[x]='#';
1089  }
1090  buffer[bitmap->BitmapWidth] = 0;
1091  sprintf(buffer2,"Bitmap%02i = \"%s\"%c%c",(int)y,buffer,13,10);
1092  error = SaveBackupText(file, "", buffer2, UseUnicode);
1093  if (error != ERR_NONE) return error;
1094  }
1095  return ERR_NONE;
1096 }
1097 
1098 static GSM_Error SaveCallerEntry(FILE *file, GSM_Bitmap *bitmap, gboolean UseUnicode)
1099 {
1100  unsigned char buffer[1000]={0};
1101  GSM_Error error;
1102 
1103  sprintf(buffer,"Location = %03i%c%c",bitmap->Location,13,10);
1104  error = SaveBackupText(file, "", buffer, UseUnicode);
1105  if (error != ERR_NONE) return error;
1106  if (!bitmap->DefaultName) {
1107  error = SaveBackupText(file, "Name", bitmap->Text, UseUnicode);
1108  if (error != ERR_NONE) return error;
1109  }
1110  if (!bitmap->DefaultRingtone) {
1111  if (bitmap->FileSystemRingtone) {
1112  sprintf(buffer,"FileRingtone = %02x%c%c",bitmap->RingtoneID,13,10);
1113  } else {
1114  sprintf(buffer,"Ringtone = %02x%c%c",bitmap->RingtoneID,13,10);
1115  }
1116  error = SaveBackupText(file, "", buffer, UseUnicode);
1117  if (error != ERR_NONE) return error;
1118  }
1119  if (bitmap->BitmapEnabled) {
1120  sprintf(buffer,"Enabled = True%c%c",13,10);
1121  } else {
1122  sprintf(buffer,"Enabled = False%c%c",13,10);
1123  }
1124  error = SaveBackupText(file, "", buffer, UseUnicode);
1125  if (error != ERR_NONE) return error;
1126  if (!bitmap->DefaultBitmap) {
1127  error = SaveBitmapEntry(file, bitmap, UseUnicode);
1128  if (error != ERR_NONE) return error;
1129  }
1130  sprintf(buffer,"%c%c",13,10);
1131  error = SaveBackupText(file, "", buffer, UseUnicode);
1132  if (error != ERR_NONE) return error;
1133 
1134  return ERR_NONE;
1135 }
1136 
1137 static GSM_Error SaveWAPBookmarkEntry(FILE *file, GSM_WAPBookmark *bookmark, gboolean UseUnicode)
1138 {
1139  unsigned char buffer[1000]={0};
1140  GSM_Error error;
1141 
1142  error = SaveBackupText(file, "URL", bookmark->Address, UseUnicode);
1143  if (error != ERR_NONE) return error;
1144  error = SaveBackupText(file, "Title", bookmark->Title, UseUnicode);
1145  if (error != ERR_NONE) return error;
1146  sprintf(buffer,"%c%c",13,10);
1147  error = SaveBackupText(file, "", buffer, UseUnicode);
1148  if (error != ERR_NONE) return error;
1149 
1150  return ERR_NONE;
1151 }
1152 
1153 static GSM_Error SaveStartupEntry(FILE *file, GSM_Bitmap *bitmap, gboolean UseUnicode)
1154 {
1155  unsigned char buffer[1000]={0};
1156  GSM_Error error;
1157 
1158  sprintf(buffer,"[Startup]%c%c",13,10);
1159  error = SaveBackupText(file, "", buffer, UseUnicode);
1160  if (error != ERR_NONE) return error;
1161  if (bitmap->Type == GSM_WelcomeNote_Text) {
1162  error = SaveBackupText(file, "Text", bitmap->Text, UseUnicode);
1163  if (error != ERR_NONE) return error;
1164  }
1165  if (bitmap->Type == GSM_StartupLogo) {
1166  error = SaveBitmapEntry(file, bitmap, UseUnicode);
1167  if (error != ERR_NONE) return error;
1168  }
1169  sprintf(buffer,"%c%c",13,10);
1170  error = SaveBackupText(file, "", buffer, UseUnicode);
1171  if (error != ERR_NONE) return error;
1172 
1173  return ERR_NONE;
1174 }
1175 
1176 static GSM_Error SaveSMSCEntry(FILE *file, GSM_SMSC *SMSC, gboolean UseUnicode)
1177 {
1178  unsigned char buffer[1000]={0};
1179  GSM_Error error;
1180 
1181  sprintf(buffer,"Location = %03i%c%c",SMSC->Location,13,10);
1182  error = SaveBackupText(file, "", buffer, UseUnicode);
1183  if (error != ERR_NONE) return error;
1184  error = SaveBackupText(file, "Name", SMSC->Name, UseUnicode);
1185  if (error != ERR_NONE) return error;
1186  error = SaveBackupText(file, "Number", SMSC->Number, UseUnicode);
1187  if (error != ERR_NONE) return error;
1188  error = SaveBackupText(file, "DefaultNumber", SMSC->DefaultNumber, UseUnicode);
1189  if (error != ERR_NONE) return error;
1190  error = SaveBackupText(file, "", "Format = ", UseUnicode);
1191  if (error != ERR_NONE) return error;
1192  switch (SMSC->Format) {
1193  case SMS_FORMAT_Text : sprintf(buffer,"Text"); break;
1194  case SMS_FORMAT_Fax : sprintf(buffer,"Fax"); break;
1195  case SMS_FORMAT_Email : sprintf(buffer,"Email"); break;
1196  case SMS_FORMAT_Pager : sprintf(buffer,"Pager"); break;
1197  }
1198  error = SaveBackupText(file, "", buffer, UseUnicode);
1199  if (error != ERR_NONE) return error;
1200  sprintf(buffer,"%c%cValidity = ",13,10);
1201  error = SaveBackupText(file, "", buffer, UseUnicode);
1202  if (error != ERR_NONE) return error;
1203  switch (SMSC->Validity.Relative) {
1204  case SMS_VALID_1_Hour : sprintf(buffer, "1hour" ); break;
1205  case SMS_VALID_6_Hours : sprintf(buffer, "6hours" ); break;
1206  case SMS_VALID_1_Day : sprintf(buffer, "24hours" ); break;
1207  case SMS_VALID_3_Days : sprintf(buffer, "72hours" ); break;
1208  case SMS_VALID_1_Week : sprintf(buffer, "1week" ); break;
1209  case SMS_VALID_Max_Time :
1210  default : sprintf(buffer,"MaximumTime" ); break;
1211  }
1212  error = SaveBackupText(file, "", buffer, UseUnicode);
1213  if (error != ERR_NONE) return error;
1214  sprintf(buffer,"%c%c%c%c",13,10,13,10);
1215  error = SaveBackupText(file, "", buffer, UseUnicode);
1216  if (error != ERR_NONE) return error;
1217 
1218  return ERR_NONE;
1219 }
1220 
1221 static GSM_Error SaveRingtoneEntry(FILE *file, GSM_Ringtone *ringtone, gboolean UseUnicode)
1222 {
1223  unsigned char *buffer=NULL;
1224  GSM_Error error;
1225 
1226  buffer = (unsigned char *)malloc(MAX(32, 2 * ringtone->NokiaBinary.Length) + 1);
1227  if (buffer == NULL)
1228  return ERR_MOREMEMORY;
1229 
1230  sprintf(buffer,"Location = %i%c%c",ringtone->Location,13,10);
1231  error = SaveBackupText(file, "", buffer, UseUnicode);
1232  if (error != ERR_NONE) {
1233  free(buffer);
1234  buffer=NULL;
1235  return error;
1236  }
1237  error = SaveBackupText(file, "Name", ringtone->Name, UseUnicode);
1238  if (error != ERR_NONE) {
1239  free(buffer);
1240  buffer=NULL;
1241  return error;
1242  }
1243  switch (ringtone->Format) {
1244  case RING_NOKIABINARY:
1245  EncodeHexBin(buffer,ringtone->NokiaBinary.Frame,ringtone->NokiaBinary.Length);
1246  SaveLinkedBackupText(file, "NokiaBinary", buffer, UseUnicode);
1247  break;
1248  case RING_MIDI:
1249  EncodeHexBin(buffer,ringtone->NokiaBinary.Frame,ringtone->NokiaBinary.Length);
1250  SaveLinkedBackupText(file, "Pure Midi", buffer, UseUnicode);
1251  break;
1252  case RING_MMF:
1253  EncodeHexBin(buffer,ringtone->NokiaBinary.Frame,ringtone->NokiaBinary.Length);
1254  SaveLinkedBackupText(file, "SMAF", buffer, UseUnicode);
1255  break;
1256  case RING_NOTETONE:
1257  break;
1258  }
1259  sprintf(buffer,"%c%c",13,10);
1260  error = SaveBackupText(file, "", buffer, UseUnicode);
1261  free(buffer);
1262  buffer=NULL;
1263 
1264  if (error != ERR_NONE) return error;
1265 
1266  return ERR_NONE;
1267 }
1268 
1269 static GSM_Error SaveOperatorEntry(FILE *file, GSM_Bitmap *bitmap, gboolean UseUnicode)
1270 {
1271  unsigned char buffer[1000]={0};
1272  GSM_Error error;
1273 
1274  sprintf(buffer,"[Operator]%c%c",13,10);
1275  error = SaveBackupText(file, "", buffer, UseUnicode);
1276  if (error != ERR_NONE) return error;
1277  sprintf(buffer,"Network = \"%s\"%c%c", bitmap->NetworkCode,13,10);
1278  error = SaveBackupText(file, "", buffer, UseUnicode);
1279  if (error != ERR_NONE) return error;
1280  error = SaveBitmapEntry(file, bitmap, UseUnicode);
1281  if (error != ERR_NONE) return error;
1282  sprintf(buffer,"%c%c",13,10);
1283  error = SaveBackupText(file, "", buffer, UseUnicode);
1284  if (error != ERR_NONE) return error;
1285 
1286  return ERR_NONE;
1287 }
1288 
1289 static GSM_Error SaveToDoEntry(FILE *file, GSM_ToDoEntry *ToDo, gboolean UseUnicode)
1290 {
1291  unsigned char buffer[1000]={0};
1292  int j;
1293  GSM_Error error;
1294 
1295  sprintf(buffer,"Location = %i%c%c",ToDo->Location,13,10);
1296  error = SaveBackupText(file, "", buffer, UseUnicode);
1297  if (error != ERR_NONE) return error;
1298  error = SaveCalendarType(file, ToDo->Type, UseUnicode);
1299  if (error != ERR_NONE) return error;
1300  switch (ToDo->Priority) {
1301  case GSM_Priority_High:
1302  sprintf(buffer,"Priority = High%c%c",13,10);
1303  break;
1304  case GSM_Priority_Medium:
1305  sprintf(buffer,"Priority = Medium%c%c",13,10);
1306  break;
1307  case GSM_Priority_Low:
1308  sprintf(buffer,"Priority = Low%c%c",13,10);
1309  break;
1310  default:
1311  break;
1312  }
1313  error = SaveBackupText(file, "", buffer, UseUnicode);
1314  if (error != ERR_NONE) return error;
1315 
1316  for (j=0;j<ToDo->EntriesNum;j++) {
1317  switch (ToDo->Entries[j].EntryType) {
1318  case TODO_END_DATETIME:
1319  error = SaveBackupText(file, "", "DueTime", UseUnicode);
1320  if (error != ERR_NONE) return error;
1321  error = SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode);
1322  if (error != ERR_NONE) return error;
1323  break;
1324  case TODO_START_DATETIME:
1325  error = SaveBackupText(file, "", "StartTime", UseUnicode);
1326  if (error != ERR_NONE) return error;
1327  error = SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode);
1328  if (error != ERR_NONE) return error;
1329  break;
1331  error = SaveBackupText(file, "", "CompletedTime", UseUnicode);
1332  if (error != ERR_NONE) return error;
1333  error = SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode);
1334  if (error != ERR_NONE) return error;
1335  break;
1336  case TODO_COMPLETED:
1337  sprintf(buffer,"Completed = %s%c%c",ToDo->Entries[j].Number == 1 ? "yes" : "no" ,13,10);
1338  error = SaveBackupText(file, "", buffer, UseUnicode);
1339  if (error != ERR_NONE) return error;
1340  break;
1341  case TODO_ALARM_DATETIME:
1342  error = SaveBackupText(file, "", "Alarm", UseUnicode);
1343  if (error != ERR_NONE) return error;
1344  error = SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode);
1345  if (error != ERR_NONE) return error;
1346  break;
1348  error = SaveBackupText(file, "", "SilentAlarm", UseUnicode);
1349  if (error != ERR_NONE) return error;
1350  error = SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode);
1351  if (error != ERR_NONE) return error;
1352  break;
1353  case TODO_LAST_MODIFIED:
1354  error = SaveBackupText(file, "", "LastModified", UseUnicode);
1355  if (error != ERR_NONE) return error;
1356  error = SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode);
1357  if (error != ERR_NONE) return error;
1358  break;
1359  case TODO_TEXT:
1360  error = SaveBackupText(file, "Text", ToDo->Entries[j].Text, UseUnicode);
1361  if (error != ERR_NONE) return error;
1362  break;
1363  case TODO_PRIVATE:
1364  sprintf(buffer,"Private = %i%c%c",ToDo->Entries[j].Number,13,10);
1365  error = SaveBackupText(file, "", buffer, UseUnicode);
1366  if (error != ERR_NONE) return error;
1367  break;
1368  case TODO_CATEGORY:
1369  sprintf(buffer,"Category = %i%c%c",ToDo->Entries[j].Number,13,10);
1370  error = SaveBackupText(file, "", buffer, UseUnicode);
1371  if (error != ERR_NONE) return error;
1372  break;
1373  case TODO_CONTACTID:
1374  sprintf(buffer,"ContactID = %i%c%c",ToDo->Entries[j].Number,13,10);
1375  error = SaveBackupText(file, "", buffer, UseUnicode);
1376  if (error != ERR_NONE) return error;
1377  break;
1378  case TODO_PHONE:
1379  error = SaveBackupText(file, "Phone", ToDo->Entries[j].Text, UseUnicode);
1380  if (error != ERR_NONE) return error;
1381  break;
1382  case TODO_DESCRIPTION:
1383  error = SaveBackupText(file, "Description", ToDo->Entries[j].Text, UseUnicode);
1384  if (error != ERR_NONE) return error;
1385  break;
1386  case TODO_LOCATION:
1387  error = SaveBackupText(file, "EventLocation", ToDo->Entries[j].Text, UseUnicode);
1388  if (error != ERR_NONE) return error;
1389  break;
1390  case TODO_LUID:
1391  error = SaveBackupText(file, "LUID", ToDo->Entries[j].Text, UseUnicode);
1392  if (error != ERR_NONE) return error;
1393  break;
1394  }
1395  }
1396  sprintf(buffer,"%c%c",13,10);
1397  error = SaveBackupText(file, "", buffer, UseUnicode);
1398  if (error != ERR_NONE) return error;
1399 
1400  return ERR_NONE;
1401 }
1402 
1403 static GSM_Error SaveProfileEntry(FILE *file, GSM_Profile *Profile, gboolean UseUnicode)
1404 {
1405  int j=0,k=0;
1406  gboolean special=FALSE;
1407  unsigned char buffer[1000]={0};
1408  GSM_Error error;
1409 
1410  sprintf(buffer,"Location = %i%c%c",Profile->Location,13,10);
1411  error = SaveBackupText(file, "", buffer, UseUnicode);
1412  if (error != ERR_NONE) return error;
1413  error = SaveBackupText(file, "Name",Profile->Name, UseUnicode);
1414  if (error != ERR_NONE) return error;
1415 
1416  if (Profile->DefaultName) {
1417  sprintf(buffer,"DefaultName = TRUE%c%c",13,10);
1418  error = SaveBackupText(file, "", buffer, UseUnicode);
1419  if (error != ERR_NONE) return error;
1420  }
1421  if (Profile->HeadSetProfile) {
1422  sprintf(buffer,"HeadSetProfile = TRUE%c%c",13,10);
1423  error = SaveBackupText(file, "", buffer, UseUnicode);
1424  if (error != ERR_NONE) return error;
1425  }
1426  if (Profile->CarKitProfile) {
1427  sprintf(buffer,"CarKitProfile = TRUE%c%c",13,10);
1428  error = SaveBackupText(file, "", buffer, UseUnicode);
1429  if (error != ERR_NONE) return error;
1430  }
1431 
1432  for (j=0;j<Profile->FeaturesNumber;j++) {
1433  sprintf(buffer,"Feature%02i = ",j);
1434  error = SaveBackupText(file, "", buffer, UseUnicode);
1435  if (error != ERR_NONE) return error;
1436  special = FALSE;
1437  switch (Profile->FeatureID[j]) {
1438  case Profile_MessageToneID:
1439  case Profile_RingtoneID:
1440  special = TRUE;
1441  if (Profile->FeatureID[j] == Profile_RingtoneID) {
1442  sprintf(buffer,"RingtoneID%c%c",13,10);
1443  } else {
1444  sprintf(buffer,"MessageToneID%c%c",13,10);
1445  }
1446  error = SaveBackupText(file, "", buffer, UseUnicode);
1447  if (error != ERR_NONE) return error;
1448  sprintf(buffer,"Value%02i = %i%c%c",j,Profile->FeatureValue[j],13,10);
1449  error = SaveBackupText(file, "", buffer, UseUnicode);
1450  if (error != ERR_NONE) return error;
1451  break;
1452  case Profile_CallerGroups:
1453  special = TRUE;
1454  sprintf(buffer,"CallerGroups%c%c",13,10);
1455  error = SaveBackupText(file, "", buffer, UseUnicode);
1456  if (error != ERR_NONE) return error;
1457  sprintf(buffer,"Value%02i = ",j);
1458  error = SaveBackupText(file, "", buffer, UseUnicode);
1459  if (error != ERR_NONE) return error;
1460  for (k=0;k<5;k++) {
1461  if (Profile->CallerGroups[k]) {
1462  sprintf(buffer,"%i",k);
1463  error = SaveBackupText(file, "", buffer, UseUnicode);
1464  if (error != ERR_NONE) return error;
1465  }
1466  }
1467  sprintf(buffer,"%c%c",13,10);
1468  error = SaveBackupText(file, "", buffer, UseUnicode);
1469  if (error != ERR_NONE) return error;
1470  break;
1472  special = TRUE;
1473  sprintf(buffer,"ScreenSaverNumber%c%c",13,10);
1474  error = SaveBackupText(file, "", buffer, UseUnicode);
1475  if (error != ERR_NONE) return error;
1476  sprintf(buffer,"Value%02i = %i%c%c",j,Profile->FeatureValue[j],13,10);
1477  error = SaveBackupText(file, "", buffer, UseUnicode);
1478  if (error != ERR_NONE) return error;
1479  break;
1480  case Profile_CallAlert : sprintf(buffer,"IncomingCallAlert%c%c",13,10); break;
1481  case Profile_RingtoneVolume : sprintf(buffer,"RingtoneVolume%c%c",13,10); break;
1482  case Profile_Vibration : sprintf(buffer,"Vibrating%c%c",13,10); break;
1483  case Profile_MessageTone : sprintf(buffer,"MessageTone%c%c",13,10); break;
1484  case Profile_KeypadTone : sprintf(buffer,"KeypadTones%c%c",13,10); break;
1485  case Profile_WarningTone : sprintf(buffer,"WarningTones%c%c",13,10); break;
1486  case Profile_ScreenSaver : sprintf(buffer,"ScreenSaver%c%c",13,10); break;
1487  case Profile_ScreenSaverTime : sprintf(buffer,"ScreenSaverTimeout%c%c",13,10); break;
1488  case Profile_AutoAnswer : sprintf(buffer,"AutomaticAnswer%c%c",13,10); break;
1489  case Profile_Lights : sprintf(buffer,"Lights%c%c",13,10); break;
1490  default : special = TRUE;
1491  }
1492  if (!special) {
1493  error = SaveBackupText(file, "", buffer, UseUnicode);
1494  if (error != ERR_NONE) return error;
1495  sprintf(buffer,"Value%02i = ",j);
1496  error = SaveBackupText(file, "", buffer, UseUnicode);
1497  if (error != ERR_NONE) return error;
1498  switch (Profile->FeatureValue[j]) {
1499  case PROFILE_VOLUME_LEVEL1 :
1500  case PROFILE_KEYPAD_LEVEL1 : sprintf(buffer,"Level1%c%c",13,10); break;
1501  case PROFILE_VOLUME_LEVEL2 :
1502  case PROFILE_KEYPAD_LEVEL2 : sprintf(buffer,"Level2%c%c",13,10); break;
1503  case PROFILE_VOLUME_LEVEL3 :
1504  case PROFILE_KEYPAD_LEVEL3 : sprintf(buffer,"Level3%c%c",13,10); break;
1505  case PROFILE_VOLUME_LEVEL4 : sprintf(buffer,"Level4%c%c",13,10); break;
1506  case PROFILE_VOLUME_LEVEL5 : sprintf(buffer,"Level5%c%c",13,10); break;
1507  case PROFILE_MESSAGE_NOTONE :
1508  case PROFILE_AUTOANSWER_OFF :
1509  case PROFILE_LIGHTS_OFF :
1510  case PROFILE_SAVER_OFF :
1511  case PROFILE_WARNING_OFF :
1512  case PROFILE_CALLALERT_OFF :
1513  case PROFILE_VIBRATION_OFF :
1514  case PROFILE_KEYPAD_OFF : sprintf(buffer,"Off%c%c",13,10); break;
1515  case PROFILE_CALLALERT_RINGING : sprintf(buffer,"Ringing%c%c",13,10); break;
1516  case PROFILE_CALLALERT_RINGONCE : sprintf(buffer,"RingOnce%c%c",13,10); break;
1517  case PROFILE_CALLALERT_ASCENDING : sprintf(buffer,"Ascending%c%c",13,10); break;
1518  case PROFILE_CALLALERT_CALLERGROUPS : sprintf(buffer,"CallerGroups%c%c",13,10); break;
1519  case PROFILE_MESSAGE_STANDARD : sprintf(buffer,"Standard%c%c",13,10); break;
1520  case PROFILE_MESSAGE_SPECIAL : sprintf(buffer,"Special%c%c",13,10); break;
1522  case PROFILE_CALLALERT_BEEPONCE : sprintf(buffer,"BeepOnce%c%c",13,10); break;
1523  case PROFILE_MESSAGE_ASCENDING : sprintf(buffer,"Ascending%c%c",13,10); break;
1524  case PROFILE_MESSAGE_PERSONAL : sprintf(buffer,"Personal%c%c",13,10); break;
1525  case PROFILE_AUTOANSWER_ON :
1526  case PROFILE_WARNING_ON :
1527  case PROFILE_SAVER_ON :
1528  case PROFILE_VIBRATION_ON : sprintf(buffer,"On%c%c",13,10); break;
1529  case PROFILE_VIBRATION_FIRST : sprintf(buffer,"VibrateFirst%c%c",13,10); break;
1530  case PROFILE_LIGHTS_AUTO : sprintf(buffer,"Auto%c%c",13,10); break;
1531  case PROFILE_SAVER_TIMEOUT_5SEC : sprintf(buffer,"5Seconds%c%c",13,10); break;
1532  case PROFILE_SAVER_TIMEOUT_20SEC : sprintf(buffer,"20Seconds%c%c",13,10); break;
1533  case PROFILE_SAVER_TIMEOUT_1MIN : sprintf(buffer,"1Minute%c%c",13,10); break;
1534  case PROFILE_SAVER_TIMEOUT_2MIN : sprintf(buffer,"2Minutes%c%c",13,10); break;
1535  case PROFILE_SAVER_TIMEOUT_5MIN : sprintf(buffer,"5Minutes%c%c",13,10); break;
1536  case PROFILE_SAVER_TIMEOUT_10MIN : sprintf(buffer,"10Minutes%c%c",13,10); break;
1537  default : sprintf(buffer,"UNKNOWN%c%c",13,10);
1538  }
1539  error = SaveBackupText(file, "", buffer, UseUnicode);
1540  if (error != ERR_NONE) return error;
1541  }
1542  }
1543  sprintf(buffer,"%c%c",13,10);
1544  error = SaveBackupText(file, "", buffer, UseUnicode);
1545  if (error != ERR_NONE) return error;
1546 
1547  return ERR_NONE;
1548 }
1549 
1550 static GSM_Error SaveFMStationEntry(FILE *file, GSM_FMStation *FMStation, gboolean UseUnicode)
1551 {
1552  unsigned char buffer[1000]={0};
1553  GSM_Error error;
1554 
1555  sprintf(buffer,"Location = %i%c%c",FMStation->Location,13,10);
1556  error = SaveBackupText(file, "", buffer, UseUnicode);
1557  if (error != ERR_NONE) return error;
1558  error = SaveBackupText(file, "StationName", FMStation->StationName, UseUnicode);
1559  if (error != ERR_NONE) return error;
1560  sprintf(buffer,"Frequency = %f%c%c",FMStation->Frequency,13,10);
1561  error = SaveBackupText(file, "", buffer, UseUnicode);
1562  if (error != ERR_NONE) return error;
1563  sprintf(buffer,"%c%c",13,10);
1564  error = SaveBackupText(file, "", buffer, UseUnicode);
1565  if (error != ERR_NONE) return error;
1566 
1567  return ERR_NONE;
1568 }
1569 
1570 static GSM_Error SaveGPRSPointEntry(FILE *file, GSM_GPRSAccessPoint *GPRSPoint, gboolean UseUnicode)
1571 {
1572  unsigned char buffer[1000]={0};
1573  GSM_Error error;
1574 
1575  sprintf(buffer,"Location = %i%c%c",GPRSPoint->Location,13,10);
1576  error = SaveBackupText(file, "", buffer, UseUnicode);
1577  if (error != ERR_NONE) return error;
1578  error = SaveBackupText(file, "Name", GPRSPoint->Name, UseUnicode);
1579  if (error != ERR_NONE) return error;
1580  error = SaveBackupText(file, "URL", GPRSPoint->URL, UseUnicode);
1581  if (error != ERR_NONE) return error;
1582  if (GPRSPoint->Active) {
1583  sprintf(buffer,"Active = Yes%c%c",13,10);
1584  error = SaveBackupText(file, "", buffer, UseUnicode);
1585  if (error != ERR_NONE) return error;
1586  }
1587  sprintf(buffer,"%c%c",13,10);
1588  error = SaveBackupText(file, "", buffer, UseUnicode);
1589  if (error != ERR_NONE) return error;
1590 
1591  return ERR_NONE;
1592 }
1593 
1594 GSM_Error SaveBackup(const char *FileName, GSM_Backup *backup, gboolean UseUnicode)
1595 {
1596  int i=0;
1597  unsigned char buffer[1000]={0},checksum[200]={0};
1598  FILE *file;
1599  GSM_Error error;
1600 
1601  file = fopen(FileName, "wb");
1602  if (file == NULL) return ERR_CANTOPENFILE;
1603 
1604  if (UseUnicode) {
1605  sprintf(buffer,"%c%c", 0xFE, 0xFF);
1606  error = SaveBackupText(file, "", buffer, FALSE);
1607  if (error != ERR_NONE) goto done;
1608  }
1609 
1610  sprintf(buffer, BACKUP_MAIN_HEADER "%c%c", 13, 10);
1611  error = SaveBackupText(file, "", buffer, UseUnicode);
1612  if (error != ERR_NONE) goto done;
1613  sprintf(buffer, BACKUP_INFO_HEADER "%c%c", 13, 10);
1614  error = SaveBackupText(file, "", buffer, UseUnicode);
1615  if (error != ERR_NONE) goto done;
1616  sprintf(buffer,"[Backup]%c%c",13,10);
1617  error = SaveBackupText(file, "", buffer, UseUnicode);
1618  if (error != ERR_NONE) goto done;
1619  sprintf(buffer,"IMEI = \"%s\"%c%c",backup->IMEI,13,10);
1620  error = SaveBackupText(file, "", buffer, UseUnicode);
1621  if (error != ERR_NONE) goto done;
1622  sprintf(buffer,"Phone = \"%s\"%c%c",backup->Model,13,10);
1623  error = SaveBackupText(file, "", buffer, UseUnicode);
1624  if (error != ERR_NONE) goto done;
1625  if (backup->Creator[0] != 0) {
1626  sprintf(buffer,"Creator = \"%s\"%c%c",backup->Creator,13,10);
1627  error = SaveBackupText(file, "", buffer, UseUnicode);
1628  if (error != ERR_NONE) goto done;
1629  }
1630  if (backup->DateTimeAvailable) {
1631  error = SaveBackupText(file, "", "DateTime", UseUnicode);
1632  if (error != ERR_NONE) goto done;
1633  error = SaveVCalDateTime(file, &backup->DateTime, UseUnicode);
1634  if (error != ERR_NONE) goto done;
1635  }
1636  sprintf(buffer,"Format = 1.05%c%c",13,10);
1637  error = SaveBackupText(file, "", buffer, UseUnicode);
1638  if (error != ERR_NONE) goto done;
1639  sprintf(buffer,"%c%c",13,10);
1640  error = SaveBackupText(file, "", buffer, UseUnicode);
1641  if (error != ERR_NONE) goto done;
1642 
1643  i=0;
1644  while (backup->PhonePhonebook[i]!=NULL) {
1645  sprintf(buffer,"[PhonePBK%03i]%c%c",i+1,13,10);
1646  error = SaveBackupText(file, "", buffer, UseUnicode);
1647  if (error != ERR_NONE) goto done;
1648  error = SavePbkEntry(file, backup->PhonePhonebook[i], UseUnicode);
1649  if (error != ERR_NONE) goto done;
1650  i++;
1651  }
1652  i=0;
1653  while (backup->SIMPhonebook[i]!=NULL) {
1654  sprintf(buffer,"[SIMPBK%03i]%c%c",i+1,13,10);
1655  error = SaveBackupText(file, "", buffer, UseUnicode);
1656  if (error != ERR_NONE) goto done;
1657  error = SavePbkEntry(file, backup->SIMPhonebook[i], UseUnicode);
1658  if (error != ERR_NONE) goto done;
1659  i++;
1660  }
1661  i=0;
1662  while (backup->Calendar[i]!=NULL) {
1663  sprintf(buffer,"[Calendar%03i]%c%c",i+1,13,10);
1664  error = SaveBackupText(file, "", buffer, UseUnicode);
1665  if (error != ERR_NONE) goto done;
1666  error = SaveCalendarEntry(file, backup->Calendar[i], UseUnicode);
1667  if (error != ERR_NONE) goto done;
1668  i++;
1669  }
1670  i=0;
1671  while (backup->Note[i]!=NULL) {
1672  sprintf(buffer,"[Note%03i]%c%c",i+1,13,10);
1673  error = SaveBackupText(file, "", buffer, UseUnicode);
1674  if (error != ERR_NONE) goto done;
1675  error = SaveNoteEntry(file, backup->Note[i], UseUnicode);
1676  if (error != ERR_NONE) goto done;
1677  i++;
1678  }
1679  i=0;
1680  while (backup->CallerLogos[i]!=NULL) {
1681  sprintf(buffer,"[Caller%03i]%c%c",i+1,13,10);
1682  error = SaveBackupText(file, "", buffer, UseUnicode);
1683  if (error != ERR_NONE) goto done;
1684  error = SaveCallerEntry(file, backup->CallerLogos[i], UseUnicode);
1685  if (error != ERR_NONE) goto done;
1686  i++;
1687  }
1688  i=0;
1689  while (backup->SMSC[i]!=NULL) {
1690  sprintf(buffer,"[SMSC%03i]%c%c",i+1,13,10);
1691  error = SaveBackupText(file, "", buffer, UseUnicode);
1692  if (error != ERR_NONE) goto done;
1693  error = SaveSMSCEntry(file, backup->SMSC[i], UseUnicode);
1694  if (error != ERR_NONE) goto done;
1695  i++;
1696  }
1697  i=0;
1698  while (backup->WAPBookmark[i]!=NULL) {
1699  sprintf(buffer,"[WAPBookmark%03i]%c%c",i+1,13,10);
1700  error = SaveBackupText(file, "", buffer, UseUnicode);
1701  if (error != ERR_NONE) goto done;
1702  error = SaveWAPBookmarkEntry(file, backup->WAPBookmark[i], UseUnicode);
1703  if (error != ERR_NONE) goto done;
1704  i++;
1705  }
1706  i=0;
1707  while (backup->WAPSettings[i]!=NULL) {
1708  sprintf(buffer,"[WAPSettings%03i]%c%c",i+1,13,10);
1709  error = SaveBackupText(file, "", buffer, UseUnicode);
1710  if (error != ERR_NONE) goto done;
1711  error = SaveWAPSettingsEntry(file, backup->WAPSettings[i], UseUnicode);
1712  if (error != ERR_NONE) goto done;
1713  i++;
1714  }
1715  i=0;
1716  while (backup->MMSSettings[i]!=NULL) {
1717  sprintf(buffer,"[MMSSettings%03i]%c%c",i+1,13,10);
1718  error = SaveBackupText(file, "", buffer, UseUnicode);
1719  if (error != ERR_NONE) goto done;
1720  error = SaveWAPSettingsEntry(file, backup->MMSSettings[i], UseUnicode);
1721  if (error != ERR_NONE) goto done;
1722  i++;
1723  }
1724  i=0;
1725  while (backup->SyncMLSettings[i]!=NULL) {
1726  sprintf(buffer,"[SyncMLSettings%03i]%c%c",i+1,13,10);
1727  error = SaveBackupText(file, "", buffer, UseUnicode);
1728  if (error != ERR_NONE) goto done;
1729  error = SaveSyncMLSettingsEntry(file, backup->SyncMLSettings[i], UseUnicode);
1730  if (error != ERR_NONE) goto done;
1731  i++;
1732  }
1733  i=0;
1734  while (backup->ChatSettings[i]!=NULL) {
1735  sprintf(buffer,"[ChatSettings%03i]%c%c",i+1,13,10);
1736  error = SaveBackupText(file, "", buffer, UseUnicode);
1737  if (error != ERR_NONE) goto done;
1738  error = SaveChatSettingsEntry(file, backup->ChatSettings[i], UseUnicode);
1739  if (error != ERR_NONE) goto done;
1740  i++;
1741  }
1742  i=0;
1743  while (backup->Ringtone[i]!=NULL) {
1744  sprintf(buffer,"[Ringtone%03i]%c%c",i+1,13,10);
1745  error = SaveBackupText(file, "", buffer, UseUnicode);
1746  if (error != ERR_NONE) goto done;
1747  error = SaveRingtoneEntry(file, backup->Ringtone[i], UseUnicode);
1748  if (error != ERR_NONE) goto done;
1749  i++;
1750  }
1751  i=0;
1752  while (backup->ToDo[i]!=NULL) {
1753  sprintf(buffer,"[TODO%03i]%c%c",i+1,13,10);
1754  error = SaveBackupText(file, "", buffer, UseUnicode);
1755  if (error != ERR_NONE) goto done;
1756  error = SaveToDoEntry(file, backup->ToDo[i], UseUnicode);
1757  if (error != ERR_NONE) goto done;
1758  i++;
1759  }
1760  i=0;
1761  while (backup->Profiles[i]!=NULL) {
1762  sprintf(buffer,"[Profile%03i]%c%c",i+1,13,10);
1763  error = SaveBackupText(file, "", buffer, UseUnicode);
1764  if (error != ERR_NONE) goto done;
1765  error = SaveProfileEntry(file, backup->Profiles[i], UseUnicode);
1766  if (error != ERR_NONE) goto done;
1767  i++;
1768  }
1769  i=0;
1770  while (backup->FMStation[i]!=NULL) {
1771  sprintf(buffer,"[FMStation%03i]%c%c",i+1,13,10);
1772  error = SaveBackupText(file, "", buffer, UseUnicode);
1773  if (error != ERR_NONE) goto done;
1774  error = SaveFMStationEntry(file, backup->FMStation[i], UseUnicode);
1775  if (error != ERR_NONE) goto done;
1776  i++;
1777  }
1778  i=0;
1779  while (backup->GPRSPoint[i]!=NULL) {
1780  sprintf(buffer,"[GPRSPoint%03i]%c%c",i+1,13,10);
1781  error = SaveBackupText(file, "", buffer, UseUnicode);
1782  if (error != ERR_NONE) goto done;
1783  error = SaveGPRSPointEntry(file, backup->GPRSPoint[i], UseUnicode);
1784  if (error != ERR_NONE) goto done;
1785  i++;
1786  }
1787 
1788  if (backup->StartupLogo!=NULL) {
1789  error = SaveStartupEntry(file, backup->StartupLogo, UseUnicode);
1790  if (error != ERR_NONE) goto done;
1791  }
1792  if (backup->OperatorLogo!=NULL) {
1793  error = SaveOperatorEntry(file, backup->OperatorLogo, UseUnicode);
1794  if (error != ERR_NONE) goto done;
1795  }
1796 
1797  fclose(file);
1798 
1799  FindBackupChecksum(FileName, UseUnicode, checksum);
1800 
1801  file = fopen(FileName, "ab");
1802  if (file == NULL) return ERR_CANTOPENFILE;
1803  sprintf(buffer,"[Checksum]%c%c",13,10);
1804  error = SaveBackupText(file, "", buffer, UseUnicode);
1805  if (error != ERR_NONE) goto done;
1806  sprintf(buffer,"MD5=%s%c%c",checksum,13,10);
1807  error = SaveBackupText(file, "", buffer, UseUnicode);
1808  if (error != ERR_NONE) goto done;
1809 
1810  error = ERR_NONE;
1811 
1812 done:
1813  fclose(file);
1814 
1815  return error;
1816 }
1817 
1818 static void ReadPbkEntry(INI_Section *file_info, char *section, GSM_MemoryEntry *Pbk, gboolean UseUnicode)
1819 {
1820  unsigned char buffer[10000]={0};
1821  char *readvalue=NULL;
1822  int num=0,i=0;
1823  INI_Entry *e;
1824 
1825  Pbk->EntriesNum = 0;
1826  e = INI_FindLastSectionEntry(file_info, section, UseUnicode);
1827 
1828  while (e != NULL) {
1829  num = -1;
1830  if (UseUnicode) {
1831  sprintf(buffer,"%s",DecodeUnicodeString(e->EntryName));
1832  } else {
1833  sprintf(buffer,"%s",e->EntryName);
1834  }
1835  if (strlen(buffer) == 11) {
1836  if (strncasecmp("Entry", buffer, 5) == 0 &&
1837  strncasecmp("Type", buffer+7, 4) == 0) {
1838  num = atoi(buffer+5);
1839  }
1840  }
1841  e = e->Prev;
1842  if (num != -1) {
1843  Pbk->Entries[Pbk->EntriesNum].AddError = ERR_NONE;
1844  sprintf(buffer,"Entry%02iLocation",num);
1845  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1846  if (readvalue == NULL) {
1848  } else if (strcasecmp(readvalue, "Home") == 0) {
1850  } else if (strcasecmp(readvalue, "Work") == 0) {
1852  } else {
1854  }
1855  sprintf(buffer,"Entry%02iType",num);
1856  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1857  if (readvalue == NULL) {
1859  } else if (strcasecmp(readvalue,"NumberGeneral") == 0) {
1861  } else if (strcasecmp(readvalue,"NumberVideo") == 0) {
1863  } else if (strcasecmp(readvalue,"NumberMobileWork") == 0) {
1866  } else if (strcasecmp(readvalue,"NumberMobileHome") == 0) {
1869  } else if (strcasecmp(readvalue,"NumberMobile") == 0) {
1871  } else if (strcasecmp(readvalue,"NumberWork") == 0) {
1874  } else if (strcasecmp(readvalue,"NumberFax") == 0) {
1876  } else if (strcasecmp(readvalue,"NumberHome") == 0) {
1879  } else if (strcasecmp(readvalue,"NumberOther") == 0) {
1881  } else if (strcasecmp(readvalue,"NumberMessaging") == 0) {
1883  } else if (strcasecmp(readvalue,"NumberPager") == 0) {
1885  } else if (strcasecmp(readvalue,"Note") == 0) {
1887  } else if (strcasecmp(readvalue,"Postal") == 0) {
1889  } else if (strcasecmp(readvalue,"WorkPostal") == 0) {
1892  } else if (strcasecmp(readvalue,"Email") == 0) {
1894  } else if (strcasecmp(readvalue,"Email2") == 0) {
1896  } else if (strcasecmp(readvalue,"URL") == 0) {
1898  } else if (strcasecmp(readvalue,"FirstName") == 0) {
1900  } else if (strcasecmp(readvalue,"SecondName") == 0) {
1902  } else if (strcasecmp(readvalue,"NickName") == 0) {
1904  } else if (strcasecmp(readvalue,"FormalName") == 0) {
1906  } else if (strcasecmp(readvalue,"NamePrefix") == 0) {
1908  } else if (strcasecmp(readvalue,"NameSuffix") == 0) {
1910  } else if (strcasecmp(readvalue,"LastName") == 0) {
1912  } else if (strcasecmp(readvalue,"Company") == 0) {
1914  } else if (strcasecmp(readvalue,"JobTitle") == 0) {
1916  } else if (strcasecmp(readvalue,"Address") == 0) {
1918  } else if (strcasecmp(readvalue,"City") == 0) {
1920  } else if (strcasecmp(readvalue,"State") == 0) {
1922  } else if (strcasecmp(readvalue,"Zip") == 0) {
1924  } else if (strcasecmp(readvalue,"Country") == 0) {
1926  } else if (strcasecmp(readvalue,"WorkAddress") == 0) {
1929  } else if (strcasecmp(readvalue,"WorkCity") == 0) {
1932  } else if (strcasecmp(readvalue,"WorkState") == 0) {
1935  } else if (strcasecmp(readvalue,"WorkZip") == 0) {
1938  } else if (strcasecmp(readvalue,"WorkCountry") == 0) {
1941  } else if (strcasecmp(readvalue,"Custom1") == 0) {
1943  } else if (strcasecmp(readvalue,"Custom2") == 0) {
1945  } else if (strcasecmp(readvalue,"Custom3") == 0) {
1947  } else if (strcasecmp(readvalue,"Custom4") == 0) {
1949  } else if (strcasecmp(readvalue,"LUID") == 0) {
1951  } else if (strcasecmp(readvalue,"VOIP") == 0) {
1953  } else if (strcasecmp(readvalue,"SWIS") == 0) {
1955  } else if (strcasecmp(readvalue,"WVID") == 0) {
1957  } else if (strcasecmp(readvalue,"SIP") == 0) {
1959  } else if (strcasecmp(readvalue,"DTMF") == 0) {
1961  } else if (strcasecmp(readvalue,"Name") == 0) {
1963  } else if (strcasecmp(readvalue,"Category") == 0) {
1965  Pbk->Entries[Pbk->EntriesNum].Number = -1;
1966  sprintf(buffer,"Entry%02iNumber",num);
1967  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1968  if (readvalue!=NULL) {
1969  Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
1970  Pbk->EntriesNum ++;
1971  continue;
1972  }
1973  } else if (strcasecmp(readvalue,"Private") == 0) {
1974  Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Private;
1975  Pbk->Entries[Pbk->EntriesNum].Number = 0;
1976  sprintf(buffer,"Entry%02iNumber",num);
1977  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1978  if (readvalue!=NULL) {
1979  Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
1980  }
1981  Pbk->EntriesNum ++;
1982  continue;
1983  } else if (strcasecmp(readvalue,"CallerGroup") == 0) {
1985  Pbk->Entries[Pbk->EntriesNum].Number = 0;
1986  sprintf(buffer,"Entry%02iNumber",num);
1987  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1988  if (readvalue!=NULL) {
1989  Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
1990  }
1991  Pbk->EntriesNum ++;
1992  continue;
1993  } else if (strcasecmp(readvalue,"RingtoneID") == 0) {
1995  Pbk->Entries[Pbk->EntriesNum].Number = 0;
1996  sprintf(buffer,"Entry%02iNumber",num);
1997  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1998  if (readvalue!=NULL) {
1999  Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
2000  }
2001  Pbk->EntriesNum ++;
2002  continue;
2003  } else if (strcasecmp(readvalue,"PictureID") == 0) {
2005  Pbk->Entries[Pbk->EntriesNum].Number = 0;
2006  sprintf(buffer,"Entry%02iNumber",num);
2007  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2008  if (readvalue!=NULL) {
2009  Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
2010  }
2011  Pbk->EntriesNum ++;
2012  continue;
2013  } else if (strcasecmp(readvalue,"Date") == 0) {
2014  Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Date;
2015  sprintf(buffer,"Entry%02iText",num);
2016  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2017  if (readvalue != NULL) {
2018  ReadVCALDateTime(readvalue, &Pbk->Entries[Pbk->EntriesNum].Date);
2019  }
2020  Pbk->EntriesNum++;
2021  continue;
2022  } else if (strcasecmp(readvalue,"LastModified") == 0) {
2024  sprintf(buffer,"Entry%02iText",num);
2025  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2026  if (readvalue != NULL) {
2027  ReadVCALDateTime(readvalue, &Pbk->Entries[Pbk->EntriesNum].Date);
2028  }
2029  Pbk->EntriesNum++;
2030  continue;
2031  } else if (strcasecmp(readvalue,"BMPPhoto") == 0) {
2032  Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Photo;
2033  Pbk->Entries[Pbk->EntriesNum].Picture.Type = PICTURE_BMP;
2034  Pbk->Entries[Pbk->EntriesNum].Picture.Length = 0;
2035  Pbk->Entries[Pbk->EntriesNum].Picture.Buffer = NULL;
2036  goto loadpicture;
2037  } else if (strcasecmp(readvalue,"GIFPhoto") == 0) {
2038  Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Photo;
2039  Pbk->Entries[Pbk->EntriesNum].Picture.Type = PICTURE_GIF;
2040  Pbk->Entries[Pbk->EntriesNum].Picture.Length = 0;
2041  Pbk->Entries[Pbk->EntriesNum].Picture.Buffer = NULL;
2042  goto loadpicture;
2043  } else if (strcasecmp(readvalue,"JPEGPhoto") == 0) {
2044  Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Photo;
2045  Pbk->Entries[Pbk->EntriesNum].Picture.Type = PICTURE_JPG;
2046  Pbk->Entries[Pbk->EntriesNum].Picture.Length = 0;
2047  Pbk->Entries[Pbk->EntriesNum].Picture.Buffer = NULL;
2048  goto loadpicture;
2049  } else if (strcasecmp(readvalue,"ICOPhoto") == 0) {
2050  Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Photo;
2051  Pbk->Entries[Pbk->EntriesNum].Picture.Type = PICTURE_ICN;
2052  Pbk->Entries[Pbk->EntriesNum].Picture.Length = 0;
2053  Pbk->Entries[Pbk->EntriesNum].Picture.Buffer = NULL;
2054  goto loadpicture;
2055  } else if (strcasecmp(readvalue,"PNGPhoto") == 0) {
2056  Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Photo;
2057  Pbk->Entries[Pbk->EntriesNum].Picture.Type = PICTURE_PNG;
2058  Pbk->Entries[Pbk->EntriesNum].Picture.Length = 0;
2059  Pbk->Entries[Pbk->EntriesNum].Picture.Buffer = NULL;
2060  goto loadpicture;
2061  } else if (strcasecmp(readvalue,"Photo") == 0) {
2062  Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Photo;
2063  Pbk->Entries[Pbk->EntriesNum].Picture.Type = 0;
2064  Pbk->Entries[Pbk->EntriesNum].Picture.Length = 0;
2065  Pbk->Entries[Pbk->EntriesNum].Picture.Buffer = NULL;
2066  goto loadpicture;
2067  } else if (strcasecmp(readvalue,"PushToTalkID") == 0) {
2069  } else if (strcasecmp(readvalue,"UserID") == 0) {
2071  }
2072  goto loadtext;
2073 loadpicture:
2074  sprintf(buffer,"Entry%02iData",num);
2075  readvalue = ReadLinkedBackupText(file_info, section, buffer, UseUnicode);
2076  if (readvalue != NULL) {
2077  /* We allocate here more memory than is actually required */
2078  Pbk->Entries[Pbk->EntriesNum].Picture.Buffer = (char *)malloc(strlen(readvalue));
2079  if (Pbk->Entries[Pbk->EntriesNum].Picture.Buffer == NULL) {
2080  free(readvalue);
2081  break;
2082  }
2083 
2084  Pbk->Entries[Pbk->EntriesNum].Picture.Length =
2085  DecodeBASE64(readvalue, Pbk->Entries[Pbk->EntriesNum].Picture.Buffer, strlen(readvalue));
2086 
2087  free(readvalue);
2088  readvalue=NULL;
2089  }
2090 
2091  goto loaddone;
2092 loadtext:
2093  sprintf(buffer,"Entry%02iText",num);
2094  ReadBackupText(file_info, section, buffer, Pbk->Entries[Pbk->EntriesNum].Text,UseUnicode);
2095  dbgprintf(NULL, "text \"%s\", type %i\n",DecodeUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text),Pbk->Entries[Pbk->EntriesNum].EntryType);
2096  Pbk->Entries[Pbk->EntriesNum].VoiceTag = 0;
2097  sprintf(buffer,"Entry%02iVoiceTag",num);
2098  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2099  if (readvalue!=NULL) {
2100  Pbk->Entries[Pbk->EntriesNum].VoiceTag = atoi(readvalue);
2101  }
2102  i = 0;
2103  while (1) {
2104  Pbk->Entries[Pbk->EntriesNum].SMSList[i] = 0;
2105  sprintf(buffer,"Entry%02iSMSList%02i",num,i);
2106  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2107  if (readvalue==NULL) {
2108  free(readvalue);
2109  break;
2110  }
2111  Pbk->Entries[Pbk->EntriesNum].SMSList[i] = atoi(readvalue);
2112  free(readvalue);
2113  i++;
2114  }
2115 loaddone:
2116  Pbk->EntriesNum ++;
2117  if (Pbk->EntriesNum >= GSM_PHONEBOOK_ENTRIES) {
2118  Pbk->EntriesNum--;
2119  return;
2120  }
2121  }
2122  }
2123 }
2124 
2125 static void ReadCalendarType(INI_Section *file_info, char *section, GSM_CalendarNoteType *type, gboolean UseUnicode)
2126 {
2127  unsigned char buffer[10000]={0};
2128  char *readvalue=NULL;
2129 
2130  sprintf(buffer,"Type");
2131  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2132  *type = GSM_CAL_REMINDER;
2133  if (readvalue!=NULL) {
2134  if (strcasecmp(readvalue,"Call") == 0) {
2135  *type = GSM_CAL_CALL;
2136  } else if (strcasecmp(readvalue,"Meeting") == 0) {
2137  *type = GSM_CAL_MEETING;
2138  } else if (strcasecmp(readvalue,"Birthday") == 0) {
2139  *type = GSM_CAL_BIRTHDAY;
2140  } else if (strcasecmp(readvalue,"Memo") == 0) {
2141  *type = GSM_CAL_MEMO;
2142  } else if (strcasecmp(readvalue,"Travel") == 0) {
2143  *type = GSM_CAL_TRAVEL;
2144  } else if (strcasecmp(readvalue,"Vacation") == 0) {
2145  *type = GSM_CAL_VACATION;
2146  } else if (strcasecmp(readvalue,"DailyAlarm") == 0) {
2147  *type = GSM_CAL_DAILY_ALARM;
2148  } else if (strcasecmp(readvalue,"Alarm") == 0) {
2149  *type = GSM_CAL_ALARM;
2150  } else if (strcasecmp(readvalue,"Shopping") == 0) {
2151  *type = GSM_CAL_SHOPPING;
2152  } else if (strcasecmp(readvalue,"Training/Athletism") == 0) {
2153  *type = GSM_CAL_T_ATHL;
2154  } else if (strcasecmp(readvalue,"Training/BallGames") == 0) {
2155  *type = GSM_CAL_T_BALL;
2156  } else if (strcasecmp(readvalue,"Training/Cycling") == 0) {
2157  *type = GSM_CAL_T_CYCL;
2158  } else if (strcasecmp(readvalue,"Training/Budo") == 0) {
2159  *type = GSM_CAL_T_BUDO;
2160  } else if (strcasecmp(readvalue,"Training/Dance") == 0) {
2161  *type = GSM_CAL_T_DANC;
2162  } else if (strcasecmp(readvalue,"Training/ExtremeSports") == 0) {
2163  *type = GSM_CAL_T_EXTR;
2164  } else if (strcasecmp(readvalue,"Training/Football") == 0) {
2165  *type = GSM_CAL_T_FOOT;
2166  } else if (strcasecmp(readvalue,"Training/Golf") == 0) {
2167  *type = GSM_CAL_T_GOLF;
2168  } else if (strcasecmp(readvalue,"Training/Gym") == 0) {
2169  *type = GSM_CAL_T_GYM;
2170  } else if (strcasecmp(readvalue,"Training/HorseRaces") == 0) {
2171  *type = GSM_CAL_T_HORS;
2172  } else if (strcasecmp(readvalue,"Training/Hockey") == 0) {
2173  *type = GSM_CAL_T_HOCK;
2174  } else if (strcasecmp(readvalue,"Training/Races") == 0) {
2175  *type = GSM_CAL_T_RACE;
2176  } else if (strcasecmp(readvalue,"Training/Rugby") == 0) {
2177  *type = GSM_CAL_T_RUGB;
2178  } else if (strcasecmp(readvalue,"Training/Sailing") == 0) {
2179  *type = GSM_CAL_T_SAIL;
2180  } else if (strcasecmp(readvalue,"Training/StreetGames") == 0) {
2181  *type = GSM_CAL_T_STRE;
2182  } else if (strcasecmp(readvalue,"Training/Swimming") == 0) {
2183  *type = GSM_CAL_T_SWIM;
2184  } else if (strcasecmp(readvalue,"Training/Tennis") == 0) {
2185  *type = GSM_CAL_T_TENN;
2186  } else if (strcasecmp(readvalue,"Training/Travels") == 0) {
2187  *type = GSM_CAL_T_TRAV;
2188  } else if (strcasecmp(readvalue,"Training/WinterGames") == 0) {
2189  *type = GSM_CAL_T_WINT;
2190  } else if (strcasecmp(readvalue,"0") == 0) {
2191  *type = 0;
2192  }
2193  }
2194 }
2195 static GSM_Error ReadCalendarEntry(INI_Section *file_info, char *section, GSM_CalendarEntry *note, gboolean UseUnicode)
2196 {
2197  unsigned char buffer[10000]={0},buf[20]={0};
2198  char *readvalue=NULL;
2199  int rec=0,rec2=0;
2200 
2201  sprintf(buffer,"Location");
2202  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2203  if (readvalue!=NULL) note->Location = atoi(readvalue);
2204 
2205  ReadCalendarType(file_info,section, &(note->Type), UseUnicode);
2206 
2207  note->EntriesNum = 0;
2208  sprintf(buffer,"Text");
2209  if (ReadBackupText(file_info, section, buffer, note->Entries[note->EntriesNum].Text,UseUnicode)) {
2210  note->Entries[note->EntriesNum].EntryType = CAL_TEXT;
2211  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2212  note->EntriesNum++;
2213  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2214  }
2215  sprintf(buffer,"Description");
2216  if (ReadBackupText(file_info, section, buffer, note->Entries[note->EntriesNum].Text,UseUnicode)) {
2218  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2219  note->EntriesNum++;
2220  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2221  }
2222  sprintf(buffer,"LUID");
2223  if (ReadBackupText(file_info, section, buffer, note->Entries[note->EntriesNum].Text,UseUnicode)) {
2224  note->Entries[note->EntriesNum].EntryType = CAL_LUID;
2225  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2226  note->EntriesNum++;
2227  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2228  }
2229  sprintf(buffer,"Phone");
2230  if (ReadBackupText(file_info, section, buffer, note->Entries[note->EntriesNum].Text,UseUnicode)) {
2231  note->Entries[note->EntriesNum].EntryType = CAL_PHONE;
2232  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2233  note->EntriesNum++;
2234  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2235  }
2236  sprintf(buffer,"Private");
2237  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2238  if (readvalue!=NULL) {
2239  note->Entries[note->EntriesNum].Number = atoi(readvalue);
2240  note->Entries[note->EntriesNum].EntryType = CAL_PRIVATE;
2241  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2242  note->EntriesNum++;
2243  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2244  }
2245  sprintf(buffer,"EventLocation");
2246  if (ReadBackupText(file_info, section, buffer, note->Entries[note->EntriesNum].Text,UseUnicode)) {
2247  note->Entries[note->EntriesNum].EntryType = CAL_LOCATION;
2248  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2249  note->EntriesNum++;
2250  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2251  }
2252  sprintf(buffer,"ContactID");
2253  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2254  if (readvalue!=NULL) {
2255  note->Entries[note->EntriesNum].Number = atoi(readvalue);
2256  note->Entries[note->EntriesNum].EntryType = CAL_CONTACTID;
2257  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2258  note->EntriesNum++;
2259  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2260  }
2261  /* StartTime must be before Recurrance */
2262  sprintf(buffer,"StartTime");
2263  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2264  if (readvalue != NULL && ReadVCALDateTime(readvalue, &note->Entries[note->EntriesNum].Date)) {
2266  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2267  note->EntriesNum++;
2268  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2269  }
2270  sprintf(buffer,"Recurrance");
2271  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2272  if (readvalue!=NULL) {
2273  rec2 = -1;
2274  rec = atoi(readvalue);
2275  switch (rec) {
2276  case 1:
2277  rec2 = 1*24;
2278  break;
2279  case 7:
2280  rec2 = 7*24;
2281  break;
2282  case 14:
2283  rec2 = 14*24;
2284  break;
2285  case 30:
2286  case ((0xffff-1)/24):
2287  rec2 = 0xffff-1;
2288  break;
2289  case 365:
2290  rec2 = 0xffff;
2291  }
2292  if (rec2 != -1) {
2293  buf[0] = rec2 / 256;
2294  buf[1] = rec2 % 256;
2295  dbgprintf(NULL, "Setting recurrance %i\n",rec2);
2296  GSM_GetCalendarRecurranceRepeat(NULL, buf, NULL, note);
2297  }
2298  }
2299  sprintf(buffer,"StopTime");
2300  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2301  if (readvalue != NULL && ReadVCALDateTime(readvalue, &note->Entries[note->EntriesNum].Date)) {
2303  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2304  note->EntriesNum++;
2305  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2306  }
2307  /* This is for compatibility with older backup formats */
2308  sprintf(buffer,"Alarm");
2309  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2310  if (readvalue != NULL && ReadVCALDateTime(readvalue, &note->Entries[note->EntriesNum].Date)) {
2312  sprintf(buffer,"AlarmType");
2313  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2314  if (readvalue!=NULL)
2315  {
2316  if (strcasecmp(readvalue,"Silent") == 0) {
2318  }
2319  }
2320  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2321  note->EntriesNum++;
2322  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2323  }
2324  sprintf(buffer,"ToneAlarm");
2325  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2326  if (readvalue != NULL && ReadVCALDateTime(readvalue, &note->Entries[note->EntriesNum].Date)) {
2328  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2329  note->EntriesNum++;
2330  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2331  }
2332  sprintf(buffer,"SilentAlarm");
2333  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2334  if (readvalue != NULL && ReadVCALDateTime(readvalue, &note->Entries[note->EntriesNum].Date)) {
2336  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2337  note->EntriesNum++;
2338  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2339  }
2340  sprintf(buffer,"LastModified");
2341  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2342  if (readvalue != NULL && ReadVCALDateTime(readvalue, &note->Entries[note->EntriesNum].Date)) {
2344  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2345  note->EntriesNum++;
2346  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2347  }
2348 
2349  sprintf(buffer,"RepeatFrequency");
2350  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2351  if (readvalue!=NULL) {
2352  note->Entries[note->EntriesNum].Number = atoi(readvalue);
2354  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2355  note->EntriesNum++;
2356  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2357  }
2358  sprintf(buffer,"RepeatDayOfWeek");
2359  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2360  if (readvalue!=NULL) {
2361  note->Entries[note->EntriesNum].Number = atoi(readvalue);
2363  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2364  note->EntriesNum++;
2365  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2366  }
2367  sprintf(buffer,"RepeatDay");
2368  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2369  if (readvalue!=NULL) {
2370  note->Entries[note->EntriesNum].Number = atoi(readvalue);
2371  note->Entries[note->EntriesNum].EntryType = CAL_REPEAT_DAY;
2372  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2373  note->EntriesNum++;
2374  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2375  }
2376  sprintf(buffer,"RepeatWeekOfMonth");
2377  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2378  if (readvalue!=NULL) {
2379  note->Entries[note->EntriesNum].Number = atoi(readvalue);
2381  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2382  note->EntriesNum++;
2383  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2384  }
2385  sprintf(buffer,"RepeatMonth");
2386  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2387  if (readvalue!=NULL) {
2388  note->Entries[note->EntriesNum].Number = atoi(readvalue);
2390  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2391  note->EntriesNum++;
2392  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2393  }
2394  sprintf(buffer,"RepeatCount");
2395  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2396  if (readvalue!=NULL) {
2397  note->Entries[note->EntriesNum].Number = atoi(readvalue);
2399  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2400  note->EntriesNum++;
2401  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2402  }
2403  sprintf(buffer,"RepeatDayOfYear");
2404  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2405  if (readvalue!=NULL) {
2406  note->Entries[note->EntriesNum].Number = atoi(readvalue);
2408  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2409  note->EntriesNum++;
2410  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2411  }
2412  sprintf(buffer,"RepeatStartDate");
2413  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2414  if (readvalue != NULL && ReadVCALDateTime(readvalue, &note->Entries[note->EntriesNum].Date)) {
2416  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2417  note->EntriesNum++;
2418  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2419  }
2420  sprintf(buffer,"RepeatStopDate");
2421  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2422  if (readvalue != NULL && ReadVCALDateTime(readvalue, &note->Entries[note->EntriesNum].Date)) {
2424  note->Entries[note->EntriesNum].AddError = ERR_NONE;
2425  note->EntriesNum++;
2426  if (note->EntriesNum >= GSM_CALENDAR_ENTRIES) return ERR_MOREMEMORY;
2427  }
2428 
2429  return ERR_NONE;
2430 }
2431 
2432 static GSM_Error ReadToDoEntry(INI_Section *file_info, char *section, GSM_ToDoEntry *ToDo, gboolean UseUnicode)
2433 {
2434  unsigned char buffer[10000]={0};
2435  char *readvalue=NULL;
2436 
2437  ToDo->EntriesNum = 0;
2438 
2439  sprintf(buffer,"Location");
2440  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2441  if (readvalue!=NULL) ToDo->Location = atoi(readvalue);
2442 
2443  ReadCalendarType(file_info,section, &(ToDo->Type), UseUnicode);
2444 
2445  ToDo->Priority = GSM_Priority_High;
2446  sprintf(buffer,"Priority");
2447  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2448  if (readvalue!=NULL) {
2449  if (!strcmp(readvalue,"3") || !strcmp(readvalue,"Low")) {
2450  ToDo->Priority = GSM_Priority_Low;
2451  }
2452  if (!strcmp(readvalue,"2") || !strcmp(readvalue,"Medium")) {
2453  ToDo->Priority = GSM_Priority_Medium;
2454  }
2455  }
2456 
2457  sprintf(buffer,"StartTime");
2458  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2459  if (readvalue != NULL && ReadVCALDateTime(readvalue, &ToDo->Entries[ToDo->EntriesNum].Date)) {
2461  ToDo->EntriesNum++;
2462  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2463  }
2464 
2465  sprintf(buffer,"CompletedTime");
2466  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2467  if (readvalue != NULL && ReadVCALDateTime(readvalue, &ToDo->Entries[ToDo->EntriesNum].Date)) {
2469  ToDo->EntriesNum++;
2470  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2471  }
2472 
2473  sprintf(buffer,"Text");
2474  if (ReadBackupText(file_info, section, buffer, ToDo->Entries[ToDo->EntriesNum].Text,UseUnicode)) {
2475  ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_TEXT;
2476  ToDo->EntriesNum++;
2477  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2478  }
2479 
2480  sprintf(buffer,"Description");
2481  if (ReadBackupText(file_info, section, buffer, ToDo->Entries[ToDo->EntriesNum].Text,UseUnicode)) {
2483  ToDo->EntriesNum++;
2484  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2485  }
2486 
2487  sprintf(buffer,"EventLocation");
2488  if (ReadBackupText(file_info, section, buffer, ToDo->Entries[ToDo->EntriesNum].Text,UseUnicode)) {
2489  ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_LOCATION;
2490  ToDo->EntriesNum++;
2491  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2492  }
2493 
2494  sprintf(buffer,"LUID");
2495  if (ReadBackupText(file_info, section, buffer, ToDo->Entries[ToDo->EntriesNum].Text,UseUnicode)) {
2496  ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_LUID;
2497  ToDo->EntriesNum++;
2498  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2499  }
2500 
2501  sprintf(buffer,"Phone");
2502  if (ReadBackupText(file_info, section, buffer, ToDo->Entries[ToDo->EntriesNum].Text,UseUnicode)) {
2503  ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_PHONE;
2504  ToDo->EntriesNum++;
2505  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2506  }
2507 
2508  sprintf(buffer,"Private");
2509  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2510  if (readvalue!=NULL) {
2511  ToDo->Entries[ToDo->EntriesNum].Number = atoi(readvalue);
2512  ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_PRIVATE;
2513  ToDo->EntriesNum++;
2514  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2515  }
2516 
2517  sprintf(buffer,"Completed");
2518  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2519  if (readvalue!=NULL) {
2520  if (strncmp(readvalue, "yes", 3) == 0) {
2521  ToDo->Entries[ToDo->EntriesNum].Number = 1;
2522  } else {
2523  ToDo->Entries[ToDo->EntriesNum].Number = 0;
2524  }
2525  ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_COMPLETED;
2526  ToDo->EntriesNum++;
2527  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2528  }
2529 
2530  sprintf(buffer,"Category");
2531  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2532  if (readvalue!=NULL) {
2533  ToDo->Entries[ToDo->EntriesNum].Number = atoi(readvalue);
2534  ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_CATEGORY;
2535  ToDo->EntriesNum++;
2536  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2537  }
2538 
2539  sprintf(buffer,"ContactID");
2540  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2541  if (readvalue!=NULL) {
2542  ToDo->Entries[ToDo->EntriesNum].Number = atoi(readvalue);
2543  ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_CONTACTID;
2544  ToDo->EntriesNum++;
2545  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2546  }
2547 
2548  sprintf(buffer,"DueTime");
2549  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2550  if (readvalue != NULL && ReadVCALDateTime(readvalue, &ToDo->Entries[ToDo->EntriesNum].Date)) {
2552  ToDo->EntriesNum++;
2553  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2554  }
2555 
2556  sprintf(buffer,"LastModified");
2557  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2558  if (readvalue != NULL && ReadVCALDateTime(readvalue, &ToDo->Entries[ToDo->EntriesNum].Date)) {
2560  ToDo->EntriesNum++;
2561  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2562  }
2563 
2564  sprintf(buffer,"Alarm");
2565  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2566  if (readvalue != NULL && ReadVCALDateTime(readvalue, &ToDo->Entries[ToDo->EntriesNum].Date)) {
2568  ToDo->EntriesNum++;
2569  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2570  }
2571 
2572  sprintf(buffer,"SilentAlarm");
2573  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2574  if (readvalue != NULL && ReadVCALDateTime(readvalue, &ToDo->Entries[ToDo->EntriesNum].Date)) {
2576  ToDo->EntriesNum++;
2577  if (ToDo->EntriesNum >= GSM_TODO_ENTRIES) return ERR_MOREMEMORY;
2578  }
2579  return ERR_NONE;
2580 }
2581 
2582 static gboolean ReadBitmapEntry(INI_Section *file_info, char *section, GSM_Bitmap *bitmap, gboolean UseUnicode)
2583 {
2584  char *readvalue=NULL;
2585  unsigned char buffer[10000]={0};
2586  size_t Width=0, Height=0;
2587  size_t x=0, y=0;
2588 
2589  GSM_GetMaxBitmapWidthHeight(bitmap->Type, &Width, &Height);
2590  sprintf(buffer,"Width");
2591  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2592  if (readvalue==NULL) bitmap->BitmapWidth = Width; else bitmap->BitmapWidth = atoi(readvalue);
2593  sprintf(buffer,"Height");
2594  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2595  if (readvalue==NULL) bitmap->BitmapHeight = Height; else bitmap->BitmapHeight = atoi(readvalue);
2596  GSM_ClearBitmap(bitmap);
2597  for (y=0;y<bitmap->BitmapHeight;y++) {
2598  sprintf(buffer,"Bitmap%02i",(int)y);
2599  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2600  if (readvalue!=NULL) {
2601  for (x=0;x<bitmap->BitmapWidth;x++) {
2602  if (readvalue[x+1]=='#') GSM_SetPointBitmap(bitmap,x,y);
2603  }
2604  } else return FALSE;
2605  }
2606  return TRUE;
2607 }
2608 
2609 static void ReadCallerEntry(INI_Section *file_info, char *section, GSM_Bitmap *bitmap, gboolean UseUnicode)
2610 {
2611  unsigned char buffer[10000]={0};
2612  char *readvalue=NULL;
2613 
2614  bitmap->Type = GSM_CallerGroupLogo;
2615  bitmap->DefaultBitmap = !ReadBitmapEntry(file_info, section, bitmap, UseUnicode);
2616  if (bitmap->DefaultBitmap) {
2617  bitmap->BitmapWidth = 72;
2618  bitmap->BitmapHeight = 14;
2619  GSM_ClearBitmap(bitmap);
2620  }
2621  sprintf(buffer,"Name");
2622  ReadBackupText(file_info, section, buffer, bitmap->Text,UseUnicode);
2623  if (bitmap->Text[0] == 0x00 && bitmap->Text[1] == 0x00) {
2624  bitmap->DefaultName = TRUE;
2625  } else {
2626  bitmap->DefaultName = FALSE;
2627  }
2628  sprintf(buffer,"Ringtone");
2629  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2630  if (readvalue==NULL) {
2631  sprintf(buffer,"FileRingtone");
2632  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2633  if (readvalue==NULL) {
2634  bitmap->DefaultRingtone = TRUE;
2635  } else {
2636  DecodeHexBin (&bitmap->RingtoneID, readvalue, 2);
2637  bitmap->DefaultRingtone = FALSE;
2638  bitmap->FileSystemRingtone = TRUE;
2639  }
2640  } else {
2641  DecodeHexBin (&bitmap->RingtoneID, readvalue, 2);
2642  bitmap->DefaultRingtone = FALSE;
2643  bitmap->FileSystemRingtone = FALSE;
2644  }
2645  sprintf(buffer,"Enabled");
2646  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2647  bitmap->BitmapEnabled = TRUE;
2648  if (readvalue!=NULL) {
2649  if (strcasecmp(readvalue,"False") == 0) bitmap->BitmapEnabled = FALSE;
2650  }
2651  bitmap->FileSystemPicture = FALSE;
2652  /* FIXME */
2653 }
2654 
2655 static void ReadStartupEntry(INI_Section *file_info, char *section, GSM_Bitmap *bitmap, gboolean UseUnicode)
2656 {
2657  unsigned char buffer[10000]={0};
2658 
2659  sprintf(buffer,"Text");
2660  ReadBackupText(file_info, section, buffer, bitmap->Text,UseUnicode);
2661  if (bitmap->Text[0]!=0 || bitmap->Text[1]!=0) {
2662  bitmap->Type = GSM_WelcomeNote_Text;
2663  } else {
2664  bitmap->Type = GSM_StartupLogo;
2665  bitmap->Location = 1;
2666  ReadBitmapEntry(file_info, section, bitmap, UseUnicode);
2667 #ifdef DEBUG
2670 #endif
2671  }
2672 }
2673 
2674 static void ReadWAPBookmarkEntry(INI_Section *file_info, char *section, GSM_WAPBookmark *bookmark, gboolean UseUnicode)
2675 {
2676  unsigned char buffer[10000]={0};
2677 
2678  sprintf(buffer,"URL");
2679  ReadBackupText(file_info, section, buffer, bookmark->Address,UseUnicode);
2680  sprintf(buffer,"Title");
2681  ReadBackupText(file_info, section, buffer, bookmark->Title,UseUnicode);
2682 }
2683 
2684 static void ReadOperatorEntry(INI_Section *file_info, char *section, GSM_Bitmap *bitmap, gboolean UseUnicode)
2685 {
2686  unsigned char buffer[10000]={0};
2687  char *readvalue=NULL;
2688 
2689  sprintf(buffer,"Network");
2690  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2691  memcpy(bitmap->NetworkCode, readvalue + 1, 6);
2692  bitmap->NetworkCode[6] = 0;
2693  bitmap->Type = GSM_OperatorLogo;
2694  ReadBitmapEntry(file_info, section, bitmap, UseUnicode);
2695 }
2696 
2697 static void ReadSMSCEntry(INI_Section *file_info, char *section, GSM_SMSC *SMSC, gboolean UseUnicode)
2698 {
2699  unsigned char buffer[10000]={0};
2700  char *readvalue=NULL;
2701 
2702  sprintf(buffer,"Name");
2703  ReadBackupText(file_info, section, buffer, SMSC->Name,UseUnicode);
2704  sprintf(buffer,"Number");
2705  ReadBackupText(file_info, section, buffer, SMSC->Number,UseUnicode);
2706  sprintf(buffer,"DefaultNumber");
2707  ReadBackupText(file_info, section, buffer, SMSC->DefaultNumber,UseUnicode);
2708  sprintf(buffer,"Format");
2709  SMSC->Format = SMS_FORMAT_Text;
2710  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2711  if (readvalue!=NULL) {
2712  if (strcasecmp(readvalue,"Fax") == 0) {
2713  SMSC->Format = SMS_FORMAT_Fax;
2714  } else if (strcasecmp(readvalue,"Email") == 0) {
2715  SMSC->Format = SMS_FORMAT_Email;
2716  } else if (strcasecmp(readvalue,"Pager") == 0) {
2717  SMSC->Format = SMS_FORMAT_Pager;
2718  }
2719  }
2720  sprintf(buffer,"Validity");
2722  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2723  if (readvalue!=NULL) {
2724  if (strcasecmp(readvalue,"1hour") == 0) {
2726  } else if (strcasecmp(readvalue,"6hours") == 0) {
2728  } else if (strcasecmp(readvalue,"24hours") == 0) {
2730  } else if (strcasecmp(readvalue,"72hours") == 0) {
2732  } else if (strcasecmp(readvalue,"1week") == 0) {
2734  }
2735  }
2736 }
2737 
2738 static void ReadWAPSettingsEntry(INI_Section *file_info, char *section, GSM_MultiWAPSettings *settings, gboolean UseUnicode)
2739 {
2740  unsigned char buffer[10000]={0}, *readvalue=NULL;
2741  int num=0;
2742  INI_Entry *e;
2743 
2745  sprintf(buffer,"Bearer");
2746  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2747  if (readvalue!=NULL) {
2748  if (strcasecmp(readvalue,"SMS") == 0) {
2750  } else if (strcasecmp(readvalue,"GPRS") == 0) {
2752  } else if (strcasecmp(readvalue,"USSD") == 0) {
2754  }
2755  }
2756 
2757  settings->Active = FALSE;
2758  sprintf(buffer,"Active");
2759  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2760  if (readvalue!=NULL) {
2761  if (strcasecmp(readvalue,"Yes") == 0) settings->Active = TRUE;
2762  }
2763 
2764  settings->ReadOnly = FALSE;
2765  sprintf(buffer,"ReadOnly");
2766  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2767  if (readvalue!=NULL) {
2768  if (strcasecmp(readvalue,"Yes") == 0) settings->ReadOnly = TRUE;
2769  }
2770 
2771  sprintf(buffer,"Proxy");
2772  ReadBackupText(file_info, section, buffer, settings->Proxy,UseUnicode);
2773  sprintf(buffer,"ProxyPort");
2774  settings->ProxyPort = 8080;
2775  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2776  if (readvalue!=NULL) settings->ProxyPort = atoi(readvalue);
2777  sprintf(buffer,"Proxy2");
2778  ReadBackupText(file_info, section, buffer, settings->Proxy2,UseUnicode);
2779  sprintf(buffer,"Proxy2Port");
2780  settings->Proxy2Port = 8080;
2781  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2782  if (readvalue!=NULL) settings->Proxy2Port = atoi(readvalue);
2783 
2784  settings->Number = 0;
2785  e = INI_FindLastSectionEntry(file_info, section, UseUnicode);
2786  while (e != NULL) {
2787  num = -1;
2788  if (UseUnicode) {
2789  sprintf(buffer,"%s",DecodeUnicodeString(e->EntryName));
2790  } else {
2791  sprintf(buffer,"%s",e->EntryName);
2792  }
2793  if (strlen(buffer) == 7) {
2794  if (strncasecmp("Title", buffer,5) == 0) num = atoi(buffer+5);
2795  }
2796  e = e->Prev;
2797  if (num != -1) {
2798  sprintf(buffer,"Title%02i",num);
2799  ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].Title,UseUnicode);
2800  sprintf(buffer,"HomePage%02i",num);
2801  ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].HomePage,UseUnicode);
2802  sprintf(buffer,"Type%02i",num);
2803  settings->Settings[settings->Number].IsContinuous = TRUE;
2804  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2805  if (readvalue!=NULL) {
2806  if (strcasecmp(readvalue,"Temporary") == 0) settings->Settings[settings->Number].IsContinuous = FALSE;
2807  }
2808  sprintf(buffer,"Security%02i",num);
2809  settings->Settings[settings->Number].IsSecurity = TRUE;
2810  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2811  if (readvalue!=NULL)
2812  {
2813  if (strcasecmp(readvalue,"Off") == 0) settings->Settings[settings->Number].IsSecurity = FALSE;
2814  }
2815  sprintf(buffer,"Bearer%02i",num);
2816  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2817  if (readvalue!=NULL)
2818  {
2819  if (strcasecmp(readvalue,"SMS") == 0) {
2820  settings->Settings[settings->Number].Bearer = WAPSETTINGS_BEARER_SMS;
2821  sprintf(buffer,"Server%02i",num);
2822  ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].Server,UseUnicode);
2823  sprintf(buffer,"Service%02i",num);
2824  ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].Service,UseUnicode);
2825  } else if ((strcasecmp(readvalue,"Data") == 0 || strcasecmp(readvalue,"GPRS") == 0)) {
2826  settings->Settings[settings->Number].Bearer = WAPSETTINGS_BEARER_DATA;
2827  if (strcasecmp(readvalue,"GPRS") == 0) settings->Settings[settings->Number].Bearer = WAPSETTINGS_BEARER_GPRS;
2828  sprintf(buffer,"Number%02i",num);
2829  ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].DialUp,UseUnicode);
2830  sprintf(buffer,"IP%02i",num);
2831  ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].IPAddress,UseUnicode);
2832  sprintf(buffer,"User%02i",num);
2833  ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].User,UseUnicode);
2834  sprintf(buffer,"Password%02i",num);
2835  ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].Password,UseUnicode);
2836  sprintf(buffer,"Authentication%02i",num);
2837  settings->Settings[settings->Number].IsNormalAuthentication = TRUE;
2838  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2839  if (readvalue!=NULL)
2840  {
2841  if (strcasecmp(readvalue,"Secure") == 0) settings->Settings[settings->Number].IsNormalAuthentication = FALSE;
2842  }
2843  sprintf(buffer,"CallSpeed%02i",num);
2844  settings->Settings[settings->Number].Speed = WAPSETTINGS_SPEED_14400;
2845  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2846  if (readvalue!=NULL)
2847  {
2848  if (strcasecmp(readvalue,"9600") == 0) settings->Settings[settings->Number].Speed = WAPSETTINGS_SPEED_9600;
2849  if (strcasecmp(readvalue,"auto") == 0) settings->Settings[settings->Number].Speed = WAPSETTINGS_SPEED_AUTO;
2850  }
2851  sprintf(buffer,"Login%02i",num);
2852  settings->Settings[settings->Number].ManualLogin = FALSE;
2853  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2854  if (readvalue!=NULL)
2855  {
2856  if (strcasecmp(readvalue,"Manual") == 0) settings->Settings[settings->Number].ManualLogin = TRUE;
2857  }
2858  sprintf(buffer,"CallType%02i",num);
2859  settings->Settings[settings->Number].IsISDNCall = TRUE;
2860  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2861  if (readvalue!=NULL)
2862  {
2863  if (strcasecmp(readvalue,"Analogue") == 0) settings->Settings[settings->Number].IsISDNCall = FALSE;
2864  }
2865  } else if (strcasecmp(readvalue,"USSD") == 0) {
2866  settings->Settings[settings->Number].Bearer = WAPSETTINGS_BEARER_USSD;
2867  sprintf(buffer,"ServiceCode%02i",num);
2868  ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].Code,UseUnicode);
2869  sprintf(buffer,"IP%02i",num);
2870  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2871  if (readvalue!=NULL) {
2872  settings->Settings[settings->Number].IsIP = TRUE;
2873  sprintf(buffer,"IP%02i",num);
2874  } else {
2875  settings->Settings[settings->Number].IsIP = FALSE;
2876  sprintf(buffer,"Number%02i",num);
2877  }
2878  ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].Service,UseUnicode);
2879  }
2880  }
2881  settings->Number++;
2882  }
2883  }
2884 }
2885 
2886 static void ReadRingtoneEntry(INI_Section *file_info, char *section, GSM_Ringtone *ringtone, gboolean UseUnicode)
2887 {
2888  unsigned char buffer[10000]={0}, *readvalue=NULL;
2889  char *buffer2=NULL;
2890 
2891  sprintf(buffer,"Name");
2892  ReadBackupText(file_info, section, buffer, ringtone->Name,UseUnicode);
2893  ringtone->Location = 0;
2894  sprintf(buffer,"Location");
2895  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2896  if (readvalue!=NULL) ringtone->Location = atoi(readvalue);
2897  sprintf(buffer,"NokiaBinary00");
2898  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2899  if (readvalue!=NULL) {
2900  ringtone->Format = RING_NOKIABINARY;
2901  buffer2 = ReadLinkedBackupText(file_info, section, "NokiaBinary", UseUnicode);
2902  DecodeHexBin (ringtone->NokiaBinary.Frame, buffer2, strlen(buffer2));
2903  ringtone->NokiaBinary.Length = strlen(buffer2)/2;
2904  free(buffer2);
2905  buffer2=NULL;
2906  }
2907  sprintf(buffer,"Pure Midi00");
2908  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2909  if (readvalue!=NULL) {
2910  ringtone->Format = RING_MIDI;
2911  buffer2 = ReadLinkedBackupText(file_info, section, "Pure Midi", UseUnicode);
2912  DecodeHexBin (ringtone->NokiaBinary.Frame, buffer2, strlen(buffer2));
2913  ringtone->NokiaBinary.Length = strlen(buffer2)/2;
2914  free(buffer2);
2915  buffer2=NULL;
2916  }
2917 
2918 }
2919 
2920 static void ReadProfileEntry(INI_Section *file_info, char *section, GSM_Profile *Profile, gboolean UseUnicode)
2921 {
2922  unsigned char buffer[10000]={0};
2923  char *readvalue=NULL;
2924  gboolean unknown;
2925  int num=0,j=0;
2926  INI_Entry *e;
2927 
2928  sprintf(buffer,"Name");
2929  ReadBackupText(file_info, section, buffer, Profile->Name,UseUnicode);
2930 
2931  sprintf(buffer,"Location");
2932  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2933  Profile->Location = atoi(readvalue);
2934 
2935  Profile->DefaultName = FALSE;
2936  sprintf(buffer,"DefaultName");
2937  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2938  if (readvalue!=NULL && strcasecmp(buffer,"TRUE") == 0) Profile->DefaultName = TRUE;
2939 
2940  Profile->HeadSetProfile = FALSE;
2941  sprintf(buffer,"HeadSetProfile");
2942  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2943  if (readvalue!=NULL && strcasecmp(buffer,"TRUE") == 0) Profile->HeadSetProfile = TRUE;
2944 
2945  Profile->CarKitProfile = FALSE;
2946  sprintf(buffer,"CarKitProfile");
2947  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2948  if (readvalue!=NULL && strcasecmp(buffer,"TRUE") == 0) Profile->CarKitProfile = TRUE;
2949 
2950  Profile->FeaturesNumber = 0;
2951  e = INI_FindLastSectionEntry(file_info, section, UseUnicode);
2952  while (e != NULL) {
2953  num = -1;
2954  if (UseUnicode) {
2955  sprintf(buffer,"%s",DecodeUnicodeString(e->EntryName));
2956  } else {
2957  sprintf(buffer,"%s",e->EntryName);
2958  }
2959  if (strlen(buffer) == 9) {
2960  if (strncasecmp("Feature", buffer, 7) == 0) num = atoi(buffer+7);
2961  }
2962  e = e->Prev;
2963  if (num != -1) {
2964  sprintf(buffer,"Feature%02i",num);
2965  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2966  if (readvalue==NULL) break;
2967  unknown = TRUE;
2968  if (strcasecmp(readvalue,"RingtoneID") == 0) {
2969  Profile->FeatureID[Profile->FeaturesNumber]=Profile_RingtoneID;
2970  sprintf(buffer,"Value%02i",num);
2971  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2972  Profile->FeatureValue[Profile->FeaturesNumber]=atoi(readvalue);
2973  Profile->FeaturesNumber++;
2974  } else if (strcasecmp(readvalue,"MessageToneID") == 0) {
2975  Profile->FeatureID[Profile->FeaturesNumber]=Profile_MessageToneID;
2976  sprintf(buffer,"Value%02i",num);
2977  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2978  Profile->FeatureValue[Profile->FeaturesNumber]=atoi(readvalue);
2979  Profile->FeaturesNumber++;
2980  } else if (strcasecmp(readvalue,"ScreenSaverNumber") == 0) {
2982  sprintf(buffer,"Value%02i",num);
2983  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2984  Profile->FeatureValue[Profile->FeaturesNumber]=atoi(readvalue);
2985  Profile->FeaturesNumber++;
2986  } else if (strcasecmp(readvalue,"CallerGroups") == 0) {
2987  Profile->FeatureID[Profile->FeaturesNumber]=Profile_CallerGroups;
2988  sprintf(buffer,"Value%02i",num);
2989  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2990  for (j = 0; j < 5; j++) {
2991  Profile->CallerGroups[j] = FALSE;
2992  if (strchr(readvalue, '1' + j) != NULL) {
2993  Profile->CallerGroups[j] = TRUE;
2994  }
2995  }
2996  Profile->FeaturesNumber++;
2997  } else if (strcasecmp(readvalue,"IncomingCallAlert") == 0) {
2998  Profile->FeatureID[Profile->FeaturesNumber]=Profile_CallAlert;
2999  unknown = FALSE;
3000  } else if (strcasecmp(readvalue,"RingtoneVolume") == 0) {
3001  Profile->FeatureID[Profile->FeaturesNumber]=Profile_RingtoneVolume;
3002  unknown = FALSE;
3003  } else if (strcasecmp(readvalue,"Vibrating") == 0) {
3004  Profile->FeatureID[Profile->FeaturesNumber]=Profile_Vibration;
3005  unknown = FALSE;
3006  } else if (strcasecmp(readvalue,"MessageTone") == 0) {
3007  Profile->FeatureID[Profile->FeaturesNumber]=Profile_MessageTone;
3008  unknown = FALSE;
3009  } else if (strcasecmp(readvalue,"KeypadTones") == 0) {
3010  Profile->FeatureID[Profile->FeaturesNumber]=Profile_KeypadTone;
3011  unknown = FALSE;
3012  } else if (strcasecmp(readvalue,"WarningTones") == 0) {
3013  Profile->FeatureID[Profile->FeaturesNumber]=Profile_WarningTone;
3014  unknown = FALSE;
3015  } else if (strcasecmp(readvalue,"ScreenSaver") == 0) {
3016  Profile->FeatureID[Profile->FeaturesNumber]=Profile_ScreenSaver;
3017  unknown = FALSE;
3018  } else if (strcasecmp(readvalue,"ScreenSaverTimeout") == 0) {
3020  unknown = FALSE;
3021  } else if (strcasecmp(readvalue,"AutomaticAnswer") == 0) {
3022  Profile->FeatureID[Profile->FeaturesNumber]=Profile_AutoAnswer;
3023  unknown = FALSE;
3024  } else if (strcasecmp(readvalue,"Lights") == 0) {
3025  Profile->FeatureID[Profile->FeaturesNumber]=Profile_Lights;
3026  unknown = FALSE;
3027  }
3028  if (!unknown) {
3029  sprintf(buffer,"Value%02i",num);
3030  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
3031  if (readvalue == NULL) {
3033  } else if (strcasecmp(readvalue,"Level1") == 0) {
3035  if (Profile->FeatureID[Profile->FeaturesNumber]==Profile_KeypadTone) {
3037  }
3038  } else if (strcasecmp(readvalue,"Level2") == 0) {
3040  if (Profile->FeatureID[Profile->FeaturesNumber]==Profile_KeypadTone) {
3042  }
3043  } else if (strcasecmp(readvalue,"Level3") == 0) {
3045  if (Profile->FeatureID[Profile->FeaturesNumber]==Profile_KeypadTone) {
3047  }
3048  } else if (strcasecmp(readvalue,"Level4") == 0) {
3050  } else if (strcasecmp(readvalue,"Level5") == 0) {
3052  } else if (strcasecmp(readvalue,"Off") == 0) {
3053  switch (Profile->FeatureID[Profile->FeaturesNumber]) {
3054  case Profile_MessageTone:
3056  break;
3057  case Profile_AutoAnswer:
3059  break;
3060  case Profile_Lights:
3061  Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_LIGHTS_OFF;
3062  break;
3063  case Profile_ScreenSaver:
3064  Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_SAVER_OFF;
3065  break;
3066  case Profile_WarningTone:
3067  Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_WARNING_OFF;
3068  break;
3069  case Profile_CallAlert:
3071  break;
3072  case Profile_Vibration:
3074  break;
3075  default:
3076  Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_KEYPAD_OFF;
3077  break;
3078  }
3079  } else if (strcasecmp(readvalue,"Ringing") == 0) {
3081  } else if (strcasecmp(readvalue,"BeepOnce") == 0) {
3083  if (Profile->FeatureID[Profile->FeaturesNumber]==Profile_MessageTone) {
3085  }
3086  } else if (strcasecmp(readvalue,"RingOnce") == 0) {
3088  } else if (strcasecmp(readvalue,"Ascending") == 0) {
3090  } else if (strcasecmp(readvalue,"CallerGroups") == 0) {
3092  } else if (strcasecmp(readvalue,"Standard") == 0) {
3094  } else if (strcasecmp(readvalue,"Special") == 0) {
3096  } else if (strcasecmp(readvalue,"Ascending") == 0) {
3098  } else if (strcasecmp(readvalue,"Personal") == 0) {
3100  } else if (strcasecmp(readvalue,"VibrateFirst") == 0) {
3102  } else if (strcasecmp(readvalue,"Auto") == 0) {
3103  Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_LIGHTS_AUTO;
3104  } else if (strcasecmp(readvalue,"5Seconds") == 0) {
3106  } else if (strcasecmp(readvalue,"20Seconds") == 0) {
3108  } else if (strcasecmp(readvalue,"1Minute") == 0) {
3110  } else if (strcasecmp(readvalue,"2Minutes") == 0) {
3112  } else if (strcasecmp(readvalue,"5Minutes") == 0) {
3114  } else if (strcasecmp(readvalue,"10Minutes") == 0) {
3116  } else if (strcasecmp(readvalue,"On") == 0) {
3117  switch (Profile->FeatureID[Profile->FeaturesNumber]) {
3118  case Profile_AutoAnswer:
3120  break;
3121  case Profile_WarningTone:
3122  Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_WARNING_ON;
3123  break;
3124  case Profile_ScreenSaver:
3125  Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_SAVER_ON;
3126  break;
3127  default:
3129  break;
3130  }
3131  } else unknown = TRUE;
3132  }
3133  if (!unknown) Profile->FeaturesNumber++;
3134  }
3135  }
3136 }
3137 
3138 static GSM_Error ReadFMStationEntry(INI_Section *file_info, char *section, GSM_FMStation *FMStation, gboolean UseUnicode)
3139 {
3140  unsigned char buffer[10000]={0}, *readvalue=NULL;
3141  char *endptr;
3142 
3143  FMStation->Location = 0;
3144  FMStation->Frequency = 0;
3145 
3146  sprintf(buffer,"Location");
3147  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
3148  if (readvalue!=NULL) FMStation->Location = atoi(readvalue);
3149 
3150  sprintf(buffer,"StationName");
3151  ReadBackupText(file_info, section, buffer, FMStation->StationName,UseUnicode);
3152 
3153  sprintf(buffer,"Frequency");
3154  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
3155  if (readvalue != NULL) {
3156  FMStation->Frequency = strtod(readvalue, &endptr);
3157  if (*endptr != 0) {
3158  return ERR_FILENOTSUPPORTED;
3159  }
3160  }
3161  return ERR_NONE;
3162 }
3163 
3164 static void ReadGPRSPointEntry(INI_Section *file_info, char *section, GSM_GPRSAccessPoint *GPRSPoint, gboolean UseUnicode)
3165 {
3166  unsigned char buffer[10000]={0}, *readvalue=NULL;
3167 
3168  GPRSPoint->Name[0] = 0;
3169  GPRSPoint->Name[1] = 0;
3170  GPRSPoint->URL[0] = 0;
3171  GPRSPoint->URL[1] = 0;
3172  GPRSPoint->Location = 0;
3173 
3174  GPRSPoint->Active = FALSE;
3175  sprintf(buffer,"Active");
3176  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
3177  if (readvalue!=NULL) {
3178  if (strcasecmp(readvalue,"Yes") == 0) GPRSPoint->Active = TRUE;
3179  }
3180 
3181  sprintf(buffer,"Location");
3182  readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
3183  if (readvalue!=NULL) GPRSPoint->Location = atoi(readvalue);
3184 
3185  sprintf(buffer,"Name");
3186  ReadBackupText(file_info, section, buffer, GPRSPoint->Name,UseUnicode);
3187 
3188  sprintf(buffer,"URL");
3189  ReadBackupText(file_info, section, buffer, GPRSPoint->URL,UseUnicode);
3190 }
3191 
3192 static void ReadNoteEntry(INI_Section *file_info, char *section, GSM_NoteEntry *Note, gboolean UseUnicode)
3193 {
3194  unsigned char buffer[100]={0};
3195 
3196  sprintf(buffer,"Text");
3197  ReadBackupText(file_info, section, buffer, Note->Text,UseUnicode);
3198 }
3199 
3200 GSM_Error LoadBackup(const char *FileName, GSM_Backup *backup)
3201 {
3202  INI_Section *file_info, *h;
3203  char buffer[100]={0}, *readvalue=NULL;
3204  int num=0;
3205  gboolean found;
3206  GSM_Error error;
3207  gboolean UseUnicode = FALSE;
3208  FILE *file;
3209  unsigned char guessbuffer[10]={0};
3210  size_t readbytes=0;
3211 
3212  file = fopen(FileName, "rb");
3213  if (file == NULL) return ERR_CANTOPENFILE;
3214  readbytes = fread(guessbuffer, 1, 9, file); /* Read the header of the file. */
3215  fclose(file);
3216  if (readbytes >= 2 && ((guessbuffer[0] == 0xFE && guessbuffer[1] == 0xFF) ||
3217  (guessbuffer[0] == 0xFF && guessbuffer[1] == 0xFE))) {
3218  UseUnicode = TRUE;
3219  }
3220 
3221 
3222  error = INI_ReadFile(FileName, UseUnicode, &file_info);
3223  if (error != ERR_NONE) {
3224  return error;
3225  }
3226 
3227  sprintf(buffer,"Backup");
3228  if (UseUnicode) EncodeUnicode(buffer,"Backup",6);
3229 
3230  readvalue = ReadCFGText(file_info, buffer, "Format", UseUnicode);
3231  /* Did we read anything? */
3232  if (readvalue == NULL) {
3233  error = ERR_FILENOTSUPPORTED;
3234  goto fail_error;
3235  }
3236  /* Is this format version supported ? */
3237  if (strcmp(readvalue,"1.01")!=0 && strcmp(readvalue,"1.02")!=0 &&
3238  strcmp(readvalue,"1.05")!=0 &&
3239  strcmp(readvalue,"1.03")!=0 && strcmp(readvalue,"1.04")!=0) {
3240  error = ERR_FILENOTSUPPORTED;
3241  goto fail_error;
3242  }
3243 
3244  readvalue = ReadCFGText(file_info, buffer, "IMEI", UseUnicode);
3245  if (readvalue!=NULL) {
3246  strncpy(backup->IMEI, readvalue, sizeof(backup->IMEI) - 1);
3247  backup->IMEI[sizeof(backup->IMEI) - 1] = 0;
3248  }
3249  readvalue = ReadCFGText(file_info, buffer, "Phone", UseUnicode);
3250  if (readvalue!=NULL) {
3251  strncpy(backup->Model, readvalue, sizeof(backup->Model) - 1);
3252  backup->Model[sizeof(backup->Model) - 1] = 0;
3253  }
3254  readvalue = ReadCFGText(file_info, buffer, "Creator", UseUnicode);
3255  if (readvalue!=NULL) {
3256  strncpy(backup->Creator,readvalue, sizeof(backup->Creator) - 1);
3257  backup->Creator[sizeof(backup->Creator) - 1] = 0;
3258  }
3259  readvalue = ReadCFGText(file_info, buffer, "DateTime", UseUnicode);
3260  if (readvalue != NULL && ReadVCALDateTime(readvalue, &backup->DateTime)) {
3261  backup->DateTimeAvailable = TRUE;
3262  }
3263 
3264  sprintf(buffer,"Checksum");
3265  if (UseUnicode) EncodeUnicode(buffer,"Checksum",8);
3266  readvalue = ReadCFGText(file_info, buffer, "MD5", UseUnicode);
3267  if (readvalue!=NULL) strcpy(backup->MD5Original,readvalue);
3268 
3269  num = 0;
3270  for (h = file_info; h != NULL; h = h->Next) {
3271  found = FALSE;
3272  if (UseUnicode) {
3273  EncodeUnicode(buffer,"Profile",7);
3274  if (mywstrncasecmp(buffer, h->SectionName, 7)) found = TRUE;
3275  } else {
3276  if (strncasecmp("Profile", h->SectionName, 7) == 0) found = TRUE;
3277  }
3278  if (found) {
3279  readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
3280  if (readvalue==NULL) break;
3281  if (num < GSM_BACKUP_MAX_PROFILES) {
3282  backup->Profiles[num] = (GSM_Profile *)malloc(sizeof(GSM_Profile));
3283  if (backup->Profiles[num] == NULL) {
3284  goto fail_memory;
3285  }
3286  backup->Profiles[num + 1] = NULL;
3287  } else {
3288  dbgprintf(NULL, "Increase GSM_BACKUP_MAX_PROFILES\n");
3289  goto fail_memory;
3290  }
3291  ReadProfileEntry(file_info, h->SectionName, backup->Profiles[num], UseUnicode);
3292  num++;
3293  }
3294  }
3295  num = 0;
3296  for (h = file_info; h != NULL; h = h->Next) {
3297  found = FALSE;
3298  if (UseUnicode) {
3299  EncodeUnicode(buffer,"PhonePBK",8);
3300  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3301  } else {
3302  if (strncasecmp("PhonePBK", h->SectionName, 8) == 0) found = TRUE;
3303  }
3304  if (found) {
3305  readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
3306  if (readvalue==NULL) break;
3307  if (num < GSM_BACKUP_MAX_PHONEPHONEBOOK) {
3308  backup->PhonePhonebook[num] = (GSM_MemoryEntry *)malloc(sizeof(GSM_MemoryEntry));
3309  if (backup->PhonePhonebook[num] == NULL) {
3310  goto fail_memory;
3311  }
3312  backup->PhonePhonebook[num + 1] = NULL;
3313  } else {
3314  dbgprintf(NULL, "Increase GSM_BACKUP_MAX_PHONEPHONEBOOK\n");
3315  goto fail_memory;
3316  }
3317  backup->PhonePhonebook[num]->Location = atoi (readvalue);
3318  backup->PhonePhonebook[num]->MemoryType = MEM_ME;
3319  ReadPbkEntry(file_info, h->SectionName, backup->PhonePhonebook[num],UseUnicode);
3320  dbgprintf(NULL, "number of entries = %i\n",backup->PhonePhonebook[num]->EntriesNum);
3321  num++;
3322  }
3323  }
3324  num = 0;
3325  for (h = file_info; h != NULL; h = h->Next) {
3326  found = FALSE;
3327  if (UseUnicode) {
3328  EncodeUnicode(buffer,"SIMPBK",6);
3329  if (mywstrncasecmp(buffer, h->SectionName, 6)) found = TRUE;
3330  } else {
3331  if (strncasecmp("SIMPBK", h->SectionName, 6) == 0) found = TRUE;
3332  }
3333  if (found) {
3334  readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
3335  if (readvalue==NULL) break;
3336  if (num < GSM_BACKUP_MAX_SIMPHONEBOOK) {
3337  backup->SIMPhonebook[num] = (GSM_MemoryEntry *)malloc(sizeof(GSM_MemoryEntry));
3338  if (backup->SIMPhonebook[num] == NULL) {
3339  goto fail_memory;
3340  }
3341  backup->SIMPhonebook[num + 1] = NULL;
3342  } else {
3343  dbgprintf(NULL, "Increase GSM_BACKUP_MAX_SIMPHONEBOOK\n");
3344  goto fail_memory;
3345  }
3346  backup->SIMPhonebook[num]->Location = atoi (readvalue);
3347  backup->SIMPhonebook[num]->MemoryType = MEM_SM;
3348  ReadPbkEntry(file_info, h->SectionName, backup->SIMPhonebook[num],UseUnicode);
3349  num++;
3350  }
3351  }
3352  num = 0;
3353  for (h = file_info; h != NULL; h = h->Next) {
3354  found = FALSE;
3355  if (UseUnicode) {
3356  EncodeUnicode(buffer,"Calendar",8);
3357  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3358  } else {
3359  if (strncasecmp("Calendar", h->SectionName, 8) == 0) found = TRUE;
3360  }
3361  if (found) {
3362  readvalue = ReadCFGText(file_info, h->SectionName, "Type", UseUnicode);
3363  if (readvalue==NULL) break;
3364  if (num < GSM_MAXCALENDARTODONOTES) {
3365  backup->Calendar[num] = (GSM_CalendarEntry *)malloc(sizeof(GSM_CalendarEntry));
3366  if (backup->Calendar[num] == NULL) {
3367  goto fail_memory;
3368  }
3369  backup->Calendar[num + 1] = NULL;
3370  } else {
3371  dbgprintf(NULL, "Increase GSM_MAXCALENDARTODONOTES\n");
3372  goto fail_memory;
3373  }
3374  backup->Calendar[num]->Location = num + 1;
3375  error = ReadCalendarEntry(file_info, h->SectionName, backup->Calendar[num],UseUnicode);
3376  if (error != ERR_NONE) {
3377  goto fail_error;
3378  }
3379  num++;
3380  }
3381  }
3382  num = 0;
3383  for (h = file_info; h != NULL; h = h->Next) {
3384  found = FALSE;
3385  if (UseUnicode) {
3386  EncodeUnicode(buffer,"Caller",6);
3387  if (mywstrncasecmp(buffer, h->SectionName, 6)) found = TRUE;
3388  } else {
3389  if (strncasecmp("Caller", h->SectionName, 6) == 0) found = TRUE;
3390  }
3391  if (found) {
3392  readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
3393  if (readvalue==NULL) break;
3394  if (num < GSM_BACKUP_MAX_CALLER) {
3395  backup->CallerLogos[num] = (GSM_Bitmap *)malloc(sizeof(GSM_Bitmap));
3396  if (backup->CallerLogos[num] == NULL) {
3397  goto fail_memory;
3398  }
3399  backup->CallerLogos[num + 1] = NULL;
3400  } else {
3401  dbgprintf(NULL, "Increase GSM_BACKUP_MAX_CALLER\n");
3402  goto fail_memory;
3403  }
3404  backup->CallerLogos[num]->Location = atoi (readvalue);
3405  ReadCallerEntry(file_info, h->SectionName, backup->CallerLogos[num],UseUnicode);
3406  num++;
3407  }
3408  }
3409  num = 0;
3410  for (h = file_info; h != NULL; h = h->Next) {
3411  found = FALSE;
3412  if (UseUnicode) {
3413  EncodeUnicode(buffer,"SMSC",4);
3414  if (mywstrncasecmp(buffer, h->SectionName, 4)) found = TRUE;
3415  } else {
3416  if (strncasecmp("SMSC", h->SectionName, 4) == 0) found = TRUE;
3417  }
3418  if (found) {
3419  readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
3420  if (readvalue==NULL) break;
3421  if (num < GSM_BACKUP_MAX_SMSC) {
3422  backup->SMSC[num] = (GSM_SMSC *)malloc(sizeof(GSM_SMSC));
3423  if (backup->SMSC[num] == NULL) {
3424  goto fail_memory;
3425  }
3426  backup->SMSC[num + 1] = NULL;
3427  } else {
3428  dbgprintf(NULL, "Increase GSM_BACKUP_MAX_SMSC\n");
3429  goto fail_memory;
3430  }
3431  backup->SMSC[num]->Location = atoi (readvalue);
3432  ReadSMSCEntry(file_info, h->SectionName, backup->SMSC[num],UseUnicode);
3433  num++;
3434  }
3435  }
3436  num = 0;
3437  for (h = file_info; h != NULL; h = h->Next) {
3438  found = FALSE;
3439  if (UseUnicode) {
3440  EncodeUnicode(buffer,"WAPBookmark",11);
3441  if (mywstrncasecmp(buffer, h->SectionName, 11)) found = TRUE;
3442  if (!found) {
3443  EncodeUnicode(buffer,"Bookmark",8);
3444  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3445  }
3446  } else {
3447  if (strncasecmp("WAPBookmark", h->SectionName, 11) == 0) found = TRUE;
3448  if (!found) {
3449  if (strncasecmp("Bookmark", h->SectionName, 8) == 0) found = TRUE;
3450  }
3451  }
3452  if (found) {
3453  readvalue = ReadCFGText(file_info, h->SectionName, "URL", UseUnicode);
3454  if (readvalue==NULL) break;
3455  if (num < GSM_BACKUP_MAX_WAPBOOKMARK) {
3456  backup->WAPBookmark[num] = (GSM_WAPBookmark *)malloc(sizeof(GSM_WAPBookmark));
3457  if (backup->WAPBookmark[num] == NULL) {
3458  goto fail_memory;
3459  }
3460  backup->WAPBookmark[num + 1] = NULL;
3461  } else {
3462  dbgprintf(NULL, "Increase GSM_BACKUP_MAX_WAPBOOKMARK\n");
3463  goto fail_memory;
3464  }
3465  backup->WAPBookmark[num]->Location = num + 1;
3466  ReadWAPBookmarkEntry(file_info, h->SectionName, backup->WAPBookmark[num],UseUnicode);
3467  num++;
3468  }
3469  }
3470  num = 0;
3471  for (h = file_info; h != NULL; h = h->Next) {
3472  found = FALSE;
3473  if (UseUnicode) {
3474  EncodeUnicode(buffer,"WAPSettings",11);
3475  if (mywstrncasecmp(buffer, h->SectionName, 11)) found = TRUE;
3476  if (!found) {
3477  EncodeUnicode(buffer,"Settings",8);
3478  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3479  }
3480  } else {
3481  if (strncasecmp("WAPSettings", h->SectionName, 11) == 0) found = TRUE;
3482  if (!found) {
3483  if (strncasecmp("Settings", h->SectionName, 8) == 0) found = TRUE;
3484  }
3485  }
3486  if (found) {
3487  readvalue = ReadCFGText(file_info, h->SectionName, "Title00", UseUnicode);
3488  if (readvalue==NULL) break;
3489  if (num < GSM_BACKUP_MAX_WAPSETTINGS) {
3490  backup->WAPSettings[num] = (GSM_MultiWAPSettings *)malloc(sizeof(GSM_MultiWAPSettings));
3491  if (backup->WAPSettings[num] == NULL) {
3492  goto fail_memory;
3493  }
3494  backup->WAPSettings[num + 1] = NULL;
3495  } else {
3496  dbgprintf(NULL, "Increase GSM_BACKUP_MAX_WAPSETTINGS\n");
3497  goto fail_memory;
3498  }
3499  backup->WAPSettings[num]->Location = num + 1;
3500  dbgprintf(NULL, "reading wap settings\n");
3501  ReadWAPSettingsEntry(file_info, h->SectionName, backup->WAPSettings[num],UseUnicode);
3502  num++;
3503  }
3504  }
3505  num = 0;
3506  for (h = file_info; h != NULL; h = h->Next) {
3507  found = FALSE;
3508  if (UseUnicode) {
3509  EncodeUnicode(buffer,"MMSSettings",8);
3510  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3511  } else {
3512  if (strncasecmp("MMSSettings", h->SectionName, 8) == 0) found = TRUE;
3513  }
3514  if (found) {
3515  readvalue = ReadCFGText(file_info, h->SectionName, "Title00", UseUnicode);
3516  if (readvalue==NULL) break;
3517  if (num < GSM_BACKUP_MAX_MMSSETTINGS) {
3518  backup->MMSSettings[num] = (GSM_MultiWAPSettings *)malloc(sizeof(GSM_MultiWAPSettings));
3519  if (backup->MMSSettings[num] == NULL) {
3520  goto fail_memory;
3521  }
3522  backup->MMSSettings[num + 1] = NULL;
3523  } else {
3524  dbgprintf(NULL, "Increase GSM_BACKUP_MAX_MMSSETTINGS\n");
3525  goto fail_memory;
3526  }
3527  backup->MMSSettings[num]->Location = num + 1;
3528  dbgprintf(NULL, "reading mms settings\n");
3529  ReadWAPSettingsEntry(file_info, h->SectionName, backup->MMSSettings[num],UseUnicode);
3530  num++;
3531  }
3532  }
3533  num = 0;
3534  for (h = file_info; h != NULL; h = h->Next) {
3535  found = FALSE;
3536  if (UseUnicode) {
3537  EncodeUnicode(buffer,"Ringtone",8);
3538  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3539  } else {
3540  if (strncasecmp("Ringtone", h->SectionName, 8) == 0) found = TRUE;
3541  }
3542  if (found) {
3543  readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
3544  if (readvalue==NULL) break;
3545  if (num < GSM_BACKUP_MAX_RINGTONES) {
3546  backup->Ringtone[num] = (GSM_Ringtone *)malloc(sizeof(GSM_Ringtone));
3547  if (backup->Ringtone[num] == NULL) {
3548  goto fail_memory;
3549  }
3550  backup->Ringtone[num + 1] = NULL;
3551  } else {
3552  dbgprintf(NULL, "Increase GSM_BACKUP_MAX_RINGTONES\n");
3553  goto fail_memory;
3554  }
3555  ReadRingtoneEntry(file_info, h->SectionName, backup->Ringtone[num],UseUnicode);
3556  num++;
3557  }
3558  }
3559  num = 0;
3560  for (h = file_info; h != NULL; h = h->Next) {
3561  found = FALSE;
3562  if (UseUnicode) {
3563  EncodeUnicode(buffer,"TODO",4);
3564  if (mywstrncasecmp(buffer, h->SectionName, 4)) found = TRUE;
3565  } else {
3566  if (strncasecmp("TODO", h->SectionName, 4) == 0) found = TRUE;
3567  }
3568  if (found) {
3569  readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
3570  if (readvalue==NULL) break;
3571  if (num < GSM_MAXCALENDARTODONOTES) {
3572  backup->ToDo[num] = (GSM_ToDoEntry *)malloc(sizeof(GSM_ToDoEntry));
3573  if (backup->ToDo[num] == NULL) {
3574  goto fail_memory;
3575  }
3576  backup->ToDo[num + 1] = NULL;
3577  } else {
3578  dbgprintf(NULL, "Increase GSM_MAXCALENDARTODONOTES\n");
3579  goto fail_memory;
3580  }
3581  backup->ToDo[num]->Location = num + 1;
3582  error = ReadToDoEntry(file_info, h->SectionName, backup->ToDo[num],UseUnicode);
3583  if (error != ERR_NONE) {
3584  goto fail_error;
3585  }
3586  num++;
3587  }
3588  }
3589  sprintf(buffer,"Startup");
3590  readvalue = ReadCFGText(file_info, buffer, "Text", UseUnicode);
3591  if (readvalue==NULL) {
3592  readvalue = ReadCFGText(file_info, buffer, "Width", UseUnicode);
3593  }
3594  if (readvalue!=NULL) {
3595  backup->StartupLogo = (GSM_Bitmap *)malloc(sizeof(GSM_Bitmap));
3596  if (backup->StartupLogo == NULL) {
3597  goto fail_memory;
3598  }
3599  ReadStartupEntry(file_info, buffer, backup->StartupLogo,UseUnicode);
3600  }
3601  sprintf(buffer,"Operator");
3602  readvalue = ReadCFGText(file_info, buffer, "Network", UseUnicode);
3603  if (readvalue!=NULL) {
3604  backup->OperatorLogo = (GSM_Bitmap *)malloc(sizeof(GSM_Bitmap));
3605  if (backup->OperatorLogo == NULL) {
3606  goto fail_memory;
3607  }
3608  ReadOperatorEntry(file_info, buffer, backup->OperatorLogo,UseUnicode);
3609  }
3610  num = 0;
3611  for (h = file_info; h != NULL; h = h->Next) {
3612  found = FALSE;
3613  if (UseUnicode) {
3614  EncodeUnicode(buffer,"FMStation",9);
3615  if (mywstrncasecmp(buffer, h->SectionName, 9)) found = TRUE;
3616  } else {
3617  if (strncasecmp("FMStation", h->SectionName, 9) == 0) found = TRUE;
3618  }
3619  if (found) {
3620  readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
3621  if (readvalue==NULL) break;
3622  if (num < GSM_BACKUP_MAX_FMSTATIONS) {
3623  backup->FMStation[num] = (GSM_FMStation *)malloc(sizeof(GSM_FMStation));
3624  if (backup->FMStation[num] == NULL) {
3625  goto fail_memory;
3626  }
3627  backup->FMStation[num + 1] = NULL;
3628  } else {
3629  dbgprintf(NULL, "Increase GSM_BACKUP_MAX_FMSTATIONS\n");
3630  goto fail_memory;
3631  }
3632  backup->FMStation[num]->Location = num + 1;
3633  error = ReadFMStationEntry(file_info, h->SectionName, backup->FMStation[num],UseUnicode);
3634  if (error != ERR_NONE) {
3635  goto fail_error;
3636  }
3637  num++;
3638  }
3639  }
3640  num = 0;
3641  for (h = file_info; h != NULL; h = h->Next) {
3642  found = FALSE;
3643  if (UseUnicode) {
3644  EncodeUnicode(buffer,"GPRSPoint",9);
3645  if (mywstrncasecmp(buffer, h->SectionName, 9)) found = TRUE;
3646  } else {
3647  if (strncasecmp("GPRSPoint", h->SectionName, 9) == 0) found = TRUE;
3648  }
3649  if (found) {
3650  readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
3651  if (readvalue==NULL) break;
3652  if (num < GSM_BACKUP_MAX_GPRSPOINT) {
3653  backup->GPRSPoint[num] = (GSM_GPRSAccessPoint *)malloc(sizeof(GSM_GPRSAccessPoint));
3654  if (backup->GPRSPoint[num] == NULL) {
3655  goto fail_memory;
3656  }
3657  backup->GPRSPoint[num + 1] = NULL;
3658  } else {
3659  dbgprintf(NULL, "Increase GSM_BACKUP_MAX_GPRSPOINT\n");
3660  goto fail_memory;
3661  }
3662  backup->GPRSPoint[num]->Location = num + 1;
3663  ReadGPRSPointEntry(file_info, h->SectionName, backup->GPRSPoint[num],UseUnicode);
3664  num++;
3665  }
3666  }
3667  num = 0;
3668  for (h = file_info; h != NULL; h = h->Next) {
3669  found = FALSE;
3670  if (UseUnicode) {
3671  EncodeUnicode(buffer,"Note",4);
3672  if (mywstrncasecmp(buffer, h->SectionName, 4)) found = TRUE;
3673  } else {
3674  if (strncasecmp("Note", h->SectionName, 4) == 0) found = TRUE;
3675  }
3676  if (found) {
3677  readvalue = ReadCFGText(file_info, h->SectionName, "Text", UseUnicode);
3678  if (readvalue==NULL) break;
3679  if (num < GSM_BACKUP_MAX_NOTE) {
3680  backup->Note[num] = (GSM_NoteEntry *)malloc(sizeof(GSM_NoteEntry));
3681  if (backup->Note[num] == NULL) {
3682  goto fail_memory;
3683  }
3684  backup->Note[num + 1] = NULL;
3685  } else {
3686  dbgprintf(NULL, "Increase GSM_BACKUP_MAX_NOTE\n");
3687  goto fail_memory;
3688  }
3689  ReadNoteEntry(file_info, h->SectionName, backup->Note[num],UseUnicode);
3690  num++;
3691  }
3692  }
3693  if (backup->MD5Original[0]!=0) {
3694  FindBackupChecksum(FileName, UseUnicode, backup->MD5Calculated);
3695  }
3696  for (h = file_info; h != NULL; h = h->Next) {
3697  found = FALSE;
3698  if (UseUnicode) {
3699  EncodeUnicode(buffer,"Backup",6);
3700  if (mywstrncasecmp(buffer, h->SectionName, 6)) found = TRUE;
3701  } else {
3702  if (strncasecmp("Backup", h->SectionName, 6) == 0) found = TRUE;
3703  }
3704  if (UseUnicode) {
3705  EncodeUnicode(buffer,"Checksum",8);
3706  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3707  } else {
3708  if (strncasecmp("Checksum", h->SectionName, 8) == 0) found = TRUE;
3709  }
3710  if (UseUnicode) {
3711  EncodeUnicode(buffer,"Profile",7);
3712  if (mywstrncasecmp(buffer, h->SectionName, 7)) found = TRUE;
3713  } else {
3714  if (strncasecmp("Profile", h->SectionName, 7) == 0) found = TRUE;
3715  }
3716  if (UseUnicode) {
3717  EncodeUnicode(buffer,"PhonePBK",8);
3718  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3719  } else {
3720  if (strncasecmp("PhonePBK", h->SectionName, 8) == 0) found = TRUE;
3721  }
3722  if (UseUnicode) {
3723  EncodeUnicode(buffer,"SIMPBK",6);
3724  if (mywstrncasecmp(buffer, h->SectionName, 6)) found = TRUE;
3725  } else {
3726  if (strncasecmp("SIMPBK", h->SectionName, 6) == 0) found = TRUE;
3727  }
3728  if (UseUnicode) {
3729  EncodeUnicode(buffer,"Calendar",8);
3730  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3731  } else {
3732  if (strncasecmp("Calendar", h->SectionName, 8) == 0) found = TRUE;
3733  }
3734  if (UseUnicode) {
3735  EncodeUnicode(buffer,"Caller",6);
3736  if (mywstrncasecmp(buffer, h->SectionName, 6)) found = TRUE;
3737  } else {
3738  if (strncasecmp("Caller", h->SectionName, 6) == 0) found = TRUE;
3739  }
3740  if (UseUnicode) {
3741  EncodeUnicode(buffer,"SMSC",4);
3742  if (mywstrncasecmp(buffer, h->SectionName, 4)) found = TRUE;
3743  } else {
3744  if (strncasecmp("SMSC", h->SectionName, 4) == 0) found = TRUE;
3745  }
3746  if (UseUnicode) {
3747  EncodeUnicode(buffer,"WAPBookmark",11);
3748  if (mywstrncasecmp(buffer, h->SectionName, 11)) found = TRUE;
3749  if (!found) {
3750  EncodeUnicode(buffer,"Bookmark",8);
3751  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3752  }
3753  } else {
3754  if (strncasecmp("WAPBookmark", h->SectionName, 11) == 0) found = TRUE;
3755  if (!found) {
3756  if (strncasecmp("Bookmark", h->SectionName, 8) == 0) found = TRUE;
3757  }
3758  }
3759  if (UseUnicode) {
3760  EncodeUnicode(buffer,"WAPSettings",11);
3761  if (mywstrncasecmp(buffer, h->SectionName, 11)) found = TRUE;
3762  if (!found) {
3763  EncodeUnicode(buffer,"Settings",8);
3764  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3765  }
3766  } else {
3767  if (strncasecmp("WAPSettings", h->SectionName, 11) == 0) found = TRUE;
3768  if (!found) {
3769  if (strncasecmp("Settings", h->SectionName, 8) == 0) found = TRUE;
3770  }
3771  }
3772  if (UseUnicode) {
3773  EncodeUnicode(buffer,"MMSSettings",8);
3774  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3775  } else {
3776  if (strncasecmp("MMSSettings", h->SectionName, 8) == 0) found = TRUE;
3777  }
3778  if (UseUnicode) {
3779  EncodeUnicode(buffer,"Ringtone",8);
3780  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3781  } else {
3782  if (strncasecmp("Ringtone", h->SectionName, 8) == 0) found = TRUE;
3783  }
3784  if (UseUnicode) {
3785  EncodeUnicode(buffer,"TODO",4);
3786  if (mywstrncasecmp(buffer, h->SectionName, 4)) found = TRUE;
3787  } else {
3788  if (strncasecmp("TODO", h->SectionName, 4) == 0) found = TRUE;
3789  }
3790  if (UseUnicode) {
3791  EncodeUnicode(buffer,"Startup",7);
3792  if (mywstrncasecmp(buffer, h->SectionName, 7)) found = TRUE;
3793  } else {
3794  if (strncasecmp("Startup", h->SectionName, 7) == 0) found = TRUE;
3795  }
3796  if (UseUnicode) {
3797  EncodeUnicode(buffer,"Operator",8);
3798  if (mywstrncasecmp(buffer, h->SectionName, 8)) found = TRUE;
3799  } else {
3800  if (strncasecmp("Operator", h->SectionName, 8) == 0) found = TRUE;
3801  }
3802  if (UseUnicode) {
3803  EncodeUnicode(buffer,"FMStation",9);
3804  if (mywstrncasecmp(buffer, h->SectionName, 9)) found = TRUE;
3805  } else {
3806  if (strncasecmp("FMStation", h->SectionName, 9) == 0) found = TRUE;
3807  }
3808  if (UseUnicode) {
3809  EncodeUnicode(buffer,"GPRSPoint",9);
3810  if (mywstrncasecmp(buffer, h->SectionName, 9)) found = TRUE;
3811  } else {
3812  if (strncasecmp("GPRSPoint", h->SectionName, 9) == 0) found = TRUE;
3813  }
3814  if (UseUnicode) {
3815  EncodeUnicode(buffer,"Note",4);
3816  if (mywstrncasecmp(buffer, h->SectionName, 4)) found = TRUE;
3817  } else {
3818  if (strncasecmp("Note", h->SectionName, 4) == 0) found = TRUE;
3819  }
3820  if (!found) {
3821  goto fail_memory;
3822  }
3823  }
3824  INI_Free(file_info);
3825  return ERR_NONE;
3826 fail_memory:
3827  error = ERR_MOREMEMORY;
3828 fail_error:
3829  INI_Free(file_info);
3830  return error;
3831 }
3832 
3833 /* ---------------------- backup files for SMS ----------------------------- */
3834 
3835 static GSM_Error ReadSMSBackupEntry(INI_Section *file_info, char *section, GSM_SMSMessage *SMS)
3836 {
3837  unsigned char *readvalue=NULL, *readbuffer=NULL;
3838 
3839  GSM_SetDefaultSMSData(SMS);
3840 
3841  SMS->PDU = SMS_Submit;
3842  SMS->SMSC.Location = 0;
3843  ReadBackupText(file_info, section, "SMSC", SMS->SMSC.Number, FALSE);
3844  SMS->ReplyViaSameSMSC = INI_GetBool(file_info, section, "ReplySMSC", FALSE);
3845  SMS->Class = INI_GetInt(file_info, section, "Class", -1);
3846  readvalue = ReadCFGText(file_info, section, "Sent", FALSE);
3847  if (readvalue != NULL && ReadVCALDateTime(readvalue, &SMS->DateTime)) {
3848  SMS->PDU = SMS_Deliver;
3849  }
3850  readvalue = ReadCFGText(file_info, section, "PDU", FALSE);
3851  if (readvalue != NULL) {
3852  if (strcmp(readvalue, "Deliver") == 0) {
3853  SMS->PDU = SMS_Deliver;
3854  } else if (strcmp(readvalue, "Submit" ) == 0) {
3855  SMS->PDU = SMS_Submit;
3856  } else if (strcmp(readvalue, "Status_Report" ) == 0) {
3857  SMS->PDU = SMS_Status_Report;
3858  }
3859  }
3860  readvalue = ReadCFGText(file_info, section, "DateTime", FALSE);
3861  if (readvalue != NULL) {
3862  ReadVCALDateTime(readvalue, &SMS->DateTime);
3863  }
3864  SMS->RejectDuplicates = INI_GetBool(file_info, section, "RejectDuplicates", FALSE);
3865  SMS->ReplaceMessage = INI_GetInt(file_info, section, "ReplaceMessage", 0);
3866  SMS->MessageReference = INI_GetInt(file_info, section, "MessageReference", 0);
3867  SMS->State = SMS_UnRead;
3868  readvalue = ReadCFGText(file_info, section, "State", FALSE);
3869  if (readvalue!=NULL) {
3870  if (strcasecmp(readvalue,"Read") == 0) SMS->State = SMS_Read;
3871  else if (strcasecmp(readvalue,"Sent") == 0) SMS->State = SMS_Sent;
3872  else if (strcasecmp(readvalue,"UnSent") == 0) SMS->State = SMS_UnSent;
3873  }
3874  ReadBackupText(file_info, section, "Number", SMS->Number, FALSE);
3875  ReadBackupText(file_info, section, "Name", SMS->Name, FALSE);
3876  SMS->Length = INI_GetInt(file_info, section, "Length", 0);
3877  SMS->Coding = SMS_Coding_8bit;
3878  readvalue = ReadCFGText(file_info, section, "Coding", FALSE);
3879  if (readvalue!=NULL) {
3880  SMS->Coding = GSM_StringToSMSCoding(readvalue);
3881  if (SMS->Coding == 0) {
3882  SMS->Coding = SMS_Coding_8bit;
3883  }
3884  }
3885  readbuffer = ReadLinkedBackupText(file_info, section, "Text", FALSE);
3886  if (readbuffer == NULL) {
3887  dbgprintf(NULL, "No text found, assuming empty!\n");
3888  SMS->Length = 0;
3889  SMS->Text[0] = 0;
3890  SMS->Text[1] = 0;
3891  } else {
3892  dbgprintf(NULL, "Linked text: %s\n", readbuffer);
3893  /* This is hex encoded unicode, need to multiply by 4 */
3894  if (strlen(readbuffer) > 4 * GSM_MAX_SMS_CHARS_LENGTH) {
3895  dbgprintf(NULL, "Message text too long, truncating!\n");
3896  readbuffer[4 * GSM_MAX_SMS_CHARS_LENGTH] = 0;
3897  }
3898  if (!DecodeHexBin (SMS->Text, readbuffer, strlen(readbuffer))) {
3899  dbgprintf(NULL, "Failed decoding binary field!\n");
3900  }
3901  /*
3902  * For 8-bit messages we store number of bytes,
3903  * otherwise length of text which should be nul terminated.
3904  */
3905  if (SMS->Coding == SMS_Coding_8bit) {
3906  SMS->Length = strlen(readbuffer)/2;
3907  } else {
3908  SMS->Length = strlen(readbuffer)/4;
3909  SMS->Text[(SMS->Length * 2)] = 0;
3910  SMS->Text[(SMS->Length * 2) + 1] = 0;
3911  }
3912  }
3913  free(readbuffer);
3914  readbuffer=NULL;
3915  SMS->Folder = INI_GetInt(file_info, section, "Folder", SMS->Folder);
3916  SMS->UDH.Type = UDH_NoUDH;
3917  SMS->UDH.Length = 0;
3918  SMS->UDH.ID8bit = -1;
3919  SMS->UDH.ID16bit = -1;
3920  SMS->UDH.PartNumber = -1;
3921  SMS->UDH.AllParts = -1;
3922  readvalue = ReadCFGText(file_info, section, "UDH", FALSE);
3923  if (readvalue!=NULL) {
3924  DecodeHexBin (SMS->UDH.Text, readvalue, strlen(readvalue));
3925  SMS->UDH.Length = strlen(readvalue)/2;
3926  GSM_DecodeUDHHeader(NULL, &SMS->UDH);
3927  }
3928  return ERR_NONE;
3929 }
3930 
3931 static GSM_Error GSM_ReadSMSBackupTextFile(const char *FileName, GSM_SMS_Backup *backup)
3932 {
3933  INI_Section *file_info, *h;
3934  char *readvalue=NULL;
3935  int num=0;
3936  GSM_Error error;
3937 
3938  backup->SMS[0] = NULL;
3939 
3940  error = INI_ReadFile(FileName, FALSE, &file_info);
3941  if (error != ERR_NONE) {
3942  return error;
3943  }
3944 
3945  num = 0;
3946  for (h = file_info; h != NULL; h = h->Next) {
3947  if (strncasecmp("SMSBackup", h->SectionName, 9) == 0) {
3948  readvalue = ReadCFGText(file_info, h->SectionName, "Number", FALSE);
3949  if (readvalue==NULL) break;
3950  if (num < GSM_BACKUP_MAX_SMS) {
3951  backup->SMS[num] = (GSM_SMSMessage *)malloc(sizeof(GSM_SMSMessage));
3952  if (backup->SMS[num] == NULL) return ERR_MOREMEMORY;
3953  backup->SMS[num + 1] = NULL;
3954  } else {
3955  dbgprintf(NULL, "Increase GSM_BACKUP_MAX_SMS\n");
3956  return ERR_MOREMEMORY;
3957  }
3958  backup->SMS[num]->Location = num + 1;
3959  error = ReadSMSBackupEntry(file_info, h->SectionName, backup->SMS[num]);
3960  if (error != ERR_NONE) {
3961  goto done;
3962  }
3963  num++;
3964  }
3965  }
3966  error = ERR_NONE;
3967 done:
3968  INI_Free(file_info);
3969  return error;
3970 }
3971 
3972 GSM_Error GSM_ReadSMSBackupFile(const char *FileName, GSM_SMS_Backup *backup)
3973 {
3974  FILE *file;
3975 
3976  GSM_ClearSMSBackup(backup);
3977 
3978  file = fopen(FileName, "rb");
3979  if (file == NULL) return(ERR_CANTOPENFILE);
3980 
3981  fclose(file);
3982 
3983  return GSM_ReadSMSBackupTextFile(FileName, backup);
3984 
3985 }
3986 
3990 GSM_Error SaveTextComment(FILE *file, unsigned char *comment)
3991 {
3992  char buffer[10000]={0};
3993  size_t i=0, len=0, pos = 0;
3994 
3995  sprintf(buffer, "%s", DecodeUnicodeString(comment));
3996 
3997  fprintf(file, "; ");
3998 
3999  len = strlen(buffer);
4000 
4001  for (i = 0; i < len; i++) {
4002  if (buffer[i] == 10 || buffer[i] == 13) {
4003  fprintf(file,"\n; ");
4004  pos = 0;
4005  } else {
4006  if (pos > 75) {
4007  fprintf(file,"\n; ");
4008  pos = 0;
4009  }
4010  fprintf(file, "%c", buffer[i]);
4011  pos++;
4012  }
4013  }
4014  fprintf(file,"\n");
4015  return ERR_NONE;
4016 }
4017 
4018 static GSM_Error SaveSMSBackupTextFile(FILE *file, GSM_SMS_Backup *backup)
4019 {
4020  int i=0;
4021  unsigned char *buffer;
4022  const char *s;
4023  GSM_DateTime DT;
4024  GSM_Error error;
4025 
4026  buffer = malloc(10000);
4027  if (buffer == NULL) {
4028  return ERR_MOREMEMORY;
4029  }
4030  buffer[0] = 0;
4031 
4032  fprintf(file, BACKUP_MAIN_HEADER "\n");
4033  fprintf(file, BACKUP_INFO_HEADER "\n");
4034  GSM_GetCurrentDateTime (&DT);
4035  fprintf(file,"; Saved ");
4036  fprintf(file, "%04d%02d%02dT%02d%02d%02d",
4037  DT.Year, DT.Month, DT.Day,
4038  DT.Hour, DT.Minute, DT.Second);
4039  fprintf(file," (%s)\n\n",OSDateTime(DT,FALSE));
4040 
4041  i=0;
4042  while (backup->SMS[i]!=NULL) {
4043  fprintf(file,"[SMSBackup%03i]\n",i);
4044  switch (backup->SMS[i]->Coding) {
4047  error = SaveTextComment(file, backup->SMS[i]->Text);
4048  if (error != ERR_NONE) {
4049  free(buffer);
4050  return error;
4051  }
4052  break;
4053  default:
4054  break;
4055  }
4056  if (backup->SMS[i]->PDU == SMS_Deliver) {
4057  error = SaveBackupText(file, "SMSC", backup->SMS[i]->SMSC.Number, FALSE);
4058  if (error != ERR_NONE) {
4059  free(buffer);
4060  return error;
4061  }
4062  if (backup->SMS[i]->ReplyViaSameSMSC) {
4063  fprintf(file,"SMSCReply = TRUE\n");
4064  }
4065  fprintf(file,"PDU = Deliver\n");
4066  } else if (backup->SMS[i]->PDU == SMS_Submit) {
4067  fprintf(file,"PDU = Submit\n");
4068  } else if (backup->SMS[i]->PDU == SMS_Status_Report) {
4069  fprintf(file,"PDU = Status_Report\n");
4070  }
4071  if (backup->SMS[i]->DateTime.Year != 0) {
4072  fprintf(file,"DateTime");
4073  error = SaveVCalDateTime(file,&backup->SMS[i]->DateTime, FALSE);
4074  if (error != ERR_NONE) {
4075  free(buffer);
4076  return error;
4077  }
4078  }
4079  fprintf(file,"State = ");
4080  switch (backup->SMS[i]->State) {
4081  case SMS_UnRead : fprintf(file,"UnRead\n"); break;
4082  case SMS_Read : fprintf(file,"Read\n"); break;
4083  case SMS_Sent : fprintf(file,"Sent\n"); break;
4084  case SMS_UnSent : fprintf(file,"UnSent\n"); break;
4085  }
4086  error = SaveBackupText(file, "Number", backup->SMS[i]->Number, FALSE);
4087  if (error != ERR_NONE) {
4088  free(buffer);
4089  return error;
4090  }
4091  error = SaveBackupText(file, "Name", backup->SMS[i]->Name, FALSE);
4092  if (error != ERR_NONE) {
4093  free(buffer);
4094  return error;
4095  }
4096  if (backup->SMS[i]->UDH.Type != UDH_NoUDH) {
4097  EncodeHexBin(buffer,backup->SMS[i]->UDH.Text,backup->SMS[i]->UDH.Length);
4098  fprintf(file,"UDH = %s\n",buffer);
4099  }
4100  switch (backup->SMS[i]->Coding) {
4103  EncodeHexBin(buffer,backup->SMS[i]->Text,backup->SMS[i]->Length*2);
4104  break;
4105  default:
4106  EncodeHexBin(buffer,backup->SMS[i]->Text,backup->SMS[i]->Length);
4107  break;
4108  }
4109  SaveLinkedBackupText(file, "Text", buffer, FALSE);
4110  s = GSM_SMSCodingToString(backup->SMS[i]->Coding);
4111  fprintf(file, "Coding = %s\n", s);
4112  fprintf(file,"Folder = %i\n",backup->SMS[i]->Folder);
4113  fprintf(file,"Length = %i\n",backup->SMS[i]->Length);
4114  fprintf(file,"Class = %i\n",backup->SMS[i]->Class);
4115  fprintf(file,"ReplySMSC = ");
4116  if (backup->SMS[i]->ReplyViaSameSMSC) fprintf(file,"True\n"); else fprintf(file,"False\n");
4117  fprintf(file,"RejectDuplicates = ");
4118  if (backup->SMS[i]->RejectDuplicates) fprintf(file,"True\n"); else fprintf(file,"False\n");
4119  fprintf(file,"ReplaceMessage = %i\n",backup->SMS[i]->ReplaceMessage);
4120  fprintf(file,"MessageReference = %i\n",backup->SMS[i]->MessageReference);
4121  fprintf(file,"\n");
4122  i++;
4123  }
4124  free(buffer);
4125  return ERR_NONE;
4126 }
4127 
4128 GSM_Error GSM_AddSMSBackupFile(const char *FileName, GSM_SMS_Backup *backup)
4129 {
4130  FILE *file;
4131 
4132  file = fopen(FileName, "ab");
4133 
4134  if (file == NULL) return(ERR_CANTOPENFILE);
4135 
4136  SaveSMSBackupTextFile(file,backup);
4137 
4138  fclose(file);
4139 
4140  return ERR_NONE;
4141 }
4142 
4143 void GSM_ClearSMSBackup(GSM_SMS_Backup *backup)
4144 {
4145  int i=0;
4146 
4147  for (i = 0; i <= GSM_BACKUP_MAX_SMS; i++) {
4148  backup->SMS[i] = NULL;
4149  }
4150 }
4151 
4152 void GSM_FreeSMSBackup(GSM_SMS_Backup *backup)
4153 {
4154  int i=0;
4155 
4156  for (i = 0; i <= GSM_BACKUP_MAX_SMS; i++) {
4157  if (backup->SMS[i] == NULL) break;
4158  free(backup->SMS[i]);
4159  backup->SMS[i] = NULL;
4160  }
4161 }
4162 #endif
4163 
4164 /* How should editor hadle tabs in this file? Add editor commands here.
4165  * vim: noexpandtab sw=8 ts=8 sts=8:
4166  */
GSM_SMSMessageType PDU
GSM_DateTime DateTime
WAPSettings_Bearer ActiveBearer
Definition: gammu-wap.h:200
char Server[(128+1) *2]
char IPAddress[(20+1) *2]
Definition: gammu-wap.h:128
unsigned char Name[(GSM_MAX_RINGTONE_NAME_LENGTH+1) *2]
gboolean IsNormalAuthentication
Definition: gammu-wap.h:104
gboolean DefaultRingtone
Definition: gammu-bitmap.h:134
GSM_Profile_Feat_ID FeatureID[15]
unsigned char Text[(GSM_MAX_SMS_LENGTH+1) *2]
char * DecodeUnicodeString(const unsigned char *src)
Definition: coding.c:245
GSM_RingtoneFormat Format
unsigned char Number[(GSM_MAX_NUMBER_LENGTH+1) *2]
int INI_GetInt(INI_Section *cfg, const unsigned char *section, const unsigned char *key, int fallback)
Definition: cfg.c:329
char Title[(20+1) *2]
Definition: gammu-wap.h:79
unsigned char * DecodeUnicodeSpecialChars(unsigned char *dest, const unsigned char *buffer)
Definition: coding.c:121
void CopyUnicodeString(unsigned char *Dest, const unsigned char *Source)
Definition: coding.c:1192
#define MAX(a, b)
Definition: gammu-misc.h:68
GSM_WAPSettings Settings[4]
Definition: gammu-wap.h:172
void INI_Free(INI_Section *head)
Definition: cfg.c:454
GSM_ToDo_Priority Priority
gboolean IsSecurity
Definition: gammu-wap.h:91
unsigned char ReplaceMessage
GSM_SMS_State State
unsigned int Number
gboolean FileSystemRingtone
Definition: gammu-bitmap.h:139
const char * GSM_SMSCodingToString(GSM_Coding_Type type)
Definition: gsmsms.c:1284
GSM_Bitmap_Types Type
Definition: gammu-bitmap.h:107
GSM_Error VC_StoreDateTime(char *Buffer, const size_t buff_len, size_t *Pos, const GSM_DateTime *Date, const char *Start)
Definition: gsmmisc.c:224
GSM_CalendarNoteType Type
char Password[(50+1) *2]
#define GSM_PHONEBOOK_ENTRIES
Definition: gammu-limits.h:98
#define GSM_MAX_SMS_CHARS_LENGTH
Definition: gammu-limits.h:183
gboolean HeadSetProfile
void EncodeBASE64(const unsigned char *Input, char *Output, const size_t Length)
Definition: coding.c:2118
GSM_Error
Definition: gammu-error.h:23
gboolean mywstrncasecmp(unsigned const char *a, unsigned const char *b, int num)
Definition: coding.c:1437
gboolean RejectDuplicates
gboolean FileSystemPicture
Definition: gammu-bitmap.h:144
FILE * df
Definition: debug.h:36
GSM_BinaryPicture_Types Type
Definition: gammu-bitmap.h:44
unsigned char * Buffer
Definition: gammu-bitmap.h:45
signed char Class
char Service[(20+1) *2]
Definition: gammu-wap.h:114
void GSM_SetDefaultSMSData(GSM_SMSMessage *SMS)
Definition: gsmsms.c:1129
size_t UnicodeLength(const unsigned char *str)
Definition: coding.c:186
GSM_UDHHeader UDH
GSM_MultiWAPSettings Connection
unsigned char Location
Definition: gammu-bitmap.h:112
unsigned char Number
Definition: gammu-wap.h:168
char PhonebookDataBase[(50+1) *2]
GSM_BinaryPicture Picture
Definition: gammu-memory.h:403
GSM_Coding_Type Coding
#define chk_fwrite(data, size, count, file)
Definition: gsmlogo.c:20
char Name[40 *2]
GSM_SMSFormat Format
INI_Entry * Prev
Definition: gammu-inifile.h:42
WAPSettings_Bearer Bearer
Definition: gammu-wap.h:87
GSM_EntryType EntryType
Definition: gammu-memory.h:372
char Code[(10+1) *2]
Definition: gammu-wap.h:123
gboolean IsIP
Definition: gammu-wap.h:118
char HomePage[(200+1) *2]
GSM_ToDoType EntryType
unsigned char Text[GSM_MAX_UDH_LENGTH]
char NetworkCode[10]
Definition: gammu-bitmap.h:160
void GSM_GetCalendarRecurranceRepeat(GSM_Debug_Info *di, unsigned char *rec, unsigned char *endday, GSM_CalendarEntry *entry)
Definition: gsmcal.c:137
char Server[(21+1) *2]
Definition: gammu-wap.h:109
gboolean ReadVCALDateTime(const char *Buffer, GSM_DateTime *dt)
Definition: gsmmisc.c:254
unsigned char RingtoneID
Definition: gammu-bitmap.h:138
INI_Entry * SubEntries
Definition: gammu-inifile.h:54
#define BACKUP_MAIN_HEADER
Definition: misc.h:11
unsigned char DefaultNumber[(GSM_MAX_NUMBER_LENGTH+1) *2]
unsigned char Text[(GSM_PHONEBOOK_TEXT_LENGTH+1) *2]
Definition: gammu-memory.h:399
char Text[(GSM_MAX_NOTE_TEXT_LENGTH+1) *2]
int gboolean
Definition: gammu-types.h:23
#define GSM_CALENDAR_ENTRIES
Definition: gammu-limits.h:105
char Password[(20+1) *2]
char User[(50+1) *2]
Definition: gammu-wap.h:142
gboolean ManualLogin
Definition: gammu-wap.h:132
void GSM_PrintBitmap(FILE *file, GSM_Bitmap *bitmap)
Definition: gsmlogo.c:257
GSM_Debug_Info GSM_global_debug
Definition: debug.c:33
GSM_CalendarNoteType Type
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
Definition: coding.c:301
unsigned char Name[(GSM_MAX_SMS_NAME_LENGTH+1) *2]
#define FALSE
Definition: gammu-types.h:25
GSM_SMSValidity Validity
char Proxy[(100+1) *2]
Definition: gammu-wap.h:184
gboolean INI_GetBool(INI_Section *cfg, const unsigned char *section, const unsigned char *key, gboolean fallback)
Definition: cfg.c:344
unsigned char * EntryValue
Definition: gammu-inifile.h:44
GSM_SubToDoEntry Entries[GSM_TODO_ENTRIES]
gboolean GSM_IsPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:238
GSM_NokiaBinaryRingtone NokiaBinary
GSM_Error INI_ReadFile(const char *FileName, gboolean Unicode, INI_Section **result)
Definition: cfg.c:24
WAPSettings_Speed Speed
Definition: gammu-wap.h:152
char * EncodeSpecialChars(char *dest, const char *buffer)
Definition: coding.c:94
unsigned char Frame[50000]
INI_Entry * INI_FindLastSectionEntry(INI_Section *file_info, const unsigned char *section, const gboolean Unicode)
Definition: cfg.c:409
GSM_Coding_Type GSM_StringToSMSCoding(const char *s)
Definition: gsmsms.c:1260
#define GSM_MAXCALENDARTODONOTES
Definition: gammu-limits.h:84
char CalendarDataBase[(50+1) *2]
GSM_MultiWAPSettings Connection
gboolean BitmapEnabled
Definition: gammu-bitmap.h:122
GSM_Profile_Feat_Value FeatureValue[15]
#define GSM_TODO_ENTRIES
Definition: gammu-limits.h:126
Definition: gammu-inifile.h:41
GSM_CalendarType EntryType
unsigned char Name[(GSM_MAX_GPRS_AP_NAME_LENGTH+1) *2]
gboolean IsISDNCall
Definition: gammu-wap.h:100
gboolean CarKitProfile
unsigned char URL[(GSM_MAX_GPRS_AP_URL_LENGTH+1) *2]
char * OSDateTime(GSM_DateTime dt, gboolean TimeZone)
Definition: misc.c:264
GSM_CalendarNoteType
gboolean DefaultBitmap
Definition: gammu-bitmap.h:130
char Password[(50+1) *2]
Definition: gammu-wap.h:148
GSM_DateTime Date
Definition: gammu-memory.h:380
unsigned char Number[(GSM_MAX_NUMBER_LENGTH+1) *2]
gboolean CallerGroups[5]
unsigned char Title[(50+1) *2]
Definition: gammu-wap.h:42
char Proxy2[(100+1) *2]
Definition: gammu-wap.h:192
GSM_SubCalendarEntry Entries[GSM_CALENDAR_ENTRIES]
#define dbgprintf
Definition: debug.h:72
void GSM_GetCurrentDateTime(GSM_DateTime *Date)
Definition: misc.c:184
void GSM_ClearBitmap(GSM_Bitmap *bmp)
Definition: gsmlogo.c:247
char DialUp[(20+1) *2]
Definition: gammu-wap.h:136
gboolean IsContinuous
Definition: gammu-wap.h:95
#define BACKUP_INFO_HEADER
Definition: misc.h:12
void GSM_DecodeUDHHeader(GSM_Debug_Info *di, GSM_UDHHeader *UDH)
Definition: gsmsms.c:121
unsigned char * INI_GetValue(INI_Section *cfg, const unsigned char *section, const unsigned char *key, const gboolean Unicode)
Definition: cfg.c:365
gboolean DefaultName
Definition: gammu-bitmap.h:126
gboolean DecodeHexBin(unsigned char *dest, const unsigned char *src, size_t len)
Definition: coding.c:411
GSM_EntryLocation Location
Definition: gammu-memory.h:376
size_t BitmapHeight
Definition: gammu-bitmap.h:152
void EncodeHexBin(char *dest, const unsigned char *src, size_t len)
Definition: coding.c:426
unsigned char * SectionName
Definition: gammu-inifile.h:55
char * DecodeSpecialChars(char *dest, const char *buffer)
Definition: coding.c:159
#define MIN(a, b)
Definition: gammu-misc.h:70
gboolean DefaultName
unsigned char * EncodeUnicodeSpecialChars(unsigned char *dest, const unsigned char *buffer)
Definition: coding.c:41
size_t BitmapWidth
Definition: gammu-bitmap.h:156
unsigned char Text[2 *(GSM_BITMAP_TEXT_LENGTH+1)]
Definition: gammu-bitmap.h:118
void GSM_SetPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:228
char User[(30+1) *2]
unsigned char * EntryName
Definition: gammu-inifile.h:43
char HomePage[(100+1) *2]
Definition: gammu-wap.h:83
unsigned char Address[(255+1) *2]
Definition: gammu-wap.h:38
#define TRUE
Definition: gammu-types.h:28
void CalculateMD5(unsigned char *buffer, int length, char *checksum)
Definition: md5-glib.c:8
unsigned char MessageReference
gboolean ReplyViaSameSMSC
char StationName[(GSM_MAX_FMSTATION_LENGTH+1) *2]
char User[(50+1) *2]
unsigned char Text[(GSM_MAX_TODO_TEXT_LENGTH+1) *2]
GSM_ValidityPeriod Relative
Debug_Level dl
Definition: debug.h:35
GSM_DateTime Date
void GSM_GetMaxBitmapWidthHeight(GSM_Bitmap_Types Type, size_t *width, size_t *height)
Definition: gsmlogo.c:217
unsigned char Text[(GSM_MAX_CALENDAR_TEXT_LENGTH+1) *2]
INI_Section * Next
Definition: gammu-inifile.h:53
int DecodeBASE64(const char *Input, unsigned char *Output, const size_t Length)
Definition: coding.c:2149
INI_Entry * Next
Definition: gammu-inifile.h:42
unsigned char Name[(GSM_MAX_SMSC_NAME_LENGTH+1) *2]
GSM_SubMemoryEntry Entries[GSM_PHONEBOOK_ENTRIES]
Definition: gammu-memory.h:427