Imported gammu 0.90.7
[gammu.git] / common / service / backup / backtext.c
blob685c42ea0ed87ab589c70a87bf434a202ee108d7
2 #include <string.h>
3 #include <ctype.h>
5 #include "../../phone/nokia/nfunc.h"
6 #include "../../phone/nokia/dct3/n7110.h"
7 #include "../../misc/cfg.h"
8 #include "../../misc/coding/coding.h"
9 #include "../../misc/coding/md5.h"
10 #include "../gsmlogo.h"
11 #include "../gsmmisc.h"
12 #include "backtext.h"
14 #ifdef GSM_ENABLE_BACKUP
16 GSM_Error FindBackupChecksum(char *FileName, bool UseUnicode, char *checksum)
18 INI_Section *file_info, *h;
19 INI_Entry *e;
20 char *buffer = NULL,buff[100];
21 int len=0;
22 int i;
23 file_info = INI_ReadFile(FileName, UseUnicode);
25 dbgprintf("Checking checksum\n");
27 for (h = file_info; h != NULL; h = h->Next) {
28 if (UseUnicode) {
29 EncodeUnicode(buff,"Checksum",8);
30 if (mywstrncasecmp(buff, h->SectionName, 8)) continue;
31 } else {
32 if (mystrncasecmp("Checksum", h->SectionName, 8)) continue;
35 if (UseUnicode) {
36 buffer = (unsigned char *)realloc(buffer,len+UnicodeLength(h->SectionName)*2+2);
37 CopyUnicodeString(buffer+len,h->SectionName);
38 len+=UnicodeLength(h->SectionName)*2;
39 dbgprintf("[%s]\n",DecodeUnicodeConsole(h->SectionName));
40 } else {
41 buffer = (unsigned char *)realloc(buffer,len+strlen(h->SectionName)+1);
42 strcpy(buffer+len,h->SectionName);
43 len+=strlen(h->SectionName);
45 for (e = h->SubEntries; e != NULL; e = e->Next) {
46 if (UseUnicode) {
47 buffer = (unsigned char *)realloc(buffer,len+UnicodeLength(e->EntryName)*2+2);
48 CopyUnicodeString(buffer+len,e->EntryName);
49 len+=UnicodeLength(e->EntryName)*2;
50 buffer = (unsigned char *)realloc(buffer,len+UnicodeLength(e->EntryValue)*2+2);
51 CopyUnicodeString(buffer+len,e->EntryValue);
52 len+=UnicodeLength(e->EntryValue)*2;
53 dbgprintf("\"%s\"",DecodeUnicodeConsole(e->EntryName));
54 dbgprintf("=\"%s\"\n",DecodeUnicodeConsole(e->EntryValue));
55 } else {
56 dbgprintf("%s=%s\n",e->EntryName,e->EntryValue);
57 buffer = (unsigned char *)realloc(buffer,len+strlen(e->EntryName)+1);
58 strcpy(buffer+len,e->EntryName);
59 len+=strlen(e->EntryName);
60 buffer = (unsigned char *)realloc(buffer,len+strlen(e->EntryValue)+1);
61 strcpy(buffer+len,e->EntryValue);
62 len+=strlen(e->EntryValue);
67 for (i=0;i<len;i++) printf("%02x",buffer[i]);
68 CalculateMD5(buffer, len, checksum);
69 free(buffer);
71 return GE_NONE;
74 static unsigned char *ReadCFGText(INI_Section *cfg, unsigned char *section, unsigned char *key, bool Unicode)
76 unsigned char Buffer[500],Buffer2[500],*retval;
78 if (Unicode) {
79 EncodeUnicode(Buffer2,key,strlen(key));
80 retval = INI_GetValue(cfg,section,Buffer2,Unicode);
81 if (retval != NULL) return DecodeUnicodeString(retval);
82 return NULL;
83 } else {
84 strcpy(Buffer,section);
85 strcpy(Buffer2,key);
86 return INI_GetValue(cfg,section,key,Unicode);
90 static void SaveLinkedBackupText(FILE *file, char *myname, char *myvalue, bool UseUnicode)
92 int w,current;
93 unsigned char buffer2[1000],buffer3[1000];
95 current = strlen(myvalue); w = 0;
96 while (true) {
97 if (current > 200) {
98 memcpy(buffer2,myvalue+(strlen(myvalue)-current),200);
99 buffer2[200] = 0;
100 current = current - 200;
101 } else {
102 memcpy(buffer2,myvalue+(strlen(myvalue)-current),current);
103 buffer2[current] = 0;
104 current = 0;
106 if (UseUnicode) {
107 sprintf(buffer3,"%s%02i = %s%c%c",myname,w,buffer2,13,10);
108 EncodeUnicode(buffer2,buffer3,strlen(buffer3));
109 fwrite(buffer2,1,strlen(buffer3)*2,file);
110 } else {
111 fprintf(file,"%s%02i = %s%c%c",myname,w,buffer2,13,10);
113 if (current == 0) break;
114 w++;
118 static void ReadLinkedBackupText(INI_Section *file_info, char *section, char *myname, char *myvalue, bool UseUnicode)
120 unsigned char buffer2[300];
121 char *readvalue;
122 int i;
124 i=0;
125 myvalue[0] = 0;
126 while (true) {
127 sprintf(buffer2,"%s%02i",myname,i);
128 readvalue = ReadCFGText(file_info, section, buffer2, UseUnicode);
129 if (readvalue!=NULL) {
130 myvalue[strlen(myvalue)+strlen(readvalue)]=0;
131 memcpy(myvalue+strlen(myvalue),readvalue,strlen(readvalue));
132 } else break;
133 i++;
137 static void SaveBackupText(FILE *file, char *myname, char *myvalue, bool UseUnicode)
139 unsigned char buffer[10000], buffer2[10000];
141 if (myname[0] == 0x00) {
142 if (UseUnicode) {
143 EncodeUnicode(buffer,myvalue,strlen(myvalue));
144 fwrite(buffer,1,strlen(myvalue)*2,file);
145 } else fprintf(file,"%s",myvalue);
146 } else {
147 if (UseUnicode) {
148 sprintf(buffer,"%s = \"",myname);
149 EncodeUnicode(buffer2,buffer,strlen(buffer));
150 fwrite(buffer2,1,strlen(buffer)*2,file);
152 fwrite(myvalue,1,UnicodeLength(myvalue)*2,file);
154 sprintf(buffer,"\"%c%c",13,10);
155 EncodeUnicode(buffer2,buffer,strlen(buffer));
156 fwrite(buffer2,1,strlen(buffer)*2,file);
157 } else {
158 sprintf(buffer,"%s = \"%s\"%c%c",myname,DecodeUnicodeString(myvalue),13,10);
159 fprintf(file,"%s",buffer);
161 EncodeHexBin(buffer,myvalue,UnicodeLength(myvalue)*2);
162 fprintf(file,"%sUnicode = %s%c%c",myname,buffer,13,10);
167 static bool ReadBackupText(INI_Section *file_info, char *section, char *myname, char *myvalue, bool UseUnicode)
169 unsigned char paramname[10000],*readvalue;
171 if (UseUnicode) {
172 EncodeUnicode(paramname,myname,strlen(myname));
173 readvalue = INI_GetValue(file_info, section, paramname, UseUnicode);
174 if (readvalue!=NULL) {
175 CopyUnicodeString(myvalue,readvalue+2);
176 myvalue[UnicodeLength(readvalue)*2-4]=0;
177 myvalue[UnicodeLength(readvalue)*2-3]=0;
178 dbgprintf("%s\n",DecodeUnicodeString(readvalue));
179 } else {
180 myvalue[0]=0;
181 myvalue[1]=0;
182 return false;
184 } else {
185 strcpy(paramname,myname);
186 strcat(paramname,"Unicode");
187 readvalue = ReadCFGText(file_info, section, paramname, UseUnicode);
188 if (readvalue!=NULL) {
189 dbgprintf("%s %i\n",readvalue,strlen(readvalue));
190 DecodeHexBin (myvalue, readvalue, strlen(readvalue));
191 myvalue[strlen(readvalue)/2]=0;
192 myvalue[strlen(readvalue)/2+1]=0;
193 dbgprintf("%s\n",DecodeUnicodeString(myvalue));
194 } else {
195 strcpy(paramname,myname);
196 readvalue = ReadCFGText(file_info, section, paramname, UseUnicode);
197 if (readvalue!=NULL) {
198 EncodeUnicode(myvalue,readvalue+1,strlen(readvalue)-2);
199 } else {
200 myvalue[0]=0;
201 myvalue[1]=0;
202 return false;
206 return true;
209 static void SaveVCalDateTime(FILE *file, GSM_DateTime *dt, bool UseUnicode)
211 unsigned char buffer[100];
212 int Length = 3;
214 sprintf(buffer, " = ");
215 SaveVCALDateTime(buffer, &Length, dt, NULL);
216 SaveBackupText(file, "", buffer, UseUnicode);
219 static void SaveVCalDate(FILE *file, GSM_DateTime *dt, bool UseUnicode)
221 unsigned char buffer[100];
223 sprintf(buffer, " = %04d%02d%02d%c%c", dt->Year, dt->Month, dt->Day,13,10);
224 SaveBackupText(file, "", buffer, UseUnicode);
227 /* ---------------------- backup files ------------------------------------- */
229 static void SavePbkEntry(FILE *file, GSM_MemoryEntry *Pbk, bool UseUnicode)
231 bool text;
232 char buffer[1000];
233 int j;
235 sprintf(buffer,"Location = %03i%c%c",Pbk->Location,13,10);
236 SaveBackupText(file, "", buffer, UseUnicode);
237 sprintf(buffer,"PreferUnicode = %s%c%c",Pbk->PreferUnicode ? "yes" : "no",13,10);
238 SaveBackupText(file, "", buffer, UseUnicode);
239 for (j=0;j<Pbk->EntriesNum;j++) {
240 text = true;
241 switch (Pbk->Entries[j].EntryType) {
242 case PBK_Number_General:
243 sprintf(buffer,"Entry%02iType = NumberGeneral%c%c",j,13,10);
244 SaveBackupText(file, "", buffer, UseUnicode);
245 break;
246 case PBK_Number_Mobile:
247 sprintf(buffer,"Entry%02iType = NumberMobile%c%c",j,13,10);
248 SaveBackupText(file, "", buffer, UseUnicode);
249 break;
250 case PBK_Number_Work:
251 sprintf(buffer,"Entry%02iType = NumberWork%c%c",j,13,10);
252 SaveBackupText(file, "", buffer, UseUnicode);
253 break;
254 case PBK_Number_Fax:
255 sprintf(buffer,"Entry%02iType = NumberFax%c%c",j,13,10);
256 SaveBackupText(file, "", buffer, UseUnicode);
257 break;
258 case PBK_Number_Home:
259 sprintf(buffer,"Entry%02iType = NumberHome%c%c",j,13,10);
260 SaveBackupText(file, "", buffer, UseUnicode);
261 break;
262 case PBK_Number_Pager:
263 sprintf(buffer,"Entry%02iType = NumberPager%c%c",j,13,10);
264 SaveBackupText(file, "", buffer, UseUnicode);
265 break;
266 case PBK_Number_Other:
267 sprintf(buffer,"Entry%02iType = NumberOther%c%c",j,13,10);
268 SaveBackupText(file, "", buffer, UseUnicode);
269 break;
270 case PBK_Text_Note:
271 sprintf(buffer,"Entry%02iType = Note%c%c",j,13,10);
272 SaveBackupText(file, "", buffer, UseUnicode);
273 break;
274 case PBK_Text_Postal:
275 sprintf(buffer,"Entry%02iType = Postal%c%c",j,13,10);
276 SaveBackupText(file, "", buffer, UseUnicode);
277 break;
278 case PBK_Text_Email:
279 sprintf(buffer,"Entry%02iType = Email%c%c",j,13,10);
280 SaveBackupText(file, "", buffer, UseUnicode);
281 break;
282 case PBK_Text_Email2:
283 sprintf(buffer,"Entry%02iType = Email2%c%c",j,13,10);
284 SaveBackupText(file, "", buffer, UseUnicode);
285 break;
286 case PBK_Text_URL:
287 sprintf(buffer,"Entry%02iType = URL%c%c",j,13,10);
288 SaveBackupText(file, "", buffer, UseUnicode);
289 break;
290 case PBK_Text_Name:
291 sprintf(buffer,"Entry%02iType = Name%c%c",j,13,10);
292 SaveBackupText(file, "", buffer, UseUnicode);
293 break;
294 case PBK_Caller_Group:
295 sprintf(buffer,"Entry%02iType = CallerGroup%c%c",j,13,10);
296 SaveBackupText(file, "", buffer, UseUnicode);
297 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
298 SaveBackupText(file, "", buffer, UseUnicode);
299 text = false;
300 break;
301 case PBK_RingtoneID:
302 sprintf(buffer,"Entry%02iType = RingtoneID%c%c",j,13,10);
303 SaveBackupText(file, "", buffer, UseUnicode);
304 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
305 SaveBackupText(file, "", buffer, UseUnicode);
306 text = false;
307 break;
308 case PBK_PictureID:
309 sprintf(buffer,"Entry%02iType = PictureID%c%c",j,13,10);
310 SaveBackupText(file, "", buffer, UseUnicode);
311 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
312 SaveBackupText(file, "", buffer, UseUnicode);
313 text = false;
314 break;
315 case PBK_Date:
316 break;
317 case PBK_Category:
318 sprintf(buffer,"Entry%02iType = Category%c%c",j,13,10);
319 SaveBackupText(file, "", buffer, UseUnicode);
320 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
321 SaveBackupText(file, "", buffer, UseUnicode);
322 text = false;
323 break;
324 case PBK_Private:
325 sprintf(buffer,"Entry%02iType = Private%c%c",j,13,10);
326 SaveBackupText(file, "", buffer, UseUnicode);
327 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
328 SaveBackupText(file, "", buffer, UseUnicode);
329 text = false;
330 break;
331 case PBK_Text_LastName:
332 sprintf(buffer,"Entry%02iType = LastName%c%c",j,13,10);
333 SaveBackupText(file, "", buffer, UseUnicode);
334 break;
335 case PBK_Text_FirstName:
336 sprintf(buffer,"Entry%02iType = FirstName%c%c",j,13,10);
337 SaveBackupText(file, "", buffer, UseUnicode);
338 break;
339 case PBK_Text_Company:
340 sprintf(buffer,"Entry%02iType = Company%c%c",j,13,10);
341 SaveBackupText(file, "", buffer, UseUnicode);
342 break;
343 case PBK_Text_JobTitle:
344 sprintf(buffer,"Entry%02iType = JobTitle%c%c",j,13,10);
345 SaveBackupText(file, "", buffer, UseUnicode);
346 break;
347 case PBK_Text_StreetAddress:
348 sprintf(buffer,"Entry%02iType = Address%c%c",j,13,10);
349 SaveBackupText(file, "", buffer, UseUnicode);
350 break;
351 case PBK_Text_City:
352 sprintf(buffer,"Entry%02iType = City%c%c",j,13,10);
353 SaveBackupText(file, "", buffer, UseUnicode);
354 break;
355 case PBK_Text_State:
356 sprintf(buffer,"Entry%02iType = State%c%c",j,13,10);
357 SaveBackupText(file, "", buffer, UseUnicode);
358 break;
359 case PBK_Text_Zip:
360 sprintf(buffer,"Entry%02iType = Zip%c%c",j,13,10);
361 SaveBackupText(file, "", buffer, UseUnicode);
362 break;
363 case PBK_Text_Country:
364 sprintf(buffer,"Entry%02iType = Country%c%c",j,13,10);
365 SaveBackupText(file, "", buffer, UseUnicode);
366 break;
367 case PBK_Text_Custom1:
368 sprintf(buffer,"Entry%02iType = Custom1%c%c",j,13,10);
369 SaveBackupText(file, "", buffer, UseUnicode);
370 break;
371 case PBK_Text_Custom2:
372 sprintf(buffer,"Entry%02iType = Custom2%c%c",j,13,10);
373 SaveBackupText(file, "", buffer, UseUnicode);
374 break;
375 case PBK_Text_Custom3:
376 sprintf(buffer,"Entry%02iType = Custom3%c%c",j,13,10);
377 SaveBackupText(file, "", buffer, UseUnicode);
378 break;
379 case PBK_Text_Custom4:
380 sprintf(buffer,"Entry%02iType = Custom4%c%c",j,13,10);
381 SaveBackupText(file, "", buffer, UseUnicode);
382 break;
384 if (text) {
385 sprintf(buffer,"Entry%02iText",j);
386 SaveBackupText(file,buffer,Pbk->Entries[j].Text, UseUnicode);
388 switch (Pbk->Entries[j].EntryType) {
389 case PBK_Number_General:
390 case PBK_Number_Mobile:
391 case PBK_Number_Work:
392 case PBK_Number_Fax:
393 case PBK_Number_Home:
394 case PBK_Number_Other:
395 case PBK_Number_Pager:
396 if (Pbk->Entries[j].VoiceTag!=0) {
397 sprintf(buffer,"Entry%02iVoiceTag = %i%c%c",j,Pbk->Entries[j].VoiceTag,13,10);
398 SaveBackupText(file, "", buffer, UseUnicode);
400 break;
401 default:
402 break;
405 sprintf(buffer,"%c%c",13,10);
406 SaveBackupText(file, "", buffer, UseUnicode);
409 static void SaveCalendarEntry(FILE *file, GSM_CalendarEntry *Note, bool UseUnicode)
411 int i;
412 char buffer[1000];
414 sprintf(buffer,"Location = %d%c%c", Note->Location,13,10);
415 SaveBackupText(file, "", buffer, UseUnicode);
416 SaveBackupText(file, "", "Type = ", UseUnicode);
417 switch (Note->Type) {
418 case GCN_REMINDER : sprintf(buffer,"Reminder%c%c", 13,10); break;
419 case GCN_CALL : sprintf(buffer,"Call%c%c", 13,10); break;
420 case GCN_MEETING : sprintf(buffer,"Meeting%c%c", 13,10); break;
421 case GCN_BIRTHDAY : sprintf(buffer,"Birthday%c%c", 13,10); break;
422 case GCN_TRAVEL : sprintf(buffer,"Travel%c%c", 13,10); break;
423 case GCN_VACATION : sprintf(buffer,"Vacation%c%c", 13,10); break;
424 case GCN_MEMO : sprintf(buffer,"Memo%c%c", 13,10); break;
425 case GCN_ALARM : sprintf(buffer,"Alarm%c%c", 13,10); break;
426 case GCN_DAILY_ALARM : sprintf(buffer,"DailyAlarm%c%c", 13,10); break;
427 case GCN_T_ATHL : sprintf(buffer,"Training/Athletism%c%c", 13,10); break;
428 case GCN_T_BALL : sprintf(buffer,"Training/BallGames%c%c", 13,10); break;
429 case GCN_T_CYCL : sprintf(buffer,"Training/Cycling%c%c", 13,10); break;
430 case GCN_T_BUDO : sprintf(buffer,"Training/Budo%c%c", 13,10); break;
431 case GCN_T_DANC : sprintf(buffer,"Training/Dance%c%c", 13,10); break;
432 case GCN_T_EXTR : sprintf(buffer,"Training/ExtremeSports%c%c", 13,10); break;
433 case GCN_T_FOOT : sprintf(buffer,"Training/Football%c%c", 13,10); break;
434 case GCN_T_GOLF : sprintf(buffer,"Training/Golf%c%c", 13,10); break;
435 case GCN_T_GYM : sprintf(buffer,"Training/Gym%c%c", 13,10); break;
436 case GCN_T_HORS : sprintf(buffer,"Training/HorseRaces%c%c", 13,10); break;
437 case GCN_T_HOCK : sprintf(buffer,"Training/Hockey%c%c", 13,10); break;
438 case GCN_T_RACE : sprintf(buffer,"Training/Races%c%c", 13,10); break;
439 case GCN_T_RUGB : sprintf(buffer,"Training/Rugby%c%c", 13,10); break;
440 case GCN_T_SAIL : sprintf(buffer,"Training/Sailing%c%c", 13,10); break;
441 case GCN_T_STRE : sprintf(buffer,"Training/StreetGames%c%c", 13,10); break;
442 case GCN_T_SWIM : sprintf(buffer,"Training/Swimming%c%c", 13,10); break;
443 case GCN_T_TENN : sprintf(buffer,"Training/Tennis%c%c", 13,10); break;
444 case GCN_T_TRAV : sprintf(buffer,"Training/Travels%c%c", 13,10); break;
445 case GCN_T_WINT : sprintf(buffer,"Training/WinterGames%c%c", 13,10); break;
447 SaveBackupText(file, "", buffer, UseUnicode);
448 for (i=0;i<Note->EntriesNum;i++) {
449 switch (Note->Entries[i].EntryType) {
450 case CAL_START_DATETIME:
451 SaveBackupText(file, "", "StartTime", UseUnicode);
452 SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode);
453 break;
454 case CAL_END_DATETIME:
455 SaveBackupText(file, "", "StopTime", UseUnicode);
456 SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode);
457 break;
458 case CAL_ALARM_DATETIME:
459 SaveBackupText(file, "", "Alarm", UseUnicode);
460 SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode);
461 sprintf(buffer,"AlarmType = Tone%c%c",13,10);
462 SaveBackupText(file, "", buffer, UseUnicode);
463 break;
464 case CAL_SILENT_ALARM_DATETIME:
465 SaveBackupText(file, "", "Alarm", UseUnicode);
466 SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode);
467 sprintf(buffer,"AlarmType = Silent%c%c",13,10);
468 SaveBackupText(file, "", buffer, UseUnicode);
469 break;
470 case CAL_PRIVATE:
471 sprintf(buffer, "Private = %d%c%c",Note->Entries[i].Number,13,10);
472 SaveBackupText(file, "", buffer, UseUnicode);
473 break;
474 case CAL_LOCATION:
475 SaveBackupText(file, "EventLocation", Note->Entries[i].Text, UseUnicode);
476 break;
477 case CAL_CONTACTID:
478 sprintf(buffer, "ContactID = %d%c%c",Note->Entries[i].Number,13,10);
479 SaveBackupText(file, "", buffer, UseUnicode);
480 break;
481 case CAL_RECURRANCE:
482 sprintf(buffer, "Recurrance = %d%c%c",Note->Entries[i].Number/24,13,10);
483 SaveBackupText(file, "", buffer, UseUnicode);
484 break;
485 case CAL_TEXT:
486 SaveBackupText(file, "Text", Note->Entries[i].Text, UseUnicode);
487 break;
488 case CAL_PHONE:
489 SaveBackupText(file, "Phone", Note->Entries[i].Text, UseUnicode);
490 break;
491 case CAL_REPEAT_STOPDATE:
492 SaveBackupText(file, "", "RepeatStopDate", UseUnicode);
493 SaveVCalDate(file, &Note->Entries[i].Date, UseUnicode);
494 break;
495 case CAL_REPEAT_STARTDATE:
496 SaveBackupText(file, "", "RepeatStartDate", UseUnicode);
497 SaveVCalDate(file, &Note->Entries[i].Date, UseUnicode);
498 break;
499 case CAL_REPEAT_DAYOFWEEK:
500 sprintf(buffer, "RepeatDayOfWeek = %d%c%c",Note->Entries[i].Number,13,10);
501 SaveBackupText(file, "", buffer, UseUnicode);
502 break;
503 case CAL_REPEAT_DAY:
504 sprintf(buffer, "RepeatDay = %d%c%c",Note->Entries[i].Number,13,10);
505 SaveBackupText(file, "", buffer, UseUnicode);
506 break;
507 case CAL_REPEAT_WEEKOFMONTH:
508 sprintf(buffer, "RepeatWeekOfMonth = %d%c%c",Note->Entries[i].Number,13,10);
509 SaveBackupText(file, "", buffer, UseUnicode);
510 break;
511 case CAL_REPEAT_MONTH:
512 sprintf(buffer, "RepeatMonth = %d%c%c",Note->Entries[i].Number,13,10);
513 SaveBackupText(file, "", buffer, UseUnicode);
514 break;
515 case CAL_REPEAT_FREQUENCY:
516 sprintf(buffer, "RepeatFrequency = %d%c%c",Note->Entries[i].Number,13,10);
517 SaveBackupText(file, "", buffer, UseUnicode);
518 break;
521 sprintf(buffer, "%c%c",13,10);
522 SaveBackupText(file, "", buffer, UseUnicode);
525 static void SaveWAPSettingsEntry(FILE *file, GSM_MultiWAPSettings *settings, bool UseUnicode)
527 int i;
528 char buffer[10000];
530 if (settings->Active) {
531 sprintf(buffer,"Active = Yes%c%c",13,10);
532 SaveBackupText(file, "", buffer, UseUnicode);
534 switch (settings->ActiveBearer) {
535 case WAPSETTINGS_BEARER_SMS : sprintf(buffer,"Bearer = SMS%c%c",13,10); break;
536 case WAPSETTINGS_BEARER_GPRS: sprintf(buffer,"Bearer = GPRS%c%c",13,10); break;
537 case WAPSETTINGS_BEARER_DATA: sprintf(buffer,"Bearer = Data%c%c",13,10); break;
538 case WAPSETTINGS_BEARER_USSD: sprintf(buffer,"Bearer = USSD%c%c",13,10);
540 SaveBackupText(file, "", buffer, UseUnicode);
541 sprintf(buffer,"%c%c",13,10);
542 SaveBackupText(file, "", buffer, UseUnicode);
543 for (i=0;i<settings->Number;i++) {
544 sprintf(buffer,"Title%02i",i);
545 SaveBackupText(file, buffer, settings->Settings[i].Title, UseUnicode);
546 sprintf(buffer,"HomePage%02i",i);
547 SaveBackupText(file, buffer, settings->Settings[i].HomePage, UseUnicode);
548 if (settings->Settings[i].IsContinuous) {
549 sprintf(buffer,"Type%02i = Continuous%c%c",i,13,10);
550 } else {
551 sprintf(buffer,"Type%02i = Temporary%c%c",i,13,10);
553 SaveBackupText(file, "", buffer, UseUnicode);
554 if (settings->Settings[i].IsSecurity) {
555 sprintf(buffer,"Security%02i = On%c%c",i,13,10);
556 } else {
557 sprintf(buffer,"Security%02i = Off%c%c",i,13,10);
559 SaveBackupText(file, "", buffer, UseUnicode);
560 switch (settings->Settings[i].Bearer) {
561 case WAPSETTINGS_BEARER_SMS:
562 sprintf(buffer,"Bearer%02i = SMS%c%c",i,13,10);
563 SaveBackupText(file, "", buffer, UseUnicode);
564 sprintf(buffer,"Server%02i",i);
565 SaveBackupText(file, buffer, settings->Settings[i].Server, UseUnicode);
566 sprintf(buffer,"Service%02i",i);
567 SaveBackupText(file, buffer, settings->Settings[i].Service, UseUnicode);
568 break;
569 case WAPSETTINGS_BEARER_GPRS:
570 sprintf(buffer,"Bearer%02i = GPRS%c%c",i,13,10);
571 SaveBackupText(file, "", buffer, UseUnicode);
572 case WAPSETTINGS_BEARER_DATA:
573 if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_DATA) {
574 sprintf(buffer,"Bearer%02i = Data%c%c",i,13,10);
575 SaveBackupText(file, "", buffer, UseUnicode);
576 if (settings->Settings[i].IsISDNCall) {
577 sprintf(buffer,"CallType%02i = ISDN%c%c",i,13,10);
578 } else {
579 sprintf(buffer,"CallType%02i = Analogue%c%c",i,13,10);
581 SaveBackupText(file, "", buffer, UseUnicode);
583 sprintf(buffer,"Number%02i",i);
584 SaveBackupText(file, buffer, settings->Settings[i].DialUp, UseUnicode);
585 sprintf(buffer,"IP%02i",i);
586 SaveBackupText(file, buffer, settings->Settings[i].IPAddress, UseUnicode);
587 if (settings->Settings[i].ManualLogin) {
588 sprintf(buffer,"Login%02i = Manual%c%c",i,13,10);
589 } else {
590 sprintf(buffer,"Login%02i = Automatic%c%c",i,13,10);
592 SaveBackupText(file, "", buffer, UseUnicode);
593 if (settings->Settings[i].IsNormalAuthentication) {
594 sprintf(buffer,"Authentication%02i = Normal%c%c",i,13,10);
595 } else {
596 sprintf(buffer,"Authentication%02i = Secure%c%c",i,13,10);
598 SaveBackupText(file, "", buffer, UseUnicode);
599 switch (settings->Settings[i].Speed) {
600 case WAPSETTINGS_SPEED_9600 : sprintf(buffer,"CallSpeed%02i = 9600%c%c" ,i,13,10); break;
601 case WAPSETTINGS_SPEED_14400: sprintf(buffer,"CallSpeed%02i = 14400%c%c",i,13,10); break;
602 case WAPSETTINGS_SPEED_AUTO : sprintf(buffer,"CallSpeed%02i = auto%c%c" ,i,13,10); break;
604 switch (settings->Settings[i].Speed) {
605 case WAPSETTINGS_SPEED_9600 :
606 case WAPSETTINGS_SPEED_14400:
607 case WAPSETTINGS_SPEED_AUTO :
608 SaveBackupText(file, "", buffer, UseUnicode);
609 default:
610 break;
612 sprintf(buffer,"User%02i",i);
613 SaveBackupText(file, buffer, settings->Settings[i].User, UseUnicode);
614 sprintf(buffer,"Password%02i",i);
615 SaveBackupText(file, buffer, settings->Settings[i].Password, UseUnicode);
616 break;
617 case WAPSETTINGS_BEARER_USSD:
618 sprintf(buffer,"Bearer%02i = USSD%c%c",i,13,10);
619 SaveBackupText(file, "", buffer, UseUnicode);
620 sprintf(buffer,"ServiceCode%02i",i);
621 SaveBackupText(file, buffer, settings->Settings[i].Code, UseUnicode);
622 if (settings->Settings[i].IsIP) {
623 sprintf(buffer,"IP%02i",i);
624 } else {
625 sprintf(buffer,"Number%02i",i);
627 SaveBackupText(file, buffer, settings->Settings[i].Service, UseUnicode);
629 sprintf(buffer,"%c%c",13,10);
630 SaveBackupText(file, "", buffer, UseUnicode);
634 static void SaveBitmapEntry(FILE *file, GSM_Bitmap *bitmap, bool UseUnicode)
636 unsigned char buffer[10000],buffer2[10000];
637 int x,y;
639 sprintf(buffer,"Width = %i%c%c",bitmap->Width,13,10);
640 SaveBackupText(file, "", buffer, UseUnicode);
641 sprintf(buffer,"Height = %i%c%c",bitmap->Height,13,10);
642 SaveBackupText(file, "", buffer, UseUnicode);
643 for (y=0;y<bitmap->Height;y++) {
644 for (x=0;x<bitmap->Width;x++) {
645 buffer[x] = ' ';
646 if (GSM_IsPointBitmap(bitmap,x,y)) buffer[x]='#';
648 buffer[bitmap->Width] = 0;
649 sprintf(buffer2,"Bitmap%02i = \"%s\"%c%c",y,buffer,13,10);
650 SaveBackupText(file, "", buffer2, UseUnicode);
654 static void SaveCallerEntry(FILE *file, GSM_Bitmap *bitmap, bool UseUnicode)
656 unsigned char buffer[1000];
658 sprintf(buffer,"Location = %03i%c%c",bitmap->Location,13,10);
659 SaveBackupText(file, "", buffer, UseUnicode);
660 if (!bitmap->DefaultName) SaveBackupText(file, "Name", bitmap->Text, UseUnicode);
661 if (!bitmap->DefaultRingtone) {
662 sprintf(buffer,"Ringtone = %02x%c%c",bitmap->Ringtone,13,10);
663 SaveBackupText(file, "", buffer, UseUnicode);
665 if (bitmap->Enabled) {
666 sprintf(buffer,"Enabled = True%c%c",13,10);
667 } else {
668 sprintf(buffer,"Enabled = False%c%c",13,10);
670 SaveBackupText(file, "", buffer, UseUnicode);
671 if (!bitmap->DefaultBitmap) SaveBitmapEntry(file, bitmap, UseUnicode);
672 sprintf(buffer,"%c%c",13,10);
673 SaveBackupText(file, "", buffer, UseUnicode);
676 static void SaveWAPBookmarkEntry(FILE *file, GSM_WAPBookmark *bookmark, bool UseUnicode)
678 unsigned char buffer[1000];
680 SaveBackupText(file, "URL", bookmark->Address, UseUnicode);
681 SaveBackupText(file, "Title", bookmark->Title, UseUnicode);
682 sprintf(buffer,"%c%c",13,10);
683 SaveBackupText(file, "", buffer, UseUnicode);
686 static void SaveStartupEntry(FILE *file, GSM_Bitmap *bitmap, bool UseUnicode)
688 unsigned char buffer[1000];
690 sprintf(buffer,"[Startup]%c%c",13,10);
691 SaveBackupText(file, "", buffer, UseUnicode);
692 if (bitmap->Type == GSM_WelcomeNoteText) {
693 SaveBackupText(file, "Text", bitmap->Text, UseUnicode);
695 if (bitmap->Type == GSM_StartupLogo) {
696 SaveBitmapEntry(file, bitmap, UseUnicode);
698 sprintf(buffer,"%c%c",13,10);
699 SaveBackupText(file, "", buffer, UseUnicode);
702 static void SaveSMSCEntry(FILE *file, GSM_SMSC *SMSC, bool UseUnicode)
704 unsigned char buffer[1000];
706 sprintf(buffer,"Location = %03i%c%c",SMSC->Location,13,10);
707 SaveBackupText(file, "", buffer, UseUnicode);
708 SaveBackupText(file, "Name", SMSC->Name, UseUnicode);
709 SaveBackupText(file, "Number", SMSC->Number, UseUnicode);
710 SaveBackupText(file, "DefaultNumber", SMSC->DefaultNumber, UseUnicode);
711 SaveBackupText(file, "", "Format = ", UseUnicode);
712 switch (SMSC->Format) {
713 case GSMF_Text : sprintf(buffer,"Text"); break;
714 case GSMF_Fax : sprintf(buffer,"Fax"); break;
715 case GSMF_Email : sprintf(buffer,"Email"); break;
716 case GSMF_Pager : sprintf(buffer,"Pager"); break;
718 SaveBackupText(file, "", buffer, UseUnicode);
719 sprintf(buffer,"%c%cValidity = ",13,10);
720 SaveBackupText(file, "", buffer, UseUnicode);
721 switch (SMSC->Validity.Relative) {
722 case GSMV_1_Hour : sprintf(buffer, "1hour" ); break;
723 case GSMV_6_Hours : sprintf(buffer, "6hours" ); break;
724 case GSMV_24_Hours : sprintf(buffer, "24hours" ); break;
725 case GSMV_72_Hours : sprintf(buffer, "72hours" ); break;
726 case GSMV_1_Week : sprintf(buffer, "1week" ); break;
727 case GSMV_Max_Time :
728 default : sprintf(buffer,"MaximumTime" ); break;
730 SaveBackupText(file, "", buffer, UseUnicode);
731 sprintf(buffer,"%c%c%c%c",13,10,13,10);
732 SaveBackupText(file, "", buffer, UseUnicode);
735 static void SaveRingtoneEntry(FILE *file, GSM_Ringtone *ringtone, bool UseUnicode)
737 unsigned char buffer[45000];
738 int i,j;
740 sprintf(buffer,"Location = %i%c%c",ringtone->Location,13,10);
741 SaveBackupText(file, "", buffer, UseUnicode);
742 SaveBackupText(file, "Name", ringtone->Name, UseUnicode);
743 switch (ringtone->Format) {
744 case RING_NOKIABINARY:
745 j = 0; i = 0;
746 EncodeHexBin(buffer,ringtone->NokiaBinary.Frame,ringtone->NokiaBinary.Length);
747 SaveLinkedBackupText(file, "NokiaBinary", buffer, UseUnicode);
748 break;
749 case RING_MIDI:
750 j = 0; i = 0;
751 EncodeHexBin(buffer,ringtone->NokiaBinary.Frame,ringtone->NokiaBinary.Length);
752 SaveLinkedBackupText(file, "Pure Midi", buffer, UseUnicode);
753 break;
754 case RING_NOTETONE:
755 break;
757 sprintf(buffer,"%c%c",13,10);
758 SaveBackupText(file, "", buffer, UseUnicode);
761 static void SaveOperatorEntry(FILE *file, GSM_Bitmap *bitmap, bool UseUnicode)
763 unsigned char buffer[1000];
765 sprintf(buffer,"[Operator]%c%c",13,10);
766 SaveBackupText(file, "", buffer, UseUnicode);
767 sprintf(buffer,"Network = \"%s\"%c%c", bitmap->NetworkCode,13,10);
768 SaveBackupText(file, "", buffer, UseUnicode);
769 SaveBitmapEntry(file, bitmap, UseUnicode);
770 sprintf(buffer,"%c%c",13,10);
771 SaveBackupText(file, "", buffer, UseUnicode);
774 static void SaveToDoEntry(FILE *file, GSM_ToDoEntry *ToDo, bool UseUnicode)
776 unsigned char buffer[1000];
777 int j;
779 sprintf(buffer,"Location = %i%c%c",ToDo->Location,13,10);
780 SaveBackupText(file, "", buffer, UseUnicode);
781 switch (ToDo->Priority) {
782 case GSM_Priority_High:
783 sprintf(buffer,"Priority = High%c%c",13,10);
784 break;
785 case GSM_Priority_Medium:
786 sprintf(buffer,"Priority = Medium%c%c",13,10);
787 break;
788 case GSM_Priority_Low:
789 sprintf(buffer,"Priority = Low%c%c",13,10);
790 break;
792 SaveBackupText(file, "", buffer, UseUnicode);
794 for (j=0;j<ToDo->EntriesNum;j++) {
795 switch (ToDo->Entries[j].EntryType) {
796 case TODO_END_DATETIME:
797 SaveBackupText(file, "", "DueTime", UseUnicode);
798 SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode);
799 break;
800 case TODO_COMPLETED:
801 sprintf(buffer,"Completed = %s%c%c",ToDo->Entries[j].Number == 1 ? "yes" : "no" ,13,10);
802 SaveBackupText(file, "", buffer, UseUnicode);
803 break;
804 case TODO_ALARM_DATETIME:
805 SaveBackupText(file, "", "Alarm", UseUnicode);
806 SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode);
807 break;
808 case TODO_SILENT_ALARM_DATETIME:
809 SaveBackupText(file, "", "SilentAlarm", UseUnicode);
810 SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode);
811 break;
812 case TODO_TEXT:
813 SaveBackupText(file, "Text", ToDo->Entries[j].Text, UseUnicode);
814 break;
815 case TODO_PRIVATE:
816 sprintf(buffer,"Private = %i%c%c",ToDo->Entries[j].Number,13,10);
817 SaveBackupText(file, "", buffer, UseUnicode);
818 break;
819 case TODO_CATEGORY:
820 sprintf(buffer,"Category = %i%c%c",ToDo->Entries[j].Number,13,10);
821 SaveBackupText(file, "", buffer, UseUnicode);
822 break;
823 case TODO_CONTACTID:
824 sprintf(buffer,"ContactID = %i%c%c",ToDo->Entries[j].Number,13,10);
825 SaveBackupText(file, "", buffer, UseUnicode);
826 break;
827 case TODO_PHONE:
828 SaveBackupText(file, "Phone", ToDo->Entries[j].Text, UseUnicode);
829 break;
832 sprintf(buffer,"%c%c",13,10);
833 SaveBackupText(file, "", buffer, UseUnicode);
836 static void SaveProfileEntry(FILE *file, GSM_Profile *Profile, bool UseUnicode)
838 int j,k;
839 bool special;
840 unsigned char buffer[1000];
842 sprintf(buffer,"Location = %i%c%c",Profile->Location,13,10);
843 SaveBackupText(file, "", buffer, UseUnicode);
844 SaveBackupText(file, "Name",Profile->Name, UseUnicode);
846 if (Profile->DefaultName) {
847 sprintf(buffer,"DefaultName = true%c%c",13,10);
848 SaveBackupText(file, "", buffer, UseUnicode);
850 if (Profile->HeadSetProfile) {
851 sprintf(buffer,"HeadSetProfile = true%c%c",13,10);
852 SaveBackupText(file, "", buffer, UseUnicode);
854 if (Profile->CarKitProfile) {
855 sprintf(buffer,"CarKitProfile = true%c%c",13,10);
856 SaveBackupText(file, "", buffer, UseUnicode);
859 for (j=0;j<Profile->FeaturesNumber;j++) {
860 sprintf(buffer,"Feature%02i = ",j);
861 SaveBackupText(file, "", buffer, UseUnicode);
862 special = false;
863 switch (Profile->FeatureID[j]) {
864 case Profile_MessageToneID:
865 case Profile_RingtoneID:
866 special = true;
867 if (Profile->FeatureID[j] == Profile_RingtoneID) {
868 sprintf(buffer,"RingtoneID%c%c",13,10);
869 } else {
870 sprintf(buffer,"MessageToneID%c%c",13,10);
872 SaveBackupText(file, "", buffer, UseUnicode);
873 sprintf(buffer,"Value%02i = %i%c%c",j,Profile->FeatureValue[j],13,10);
874 SaveBackupText(file, "", buffer, UseUnicode);
875 break;
876 case Profile_CallerGroups:
877 special = true;
878 sprintf(buffer,"CallerGroups%c%c",13,10);
879 SaveBackupText(file, "", buffer, UseUnicode);
880 sprintf(buffer,"Value%02i = ",j);
881 SaveBackupText(file, "", buffer, UseUnicode);
882 for (k=0;k<5;k++) {
883 if (Profile->CallerGroups[k]) {
884 sprintf(buffer,"%i",k);
885 SaveBackupText(file, "", buffer, UseUnicode);
888 sprintf(buffer,"%c%c",13,10);
889 SaveBackupText(file, "", buffer, UseUnicode);
890 break;
891 case Profile_ScreenSaverNumber:
892 special = true;
893 sprintf(buffer,"ScreenSaverNumber%c%c",13,10);
894 SaveBackupText(file, "", buffer, UseUnicode);
895 sprintf(buffer,"Value%02i = %i%c%c",j,Profile->FeatureValue[j],13,10);
896 SaveBackupText(file, "", buffer, UseUnicode);
897 break;
898 case Profile_CallAlert : sprintf(buffer,"IncomingCallAlert%c%c",13,10); break;
899 case Profile_RingtoneVolume : sprintf(buffer,"RingtoneVolume%c%c",13,10); break;
900 case Profile_Vibration : sprintf(buffer,"Vibrating%c%c",13,10); break;
901 case Profile_MessageTone : sprintf(buffer,"MessageTone%c%c",13,10); break;
902 case Profile_KeypadTone : sprintf(buffer,"KeypadTones%c%c",13,10); break;
903 case Profile_WarningTone : sprintf(buffer,"WarningTones%c%c",13,10); break;
904 case Profile_ScreenSaver : sprintf(buffer,"ScreenSaver%c%c",13,10); break;
905 case Profile_ScreenSaverTime : sprintf(buffer,"ScreenSaverTimeout%c%c",13,10); break;
906 case Profile_AutoAnswer : sprintf(buffer,"AutomaticAnswer%c%c",13,10); break;
907 case Profile_Lights : sprintf(buffer,"Lights%c%c",13,10); break;
908 default : special = true;
910 if (!special) {
911 SaveBackupText(file, "", buffer, UseUnicode);
912 sprintf(buffer,"Value%02i = ",j);
913 SaveBackupText(file, "", buffer, UseUnicode);
914 switch (Profile->FeatureValue[j]) {
915 case PROFILE_VOLUME_LEVEL1 :
916 case PROFILE_KEYPAD_LEVEL1 : sprintf(buffer,"Level1%c%c",13,10); break;
917 case PROFILE_VOLUME_LEVEL2 :
918 case PROFILE_KEYPAD_LEVEL2 : sprintf(buffer,"Level2%c%c",13,10); break;
919 case PROFILE_VOLUME_LEVEL3 :
920 case PROFILE_KEYPAD_LEVEL3 : sprintf(buffer,"Level3%c%c",13,10); break;
921 case PROFILE_VOLUME_LEVEL4 : sprintf(buffer,"Level4%c%c",13,10); break;
922 case PROFILE_VOLUME_LEVEL5 : sprintf(buffer,"Level5%c%c",13,10); break;
923 case PROFILE_MESSAGE_NOTONE :
924 case PROFILE_AUTOANSWER_OFF :
925 case PROFILE_LIGHTS_OFF :
926 case PROFILE_SAVER_OFF :
927 case PROFILE_WARNING_OFF :
928 case PROFILE_CALLALERT_OFF :
929 case PROFILE_VIBRATION_OFF :
930 case PROFILE_KEYPAD_OFF : sprintf(buffer,"Off%c%c",13,10); break;
931 case PROFILE_CALLALERT_RINGING : sprintf(buffer,"Ringing%c%c",13,10); break;
932 case PROFILE_CALLALERT_RINGONCE : sprintf(buffer,"RingOnce%c%c",13,10); break;
933 case PROFILE_CALLALERT_ASCENDING : sprintf(buffer,"Ascending%c%c",13,10); break;
934 case PROFILE_CALLALERT_CALLERGROUPS : sprintf(buffer,"CallerGroups%c%c",13,10); break;
935 case PROFILE_MESSAGE_STANDARD : sprintf(buffer,"Standard%c%c",13,10); break;
936 case PROFILE_MESSAGE_SPECIAL : sprintf(buffer,"Special%c%c",13,10); break;
937 case PROFILE_MESSAGE_BEEPONCE :
938 case PROFILE_CALLALERT_BEEPONCE : sprintf(buffer,"BeepOnce%c%c",13,10); break;
939 case PROFILE_MESSAGE_ASCENDING : sprintf(buffer,"Ascending%c%c",13,10); break;
940 case PROFILE_MESSAGE_PERSONAL : sprintf(buffer,"Personal%c%c",13,10); break;
941 case PROFILE_AUTOANSWER_ON :
942 case PROFILE_WARNING_ON :
943 case PROFILE_SAVER_ON :
944 case PROFILE_VIBRATION_ON : sprintf(buffer,"On%c%c",13,10); break;
945 case PROFILE_VIBRATION_FIRST : sprintf(buffer,"VibrateFirst%c%c",13,10); break;
946 case PROFILE_LIGHTS_AUTO : sprintf(buffer,"Auto%c%c",13,10); break;
947 case PROFILE_SAVER_TIMEOUT_5SEC : sprintf(buffer,"5Seconds%c%c",13,10); break;
948 case PROFILE_SAVER_TIMEOUT_20SEC : sprintf(buffer,"20Seconds%c%c",13,10); break;
949 case PROFILE_SAVER_TIMEOUT_1MIN : sprintf(buffer,"1Minute%c%c",13,10); break;
950 case PROFILE_SAVER_TIMEOUT_2MIN : sprintf(buffer,"2Minutes%c%c",13,10); break;
951 case PROFILE_SAVER_TIMEOUT_5MIN : sprintf(buffer,"5Minutes%c%c",13,10); break;
952 case PROFILE_SAVER_TIMEOUT_10MIN : sprintf(buffer,"10Minutes%c%c",13,10); break;
953 default : sprintf(buffer,"UNKNOWN%c%c",13,10);
955 SaveBackupText(file, "", buffer, UseUnicode);
958 sprintf(buffer,"%c%c",13,10);
959 SaveBackupText(file, "", buffer, UseUnicode);
962 static void SaveFMStationEntry(FILE *file, GSM_FMStation *FMStation, bool UseUnicode)
964 unsigned char buffer[1000];
966 sprintf(buffer,"Location = %i%c%c",FMStation->Location,13,10);
967 SaveBackupText(file, "", buffer, UseUnicode);
968 SaveBackupText(file, "StationName", FMStation->StationName, UseUnicode);
969 sprintf(buffer,"Frequency = %f%c%c",FMStation->Frequency,13,10);
970 SaveBackupText(file, "", buffer, UseUnicode);
971 sprintf(buffer,"%c%c",13,10);
972 SaveBackupText(file, "", buffer, UseUnicode);
975 static void SaveGPRSPointEntry(FILE *file, GSM_GPRSAccessPoint *GPRSPoint, bool UseUnicode)
977 unsigned char buffer[1000];
979 sprintf(buffer,"Location = %i%c%c",GPRSPoint->Location,13,10);
980 SaveBackupText(file, "", buffer, UseUnicode);
981 SaveBackupText(file, "Name", GPRSPoint->Name, UseUnicode);
982 SaveBackupText(file, "URL", GPRSPoint->URL, UseUnicode);
983 if (GPRSPoint->Active) {
984 sprintf(buffer,"Active = Yes%c%c",13,10);
985 SaveBackupText(file, "", buffer, UseUnicode);
987 sprintf(buffer,"%c%c",13,10);
988 SaveBackupText(file, "", buffer, UseUnicode);
991 GSM_Error SaveBackup(char *FileName, GSM_Backup *backup, bool UseUnicode)
993 int i;
994 unsigned char buffer[1000],checksum[200];
995 FILE *file;
997 file = fopen(FileName, "wb");
998 if (file == NULL) return GE_CANTOPENFILE;
1000 if (UseUnicode) {
1001 sprintf(buffer,"%c%c", 0xFE, 0xFF);
1002 SaveBackupText(file, "", buffer, false);
1005 sprintf(buffer,"# Backup file created by Gammu (www.mwiacek.com) version %s%c%c%c%c",VERSION,13,10,13,10);
1006 SaveBackupText(file, "", buffer, UseUnicode);
1007 sprintf(buffer,"[Backup]%c%c",13,10);
1008 SaveBackupText(file, "", buffer, UseUnicode);
1009 sprintf(buffer,"IMEI = \"%s\"%c%c",backup->IMEI,13,10);
1010 SaveBackupText(file, "", buffer, UseUnicode);
1011 sprintf(buffer,"Phone = \"%s\"%c%c",backup->Model,13,10);
1012 SaveBackupText(file, "", buffer, UseUnicode);
1013 if (backup->DateTimeAvailable) {
1014 SaveBackupText(file, "", "DateTime", UseUnicode);
1015 SaveVCalDateTime(file, &backup->DateTime, UseUnicode);
1017 sprintf(buffer,"Format = 1.03%c%c",13,10);
1018 SaveBackupText(file, "", buffer, UseUnicode);
1019 sprintf(buffer,"%c%c",13,10);
1020 SaveBackupText(file, "", buffer, UseUnicode);
1022 i=0;
1023 while (backup->PhonePhonebook[i]!=NULL) {
1024 sprintf(buffer,"[PhonePBK%03i]%c%c",i+1,13,10);
1025 SaveBackupText(file, "", buffer, UseUnicode);
1026 SavePbkEntry(file, backup->PhonePhonebook[i], UseUnicode);
1027 i++;
1029 i=0;
1030 while (backup->SIMPhonebook[i]!=NULL) {
1031 sprintf(buffer,"[SIMPBK%03i]%c%c",i+1,13,10);
1032 SaveBackupText(file, "", buffer, UseUnicode);
1033 SavePbkEntry(file, backup->SIMPhonebook[i], UseUnicode);
1034 i++;
1036 i=0;
1037 while (backup->Calendar[i]!=NULL) {
1038 sprintf(buffer,"[Calendar%03i]%c%c",i+1,13,10);
1039 SaveBackupText(file, "", buffer, UseUnicode);
1040 SaveCalendarEntry(file, backup->Calendar[i], UseUnicode);
1041 i++;
1043 i=0;
1044 while (backup->CallerLogos[i]!=NULL) {
1045 sprintf(buffer,"[Caller%03i]%c%c",i+1,13,10);
1046 SaveBackupText(file, "", buffer, UseUnicode);
1047 SaveCallerEntry(file, backup->CallerLogos[i], UseUnicode);
1048 i++;
1050 i=0;
1051 while (backup->SMSC[i]!=NULL) {
1052 sprintf(buffer,"[SMSC%03i]%c%c",i+1,13,10);
1053 SaveBackupText(file, "", buffer, UseUnicode);
1054 SaveSMSCEntry(file, backup->SMSC[i], UseUnicode);
1055 i++;
1057 i=0;
1058 while (backup->WAPBookmark[i]!=NULL) {
1059 sprintf(buffer,"[WAPBookmark%03i]%c%c",i+1,13,10);
1060 SaveBackupText(file, "", buffer, UseUnicode);
1061 SaveWAPBookmarkEntry(file, backup->WAPBookmark[i], UseUnicode);
1062 i++;
1064 i=0;
1065 while (backup->WAPSettings[i]!=NULL) {
1066 sprintf(buffer,"[WAPSettings%03i]%c%c",i+1,13,10);
1067 SaveBackupText(file, "", buffer, UseUnicode);
1068 SaveWAPSettingsEntry(file, backup->WAPSettings[i], UseUnicode);
1069 i++;
1071 i=0;
1072 while (backup->MMSSettings[i]!=NULL) {
1073 sprintf(buffer,"[MMSSettings%03i]%c%c",i+1,13,10);
1074 SaveBackupText(file, "", buffer, UseUnicode);
1075 SaveWAPSettingsEntry(file, backup->MMSSettings[i], UseUnicode);
1076 i++;
1078 i=0;
1079 while (backup->Ringtone[i]!=NULL) {
1080 sprintf(buffer,"[Ringtone%03i]%c%c",i+1,13,10);
1081 SaveBackupText(file, "", buffer, UseUnicode);
1082 SaveRingtoneEntry(file, backup->Ringtone[i], UseUnicode);
1083 i++;
1085 i=0;
1086 while (backup->ToDo[i]!=NULL) {
1087 sprintf(buffer,"[TODO%03i]%c%c",i+1,13,10);
1088 SaveBackupText(file, "", buffer, UseUnicode);
1089 SaveToDoEntry(file, backup->ToDo[i], UseUnicode);
1090 i++;
1092 i=0;
1093 while (backup->Profiles[i]!=NULL) {
1094 sprintf(buffer,"[Profile%03i]%c%c",i+1,13,10);
1095 SaveBackupText(file, "", buffer, UseUnicode);
1096 SaveProfileEntry(file, backup->Profiles[i], UseUnicode);
1097 i++;
1099 i=0;
1100 while (backup->FMStation[i]!=NULL) {
1101 sprintf(buffer,"[FMStation%03i]%c%c",i+1,13,10);
1102 SaveBackupText(file, "", buffer, UseUnicode);
1103 SaveFMStationEntry(file, backup->FMStation[i], UseUnicode);
1104 i++;
1106 i=0;
1107 while (backup->GPRSPoint[i]!=NULL) {
1108 sprintf(buffer,"[GPRSPoint%03i]%c%c",i+1,13,10);
1109 SaveBackupText(file, "", buffer, UseUnicode);
1110 SaveGPRSPointEntry(file, backup->GPRSPoint[i], UseUnicode);
1111 i++;
1114 if (backup->StartupLogo!=NULL) {
1115 SaveStartupEntry(file, backup->StartupLogo, UseUnicode);
1117 if (backup->OperatorLogo!=NULL) {
1118 SaveOperatorEntry(file, backup->OperatorLogo, UseUnicode);
1121 fclose(file);
1123 FindBackupChecksum(FileName, UseUnicode, checksum);
1125 file = fopen(FileName, "ab");
1126 if (file == NULL) return GE_CANTOPENFILE;
1127 sprintf(buffer,"[Checksum]%c%c",13,10);
1128 SaveBackupText(file, "", buffer, UseUnicode);
1129 sprintf(buffer,"MD5=%s%c%c",checksum,13,10);
1130 SaveBackupText(file, "", buffer, UseUnicode);
1131 fclose(file);
1133 return GE_NONE;
1136 static void ReadPbkEntry(INI_Section *file_info, char *section, GSM_MemoryEntry *Pbk, bool UseUnicode)
1138 unsigned char buffer[10000];
1139 char *readvalue;
1140 int num;
1141 INI_Entry *e;
1143 Pbk->EntriesNum = 0;
1144 e = INI_FindLastSectionEntry(file_info, section, UseUnicode);
1146 sprintf(buffer,"PreferUnicode");
1147 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1148 Pbk->PreferUnicode = false;
1149 if (readvalue!=NULL) {
1150 if (strncmp(readvalue, "yes", 3) == 0) Pbk->PreferUnicode = true;
1153 while (1) {
1154 if (e == NULL) break;
1155 num = -1;
1156 if (UseUnicode) {
1157 sprintf(buffer,"%s",DecodeUnicodeString(e->EntryName));
1158 } else {
1159 sprintf(buffer,"%s",e->EntryName);
1161 if (strlen(buffer) == 11) {
1162 if (mystrncasecmp("Entry", buffer, 5) &&
1163 mystrncasecmp("Type", buffer+7, 4)) {
1164 num = atoi(buffer+5);
1167 e = e->Prev;
1168 if (num != -1) {
1169 sprintf(buffer,"Entry%02iType",num);
1170 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1171 if (mystrncasecmp(readvalue,"NumberGeneral",0)) {
1172 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_General;
1173 } else if (mystrncasecmp(readvalue,"NumberMobile",0)) {
1174 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Mobile;
1175 } else if (mystrncasecmp(readvalue,"NumberWork",0)) {
1176 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Work;
1177 } else if (mystrncasecmp(readvalue,"NumberFax",0)) {
1178 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Fax;
1179 } else if (mystrncasecmp(readvalue,"NumberHome",0)) {
1180 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Home;
1181 } else if (mystrncasecmp(readvalue,"NumberOther",0)) {
1182 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Other;
1183 } else if (mystrncasecmp(readvalue,"NumberPager",0)) {
1184 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Pager;
1185 } else if (mystrncasecmp(readvalue,"Note",0)) {
1186 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Note;
1187 } else if (mystrncasecmp(readvalue,"Postal",0)) {
1188 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Postal;
1189 } else if (mystrncasecmp(readvalue,"Email",0)) {
1190 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Email;
1191 } else if (mystrncasecmp(readvalue,"Email2",0)) {
1192 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Email2;
1193 } else if (mystrncasecmp(readvalue,"URL",0)) {
1194 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_URL;
1195 } else if (mystrncasecmp(readvalue,"FirstName",0)) {
1196 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_FirstName;
1197 } else if (mystrncasecmp(readvalue,"LastName",0)) {
1198 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_LastName;
1199 } else if (mystrncasecmp(readvalue,"Company",0)) {
1200 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Company;
1201 } else if (mystrncasecmp(readvalue,"JobTitle",0)) {
1202 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_JobTitle;
1203 } else if (mystrncasecmp(readvalue,"StreetAddress",0)) {
1204 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_StreetAddress;
1205 } else if (mystrncasecmp(readvalue,"City",0)) {
1206 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_City;
1207 } else if (mystrncasecmp(readvalue,"State",0)) {
1208 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_State;
1209 } else if (mystrncasecmp(readvalue,"Zip",0)) {
1210 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Zip;
1211 } else if (mystrncasecmp(readvalue,"Country",0)) {
1212 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Country;
1213 } else if (mystrncasecmp(readvalue,"Custom1",0)) {
1214 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Custom1;
1215 } else if (mystrncasecmp(readvalue,"Custom2",0)) {
1216 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Custom2;
1217 } else if (mystrncasecmp(readvalue,"Custom3",0)) {
1218 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Custom3;
1219 } else if (mystrncasecmp(readvalue,"Custom4",0)) {
1220 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Custom4;
1221 } else if (mystrncasecmp(readvalue,"Name",0)) {
1222 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Name;
1223 } else if (mystrncasecmp(readvalue,"Category",0)) {
1224 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Category;
1225 Pbk->Entries[Pbk->EntriesNum].Number = 0;
1226 sprintf(buffer,"Entry%02iNumber",num);
1227 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1228 if (readvalue!=NULL) {
1229 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
1231 Pbk->EntriesNum ++;
1232 continue;
1233 } else if (mystrncasecmp(readvalue,"Private",0)) {
1234 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Private;
1235 Pbk->Entries[Pbk->EntriesNum].Number = 0;
1236 sprintf(buffer,"Entry%02iNumber",num);
1237 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1238 if (readvalue!=NULL) {
1239 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
1241 Pbk->EntriesNum ++;
1242 continue;
1243 } else if (mystrncasecmp(readvalue,"CallerGroup",0)) {
1244 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Caller_Group;
1245 Pbk->Entries[Pbk->EntriesNum].Number = 0;
1246 sprintf(buffer,"Entry%02iNumber",num);
1247 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1248 if (readvalue!=NULL) {
1249 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
1251 Pbk->EntriesNum ++;
1252 continue;
1253 } else if (mystrncasecmp(readvalue,"RingtoneID",0)) {
1254 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_RingtoneID;
1255 Pbk->Entries[Pbk->EntriesNum].Number = 0;
1256 sprintf(buffer,"Entry%02iNumber",num);
1257 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1258 if (readvalue!=NULL) {
1259 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
1261 Pbk->EntriesNum ++;
1262 continue;
1263 } else if (mystrncasecmp(readvalue,"PictureID",0)) {
1264 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_PictureID;
1265 Pbk->Entries[Pbk->EntriesNum].Number = 0;
1266 sprintf(buffer,"Entry%02iNumber",num);
1267 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1268 if (readvalue!=NULL) {
1269 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
1271 Pbk->EntriesNum ++;
1272 continue;
1274 sprintf(buffer,"Entry%02iText",num);
1275 ReadBackupText(file_info, section, buffer, Pbk->Entries[Pbk->EntriesNum].Text,UseUnicode);
1276 dbgprintf("text \"%s\", type %i\n",DecodeUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text),Pbk->Entries[Pbk->EntriesNum].EntryType);
1277 Pbk->Entries[Pbk->EntriesNum].VoiceTag = 0;
1278 sprintf(buffer,"Entry%02iVoiceTag",num);
1279 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1280 if (readvalue!=NULL) {
1281 Pbk->Entries[Pbk->EntriesNum].VoiceTag = atoi(readvalue);
1283 Pbk->EntriesNum ++;
1288 static void ReadCalendarEntry(INI_Section *file_info, char *section, GSM_CalendarEntry *note, bool UseUnicode)
1290 unsigned char buffer[10000];
1291 char *readvalue;
1293 sprintf(buffer,"Location");
1294 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1295 if (readvalue!=NULL) note->Location = atoi(readvalue);
1297 sprintf(buffer,"Type");
1298 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1299 note->Type = GCN_REMINDER;
1300 if (readvalue!=NULL)
1302 if (mystrncasecmp(readvalue,"Call",0)) {
1303 note->Type = GCN_CALL;
1304 } else if (mystrncasecmp(readvalue,"Meeting",0)) {
1305 note->Type = GCN_MEETING;
1306 } else if (mystrncasecmp(readvalue,"Birthday",0)) {
1307 note->Type = GCN_BIRTHDAY;
1308 } else if (mystrncasecmp(readvalue,"Memo",0)) {
1309 note->Type = GCN_MEMO;
1310 } else if (mystrncasecmp(readvalue,"Travel",0)) {
1311 note->Type = GCN_TRAVEL;
1312 } else if (mystrncasecmp(readvalue,"Vacation",0)) {
1313 note->Type = GCN_VACATION;
1314 } else if (mystrncasecmp(readvalue,"DailyAlarm",0)) {
1315 note->Type = GCN_DAILY_ALARM;
1316 } else if (mystrncasecmp(readvalue,"Alarm",0)) {
1317 note->Type = GCN_ALARM;
1318 } else if (mystrncasecmp(readvalue,"Training/Athletism",0)) {
1319 note->Type = GCN_T_ATHL;
1320 } else if (mystrncasecmp(readvalue,"Training/BallGames",0)) {
1321 note->Type = GCN_T_BALL;
1322 } else if (mystrncasecmp(readvalue,"Training/Cycling",0)) {
1323 note->Type = GCN_T_CYCL;
1324 } else if (mystrncasecmp(readvalue,"Training/Budo",0)) {
1325 note->Type = GCN_T_BUDO;
1326 } else if (mystrncasecmp(readvalue,"Training/Dance",0)) {
1327 note->Type = GCN_T_DANC;
1328 } else if (mystrncasecmp(readvalue,"Training/ExtremeSports",0)) {
1329 note->Type = GCN_T_EXTR;
1330 } else if (mystrncasecmp(readvalue,"Training/Football",0)) {
1331 note->Type = GCN_T_FOOT;
1332 } else if (mystrncasecmp(readvalue,"Training/Golf",0)) {
1333 note->Type = GCN_T_GOLF;
1334 } else if (mystrncasecmp(readvalue,"Training/Gym",0)) {
1335 note->Type = GCN_T_GYM;
1336 } else if (mystrncasecmp(readvalue,"Training/HorseRaces",0)) {
1337 note->Type = GCN_T_HORS;
1338 } else if (mystrncasecmp(readvalue,"Training/Hockey",0)) {
1339 note->Type = GCN_T_HOCK;
1340 } else if (mystrncasecmp(readvalue,"Training/Races",0)) {
1341 note->Type = GCN_T_RACE;
1342 } else if (mystrncasecmp(readvalue,"Training/Rugby",0)) {
1343 note->Type = GCN_T_RUGB;
1344 } else if (mystrncasecmp(readvalue,"Training/Sailing",0)) {
1345 note->Type = GCN_T_SAIL;
1346 } else if (mystrncasecmp(readvalue,"Training/StreetGames",0)) {
1347 note->Type = GCN_T_STRE;
1348 } else if (mystrncasecmp(readvalue,"Training/Swimming",0)) {
1349 note->Type = GCN_T_SWIM;
1350 } else if (mystrncasecmp(readvalue,"Training/Tennis",0)) {
1351 note->Type = GCN_T_TENN;
1352 } else if (mystrncasecmp(readvalue,"Training/Travels",0)) {
1353 note->Type = GCN_T_TRAV;
1354 } else if (mystrncasecmp(readvalue,"Training/WinterGames",0)) {
1355 note->Type = GCN_T_WINT;
1358 note->EntriesNum = 0;
1359 sprintf(buffer,"Text");
1360 if (ReadBackupText(file_info, section, buffer, note->Entries[note->EntriesNum].Text,UseUnicode)) {
1361 note->Entries[note->EntriesNum].EntryType = CAL_TEXT;
1362 note->EntriesNum++;
1364 sprintf(buffer,"Phone");
1365 if (ReadBackupText(file_info, section, buffer, note->Entries[note->EntriesNum].Text,UseUnicode)) {
1366 note->Entries[note->EntriesNum].EntryType = CAL_PHONE;
1367 note->EntriesNum++;
1369 sprintf(buffer,"Private");
1370 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1371 if (readvalue!=NULL) {
1372 note->Entries[note->EntriesNum].Number = atoi(readvalue);
1373 note->Entries[note->EntriesNum].EntryType = CAL_PRIVATE;
1374 note->EntriesNum++;
1376 sprintf(buffer,"EventLocation");
1377 if (ReadBackupText(file_info, section, buffer, note->Entries[note->EntriesNum].Text,UseUnicode)) {
1378 note->Entries[note->EntriesNum].EntryType = CAL_LOCATION;
1379 note->EntriesNum++;
1381 sprintf(buffer,"ContactID");
1382 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1383 if (readvalue!=NULL) {
1384 note->Entries[note->EntriesNum].Number = atoi(readvalue);
1385 note->Entries[note->EntriesNum].EntryType = CAL_CONTACTID;
1386 note->EntriesNum++;
1388 sprintf(buffer,"Recurrance");
1389 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1390 if (readvalue!=NULL) {
1391 note->Entries[note->EntriesNum].Number = atoi(readvalue) * 24;
1392 note->Entries[note->EntriesNum].EntryType = CAL_RECURRANCE;
1393 note->EntriesNum++;
1395 sprintf(buffer,"StartTime");
1396 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1397 if (readvalue!=NULL) {
1398 ReadVCALDateTime(readvalue, &note->Entries[note->EntriesNum].Date);
1399 note->Entries[note->EntriesNum].EntryType = CAL_START_DATETIME;
1400 note->EntriesNum++;
1402 sprintf(buffer,"StopTime");
1403 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1404 if (readvalue!=NULL) {
1405 ReadVCALDateTime(readvalue, &note->Entries[note->EntriesNum].Date);
1406 note->Entries[note->EntriesNum].EntryType = CAL_END_DATETIME;
1407 note->EntriesNum++;
1409 sprintf(buffer,"Alarm");
1410 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1411 if (readvalue!=NULL)
1413 ReadVCALDateTime(readvalue, &note->Entries[note->EntriesNum].Date);
1414 note->Entries[note->EntriesNum].EntryType = CAL_ALARM_DATETIME;
1415 sprintf(buffer,"AlarmType");
1416 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1417 if (readvalue!=NULL)
1419 if (mystrncasecmp(readvalue,"Silent",0)) {
1420 note->Entries[note->EntriesNum].EntryType = CAL_SILENT_ALARM_DATETIME;
1423 note->EntriesNum++;
1425 sprintf(buffer,"RepeatStartDate");
1426 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1427 if (readvalue!=NULL) {
1428 ReadVCALDateTime(readvalue, &note->Entries[note->EntriesNum].Date);
1429 note->Entries[note->EntriesNum].EntryType = CAL_REPEAT_STARTDATE;
1430 note->EntriesNum++;
1432 sprintf(buffer,"RepeatStopDate");
1433 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1434 if (readvalue!=NULL) {
1435 ReadVCALDateTime(readvalue, &note->Entries[note->EntriesNum].Date);
1436 note->Entries[note->EntriesNum].EntryType = CAL_REPEAT_STOPDATE;
1437 note->EntriesNum++;
1439 sprintf(buffer,"RepeatDayOfWeek");
1440 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1441 if (readvalue!=NULL) {
1442 note->Entries[note->EntriesNum].Number = atoi(readvalue);
1443 note->Entries[note->EntriesNum].EntryType = CAL_REPEAT_DAYOFWEEK;
1444 note->EntriesNum++;
1446 sprintf(buffer,"RepeatDay");
1447 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1448 if (readvalue!=NULL) {
1449 note->Entries[note->EntriesNum].Number = atoi(readvalue);
1450 note->Entries[note->EntriesNum].EntryType = CAL_REPEAT_DAY;
1451 note->EntriesNum++;
1453 sprintf(buffer,"RepeatWeekOfMonth");
1454 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1455 if (readvalue!=NULL) {
1456 note->Entries[note->EntriesNum].Number = atoi(readvalue);
1457 note->Entries[note->EntriesNum].EntryType = CAL_REPEAT_WEEKOFMONTH;
1458 note->EntriesNum++;
1460 sprintf(buffer,"RepeatMonth");
1461 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1462 if (readvalue!=NULL) {
1463 note->Entries[note->EntriesNum].Number = atoi(readvalue);
1464 note->Entries[note->EntriesNum].EntryType = CAL_REPEAT_MONTH;
1465 note->EntriesNum++;
1467 sprintf(buffer,"RepeatFrequency");
1468 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1469 if (readvalue!=NULL) {
1470 note->Entries[note->EntriesNum].Number = atoi(readvalue);
1471 note->Entries[note->EntriesNum].EntryType = CAL_REPEAT_FREQUENCY;
1472 note->EntriesNum++;
1476 static void ReadToDoEntry(INI_Section *file_info, char *section, GSM_ToDoEntry *ToDo, bool UseUnicode)
1478 unsigned char buffer[10000];
1479 char *readvalue;
1481 ToDo->EntriesNum = 0;
1483 sprintf(buffer,"Location");
1484 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1485 if (readvalue!=NULL) ToDo->Location = atoi(readvalue);
1487 ToDo->Priority = GSM_Priority_High;
1488 sprintf(buffer,"Priority");
1489 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1490 if (readvalue!=NULL) {
1491 if (!strcmp(readvalue,"3") || !strcmp(readvalue,"Low")) {
1492 ToDo->Priority = GSM_Priority_Low;
1494 if (!strcmp(readvalue,"2") || !strcmp(readvalue,"Medium")) {
1495 ToDo->Priority = GSM_Priority_Medium;
1499 sprintf(buffer,"Text");
1500 if (ReadBackupText(file_info, section, buffer, ToDo->Entries[ToDo->EntriesNum].Text,UseUnicode)) {
1501 ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_TEXT;
1502 ToDo->EntriesNum++;
1505 sprintf(buffer,"Phone");
1506 if (ReadBackupText(file_info, section, buffer, ToDo->Entries[ToDo->EntriesNum].Text,UseUnicode)) {
1507 ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_PHONE;
1508 ToDo->EntriesNum++;
1511 sprintf(buffer,"Private");
1512 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1513 if (readvalue!=NULL) {
1514 ToDo->Entries[ToDo->EntriesNum].Number = atoi(readvalue);
1515 ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_PRIVATE;
1516 ToDo->EntriesNum++;
1519 sprintf(buffer,"Completed");
1520 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1521 if (readvalue!=NULL) {
1522 if (strncmp(readvalue, "yes", 3) == 0) {
1523 ToDo->Entries[ToDo->EntriesNum].Number = 1;
1524 } else {
1525 ToDo->Entries[ToDo->EntriesNum].Number = 0;
1527 ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_COMPLETED;
1528 ToDo->EntriesNum++;
1531 sprintf(buffer,"Category");
1532 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1533 if (readvalue!=NULL) {
1534 ToDo->Entries[ToDo->EntriesNum].Number = atoi(readvalue);
1535 ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_CATEGORY;
1536 ToDo->EntriesNum++;
1539 sprintf(buffer,"ContactID");
1540 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1541 if (readvalue!=NULL) {
1542 ToDo->Entries[ToDo->EntriesNum].Number = atoi(readvalue);
1543 ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_CONTACTID;
1544 ToDo->EntriesNum++;
1547 sprintf(buffer,"DueTime");
1548 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1549 if (readvalue!=NULL) {
1550 ReadVCALDateTime(readvalue, &ToDo->Entries[ToDo->EntriesNum].Date);
1551 ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_END_DATETIME;
1552 ToDo->EntriesNum++;
1555 sprintf(buffer,"Alarm");
1556 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1557 if (readvalue!=NULL) {
1558 ReadVCALDateTime(readvalue, &ToDo->Entries[ToDo->EntriesNum].Date);
1559 ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_ALARM_DATETIME;
1560 ToDo->EntriesNum++;
1563 sprintf(buffer,"SilentAlarm");
1564 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1565 if (readvalue!=NULL) {
1566 ReadVCALDateTime(readvalue, &ToDo->Entries[ToDo->EntriesNum].Date);
1567 ToDo->Entries[ToDo->EntriesNum].EntryType = TODO_SILENT_ALARM_DATETIME;
1568 ToDo->EntriesNum++;
1572 static bool ReadBitmapEntry(INI_Section *file_info, char *section, GSM_Bitmap *bitmap, bool UseUnicode)
1574 char *readvalue;
1575 unsigned char buffer[10000];
1576 unsigned char Width, Height;
1577 int x, y;
1579 GSM_GetMaxBitmapWidthHeight(bitmap->Type, &Width, &Height);
1580 sprintf(buffer,"Width");
1581 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1582 if (readvalue==NULL) bitmap->Width = Width; else bitmap->Width = atoi(readvalue);
1583 sprintf(buffer,"Height");
1584 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1585 if (readvalue==NULL) bitmap->Height = Height; else bitmap->Height = atoi(readvalue);
1586 GSM_ClearBitmap(bitmap);
1587 for (y=0;y<bitmap->Height;y++) {
1588 sprintf(buffer,"Bitmap%02i",y);
1589 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1590 if (readvalue!=NULL) {
1591 for (x=0;x<bitmap->Width;x++) {
1592 if (readvalue[x+1]=='#') GSM_SetPointBitmap(bitmap,x,y);
1594 } else return false;
1596 return true;
1599 static void ReadCallerEntry(INI_Section *file_info, char *section, GSM_Bitmap *bitmap, bool UseUnicode)
1601 unsigned char buffer[10000];
1602 char *readvalue;
1604 bitmap->Type = GSM_CallerLogo;
1605 bitmap->DefaultBitmap = !ReadBitmapEntry(file_info, section, bitmap, UseUnicode);
1606 if (bitmap->DefaultBitmap) {
1607 bitmap->Width = 72;
1608 bitmap->Height = 14;
1609 GSM_ClearBitmap(bitmap);
1611 sprintf(buffer,"Name");
1612 ReadBackupText(file_info, section, buffer, bitmap->Text,UseUnicode);
1613 if (bitmap->Text[0] == 0x00 && bitmap->Text[1] == 0x00) {
1614 bitmap->DefaultName = true;
1615 } else {
1616 bitmap->DefaultName = false;
1618 sprintf(buffer,"Ringtone");
1619 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1620 if (readvalue==NULL) {
1621 bitmap->DefaultRingtone = true;
1622 } else {
1623 DecodeHexBin (&bitmap->Ringtone, readvalue, 2);
1624 bitmap->DefaultRingtone = false;
1626 sprintf(buffer,"Enabled");
1627 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1628 bitmap->Enabled = true;
1629 if (readvalue!=NULL) {
1630 if (mystrncasecmp(readvalue,"False",0)) bitmap->Enabled = false;
1634 static void ReadStartupEntry(INI_Section *file_info, char *section, GSM_Bitmap *bitmap, bool UseUnicode)
1636 unsigned char buffer[10000];
1638 sprintf(buffer,"Text");
1639 ReadBackupText(file_info, section, buffer, bitmap->Text,UseUnicode);
1640 if (bitmap->Text[0]!=0 || bitmap->Text[1]!=0) {
1641 bitmap->Type = GSM_WelcomeNoteText;
1642 } else {
1643 bitmap->Type = GSM_StartupLogo;
1644 bitmap->Location = 1;
1645 ReadBitmapEntry(file_info, section, bitmap, UseUnicode);
1646 #ifdef DEBUG
1647 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) GSM_PrintBitmap(di.df,bitmap);
1648 #endif
1652 static void ReadWAPBookmarkEntry(INI_Section *file_info, char *section, GSM_WAPBookmark *bookmark, bool UseUnicode)
1654 unsigned char buffer[10000];
1656 sprintf(buffer,"URL");
1657 ReadBackupText(file_info, section, buffer, bookmark->Address,UseUnicode);
1658 sprintf(buffer,"Title");
1659 ReadBackupText(file_info, section, buffer, bookmark->Title,UseUnicode);
1662 static void ReadOperatorEntry(INI_Section *file_info, char *section, GSM_Bitmap *bitmap, bool UseUnicode)
1664 unsigned char buffer[10000];
1665 char *readvalue;
1667 sprintf(buffer,"Network");
1668 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1669 memcpy(bitmap->NetworkCode, readvalue + 1, 6);
1670 bitmap->NetworkCode[6] = 0;
1671 bitmap->Type = GSM_OperatorLogo;
1672 ReadBitmapEntry(file_info, section, bitmap, UseUnicode);
1675 static void ReadSMSCEntry(INI_Section *file_info, char *section, GSM_SMSC *SMSC, bool UseUnicode)
1677 unsigned char buffer[10000];
1678 char *readvalue;
1680 sprintf(buffer,"Name");
1681 ReadBackupText(file_info, section, buffer, SMSC->Name,UseUnicode);
1682 sprintf(buffer,"Number");
1683 ReadBackupText(file_info, section, buffer, SMSC->Number,UseUnicode);
1684 sprintf(buffer,"DefaultNumber");
1685 ReadBackupText(file_info, section, buffer, SMSC->DefaultNumber,UseUnicode);
1686 sprintf(buffer,"Format");
1687 SMSC->Format = GSMF_Text;
1688 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1689 if (readvalue!=NULL) {
1690 if (mystrncasecmp(readvalue,"Fax",0)) {
1691 SMSC->Format = GSMF_Fax;
1692 } else if (mystrncasecmp(readvalue,"Email",0)) {
1693 SMSC->Format = GSMF_Email;
1694 } else if (mystrncasecmp(readvalue,"Pager",0)) {
1695 SMSC->Format = GSMF_Pager;
1698 sprintf(buffer,"Validity");
1699 SMSC->Validity.Relative = GSMV_Max_Time;
1700 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1701 if (readvalue!=NULL)
1703 if (mystrncasecmp(readvalue,"1hour",0)) {
1704 SMSC->Validity.Relative = GSMV_1_Hour;
1705 } else if (mystrncasecmp(readvalue,"6hours",0)) {
1706 SMSC->Validity.Relative = GSMV_6_Hours;
1707 } else if (mystrncasecmp(readvalue,"24hours",0)) {
1708 SMSC->Validity.Relative = GSMV_24_Hours;
1709 } else if (mystrncasecmp(readvalue,"72hours",0)) {
1710 SMSC->Validity.Relative = GSMV_72_Hours;
1711 } else if (mystrncasecmp(readvalue,"1week",0)) {
1712 SMSC->Validity.Relative = GSMV_1_Week;
1717 static void ReadWAPSettingsEntry(INI_Section *file_info, char *section, GSM_MultiWAPSettings *settings, bool UseUnicode)
1719 unsigned char buffer[10000], *readvalue;
1720 int num;
1721 INI_Entry *e;
1723 settings->ActiveBearer = WAPSETTINGS_BEARER_DATA;
1724 sprintf(buffer,"Bearer");
1725 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1726 if (readvalue!=NULL) {
1727 if (mystrncasecmp(readvalue,"SMS",0)) {
1728 settings->ActiveBearer = WAPSETTINGS_BEARER_SMS;
1729 } else if (mystrncasecmp(readvalue,"GPRS",0)) {
1730 settings->ActiveBearer = WAPSETTINGS_BEARER_GPRS;
1731 } else if (mystrncasecmp(readvalue,"USSD",0)) {
1732 settings->ActiveBearer = WAPSETTINGS_BEARER_USSD;
1736 settings->Active = false;
1737 sprintf(buffer,"Active");
1738 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1739 if (readvalue!=NULL) {
1740 if (mystrncasecmp(readvalue,"Yes",0)) settings->Active = true;
1743 settings->Number = 0;
1744 e = INI_FindLastSectionEntry(file_info, section, UseUnicode);
1745 while (1) {
1746 if (e == NULL) break;
1747 num = -1;
1748 if (UseUnicode) {
1749 sprintf(buffer,"%s",DecodeUnicodeString(e->EntryName));
1750 } else {
1751 sprintf(buffer,"%s",e->EntryName);
1753 if (strlen(buffer) == 7) {
1754 if (mystrncasecmp("Title", buffer,5)) num = atoi(buffer+5);
1756 e = e->Prev;
1757 if (num != -1) {
1758 sprintf(buffer,"Title%02i",num);
1759 ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].Title,UseUnicode);
1760 sprintf(buffer,"HomePage%02i",num);
1761 ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].HomePage,UseUnicode);
1762 sprintf(buffer,"Type%02i",num);
1763 settings->Settings[settings->Number].IsContinuous = true;
1764 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1765 if (readvalue!=NULL) {
1766 if (mystrncasecmp(readvalue,"Temporary",0)) settings->Settings[settings->Number].IsContinuous = false;
1768 sprintf(buffer,"Security%02i",num);
1769 settings->Settings[settings->Number].IsSecurity = true;
1770 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1771 if (readvalue!=NULL)
1773 if (mystrncasecmp(readvalue,"Off",0)) settings->Settings[settings->Number].IsSecurity = false;
1775 sprintf(buffer,"Bearer%02i",num);
1776 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1777 if (readvalue!=NULL)
1779 if (mystrncasecmp(readvalue,"SMS",0)) {
1780 settings->Settings[settings->Number].Bearer = WAPSETTINGS_BEARER_SMS;
1781 sprintf(buffer,"Server%02i",num);
1782 ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].Server,UseUnicode);
1783 sprintf(buffer,"Service%02i",num);
1784 ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].Service,UseUnicode);
1785 } else if ((mystrncasecmp(readvalue,"Data",0) || mystrncasecmp(readvalue,"GPRS",0))) {
1786 settings->Settings[settings->Number].Bearer = WAPSETTINGS_BEARER_DATA;
1787 if (mystrncasecmp(readvalue,"GPRS",0)) settings->Settings[settings->Number].Bearer = WAPSETTINGS_BEARER_GPRS;
1788 sprintf(buffer,"Number%02i",num);
1789 ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].DialUp,UseUnicode);
1790 sprintf(buffer,"IP%02i",num);
1791 ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].IPAddress,UseUnicode);
1792 sprintf(buffer,"User%02i",num);
1793 ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].User,UseUnicode);
1794 sprintf(buffer,"Password%02i",num);
1795 ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].Password,UseUnicode);
1796 sprintf(buffer,"Authentication%02i",num);
1797 settings->Settings[settings->Number].IsNormalAuthentication = true;
1798 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1799 if (readvalue!=NULL)
1801 if (mystrncasecmp(readvalue,"Secure",0)) settings->Settings[settings->Number].IsNormalAuthentication = false;
1803 sprintf(buffer,"CallSpeed%02i",num);
1804 settings->Settings[settings->Number].Speed = WAPSETTINGS_SPEED_14400;
1805 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1806 if (readvalue!=NULL)
1808 if (mystrncasecmp(readvalue,"9600",0)) settings->Settings[settings->Number].Speed = WAPSETTINGS_SPEED_9600;
1809 if (mystrncasecmp(readvalue,"auto",0)) settings->Settings[settings->Number].Speed = WAPSETTINGS_SPEED_AUTO;
1811 sprintf(buffer,"Login%02i",num);
1812 settings->Settings[settings->Number].ManualLogin = false;
1813 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1814 if (readvalue!=NULL)
1816 if (mystrncasecmp(readvalue,"Manual",0)) settings->Settings[settings->Number].ManualLogin = true;
1818 sprintf(buffer,"CallType%02i",num);
1819 settings->Settings[settings->Number].IsISDNCall = true;
1820 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1821 if (readvalue!=NULL)
1823 if (mystrncasecmp(readvalue,"Analogue",0)) settings->Settings[settings->Number].IsISDNCall = false;
1825 } else if (mystrncasecmp(readvalue,"USSD",0)) {
1826 settings->Settings[settings->Number].Bearer = WAPSETTINGS_BEARER_USSD;
1827 sprintf(buffer,"ServiceCode%02i",num);
1828 ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].Code,UseUnicode);
1829 sprintf(buffer,"IP%02i",num);
1830 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1831 if (readvalue!=NULL) {
1832 settings->Settings[settings->Number].IsIP = true;
1833 sprintf(buffer,"IP%02i",num);
1834 } else {
1835 settings->Settings[settings->Number].IsIP = false;
1836 sprintf(buffer,"Number%02i",num);
1838 ReadBackupText(file_info, section, buffer, settings->Settings[settings->Number].Service,UseUnicode);
1841 settings->Number++;
1846 static void ReadRingtoneEntry(INI_Section *file_info, char *section, GSM_Ringtone *ringtone, bool UseUnicode)
1848 unsigned char buffer[10000], buffer2[10000], *readvalue;
1850 sprintf(buffer,"Name");
1851 ReadBackupText(file_info, section, buffer, ringtone->Name,UseUnicode);
1852 ringtone->Location = 0;
1853 sprintf(buffer,"Location");
1854 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1855 if (readvalue!=NULL) ringtone->Location = atoi(readvalue);
1856 sprintf(buffer,"NokiaBinary00");
1857 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1858 if (readvalue!=NULL) {
1859 ringtone->Format = RING_NOKIABINARY;
1860 ReadLinkedBackupText(file_info, section, "NokiaBinary", buffer2, UseUnicode);
1861 DecodeHexBin (ringtone->NokiaBinary.Frame, buffer2, strlen(buffer2));
1862 ringtone->NokiaBinary.Length = strlen(buffer2)/2;
1864 sprintf(buffer,"Pure Midi00");
1865 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1866 if (readvalue!=NULL) {
1867 ringtone->Format = RING_MIDI;
1868 ReadLinkedBackupText(file_info, section, "Pure Midi", buffer2, UseUnicode);
1869 DecodeHexBin (ringtone->NokiaBinary.Frame, buffer2, strlen(buffer2));
1870 ringtone->NokiaBinary.Length = strlen(buffer2)/2;
1875 static void ReadProfileEntry(INI_Section *file_info, char *section, GSM_Profile *Profile, bool UseUnicode)
1877 unsigned char buffer[10000];
1878 char *readvalue;
1879 bool unknown;
1880 int num,j;
1881 INI_Entry *e;
1883 sprintf(buffer,"Name");
1884 ReadBackupText(file_info, section, buffer, Profile->Name,UseUnicode);
1886 sprintf(buffer,"Location");
1887 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1888 Profile->Location = atoi(readvalue);
1890 Profile->DefaultName = false;
1891 sprintf(buffer,"DefaultName");
1892 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1893 if (readvalue!=NULL && mystrncasecmp(buffer,"true",0)) Profile->DefaultName = true;
1895 Profile->HeadSetProfile = false;
1896 sprintf(buffer,"HeadSetProfile");
1897 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1898 if (readvalue!=NULL && mystrncasecmp(buffer,"true",0)) Profile->HeadSetProfile = true;
1900 Profile->CarKitProfile = false;
1901 sprintf(buffer,"CarKitProfile");
1902 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1903 if (readvalue!=NULL && mystrncasecmp(buffer,"true",0)) Profile->CarKitProfile = true;
1905 Profile->FeaturesNumber = 0;
1906 e = INI_FindLastSectionEntry(file_info, section, UseUnicode);
1907 while (1) {
1908 if (e == NULL) break;
1909 num = -1;
1910 if (UseUnicode) {
1911 sprintf(buffer,"%s",DecodeUnicodeString(e->EntryName));
1912 } else {
1913 sprintf(buffer,"%s",e->EntryName);
1915 if (strlen(buffer) == 9) {
1916 if (mystrncasecmp("Feature", buffer, 7)) num = atoi(buffer+7);
1918 e = e->Prev;
1919 if (num != -1) {
1920 sprintf(buffer,"Feature%02i",num);
1921 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1922 if (readvalue==NULL) break;
1923 unknown = true;
1924 if (mystrncasecmp(readvalue,"RingtoneID",0)) {
1925 Profile->FeatureID[Profile->FeaturesNumber]=Profile_RingtoneID;
1926 sprintf(buffer,"Value%02i",num);
1927 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1928 Profile->FeatureValue[Profile->FeaturesNumber]=atoi(readvalue);
1929 Profile->FeaturesNumber++;
1930 } else if (mystrncasecmp(readvalue,"MessageToneID",0)) {
1931 Profile->FeatureID[Profile->FeaturesNumber]=Profile_MessageToneID;
1932 sprintf(buffer,"Value%02i",num);
1933 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1934 Profile->FeatureValue[Profile->FeaturesNumber]=atoi(readvalue);
1935 Profile->FeaturesNumber++;
1936 } else if (mystrncasecmp(readvalue,"ScreenSaverNumber",0)) {
1937 Profile->FeatureID[Profile->FeaturesNumber]=Profile_ScreenSaverNumber;
1938 sprintf(buffer,"Value%02i",num);
1939 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1940 Profile->FeatureValue[Profile->FeaturesNumber]=atoi(readvalue);
1941 Profile->FeaturesNumber++;
1942 } else if (mystrncasecmp(readvalue,"CallerGroups",0)) {
1943 Profile->FeatureID[Profile->FeaturesNumber]=Profile_CallerGroups;
1944 sprintf(buffer,"Value%02i",num);
1945 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1946 for (j=0;j<5;j++) {
1947 Profile->CallerGroups[j]=false;
1948 if (strstr(readvalue,"1"+j)!=NULL) Profile->CallerGroups[j]=true;
1950 Profile->FeaturesNumber++;
1951 } else if (mystrncasecmp(readvalue,"IncomingCallAlert",0)) {
1952 Profile->FeatureID[Profile->FeaturesNumber]=Profile_CallAlert;
1953 unknown = false;
1954 } else if (mystrncasecmp(readvalue,"RingtoneVolume",0)) {
1955 Profile->FeatureID[Profile->FeaturesNumber]=Profile_RingtoneVolume;
1956 unknown = false;
1957 } else if (mystrncasecmp(readvalue,"Vibrating",0)) {
1958 Profile->FeatureID[Profile->FeaturesNumber]=Profile_Vibration;
1959 unknown = false;
1960 } else if (mystrncasecmp(readvalue,"MessageTone",0)) {
1961 Profile->FeatureID[Profile->FeaturesNumber]=Profile_MessageTone;
1962 unknown = false;
1963 } else if (mystrncasecmp(readvalue,"KeypadTones",0)) {
1964 Profile->FeatureID[Profile->FeaturesNumber]=Profile_KeypadTone;
1965 unknown = false;
1966 } else if (mystrncasecmp(readvalue,"WarningTones",0)) {
1967 Profile->FeatureID[Profile->FeaturesNumber]=Profile_WarningTone;
1968 unknown = false;
1969 } else if (mystrncasecmp(readvalue,"ScreenSaver",0)) {
1970 Profile->FeatureID[Profile->FeaturesNumber]=Profile_ScreenSaver;
1971 unknown = false;
1972 } else if (mystrncasecmp(readvalue,"ScreenSaverTimeout",0)) {
1973 Profile->FeatureID[Profile->FeaturesNumber]=Profile_ScreenSaverTime;
1974 unknown = false;
1975 } else if (mystrncasecmp(readvalue,"AutomaticAnswer",0)) {
1976 Profile->FeatureID[Profile->FeaturesNumber]=Profile_AutoAnswer;
1977 unknown = false;
1978 } else if (mystrncasecmp(readvalue,"Lights",0)) {
1979 Profile->FeatureID[Profile->FeaturesNumber]=Profile_Lights;
1980 unknown = false;
1982 if (!unknown) {
1983 sprintf(buffer,"Value%02i",num);
1984 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1985 if (mystrncasecmp(readvalue,"Level1",0)) {
1986 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_VOLUME_LEVEL1;
1987 if (Profile->FeatureID[Profile->FeaturesNumber]==Profile_KeypadTone) {
1988 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_KEYPAD_LEVEL1;
1990 } else if (mystrncasecmp(readvalue,"Level2",0)) {
1991 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_VOLUME_LEVEL2;
1992 if (Profile->FeatureID[Profile->FeaturesNumber]==Profile_KeypadTone) {
1993 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_KEYPAD_LEVEL2;
1995 } else if (mystrncasecmp(readvalue,"Level3",0)) {
1996 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_VOLUME_LEVEL3;
1997 if (Profile->FeatureID[Profile->FeaturesNumber]==Profile_KeypadTone) {
1998 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_KEYPAD_LEVEL3;
2000 } else if (mystrncasecmp(readvalue,"Level4",0)) {
2001 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_VOLUME_LEVEL4;
2002 } else if (mystrncasecmp(readvalue,"Level5",0)) {
2003 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_VOLUME_LEVEL5;
2004 } else if (mystrncasecmp(readvalue,"Off",0)) {
2005 switch (Profile->FeatureID[Profile->FeaturesNumber]) {
2006 case Profile_MessageTone:
2007 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_MESSAGE_NOTONE;
2008 break;
2009 case Profile_AutoAnswer:
2010 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_AUTOANSWER_OFF;
2011 break;
2012 case Profile_Lights:
2013 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_LIGHTS_OFF;
2014 break;
2015 case Profile_ScreenSaver:
2016 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_SAVER_OFF;
2017 break;
2018 case Profile_WarningTone:
2019 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_WARNING_OFF;
2020 break;
2021 case Profile_CallAlert:
2022 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_CALLALERT_OFF;
2023 break;
2024 case Profile_Vibration:
2025 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_VIBRATION_OFF;
2026 break;
2027 default:
2028 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_KEYPAD_OFF;
2029 break;
2031 } else if (mystrncasecmp(readvalue,"Ringing",0)) {
2032 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_CALLALERT_RINGING;
2033 } else if (mystrncasecmp(readvalue,"BeepOnce",0)) {
2034 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_CALLALERT_BEEPONCE;
2035 if (Profile->FeatureID[Profile->FeaturesNumber]==Profile_MessageTone) {
2036 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_MESSAGE_BEEPONCE;
2038 } else if (mystrncasecmp(readvalue,"RingOnce",0)) {
2039 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_CALLALERT_RINGONCE;
2040 } else if (mystrncasecmp(readvalue,"Ascending",0)) {
2041 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_CALLALERT_ASCENDING;
2042 } else if (mystrncasecmp(readvalue,"CallerGroups",0)) {
2043 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_CALLALERT_CALLERGROUPS;
2044 } else if (mystrncasecmp(readvalue,"Standard",0)) {
2045 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_MESSAGE_STANDARD;
2046 } else if (mystrncasecmp(readvalue,"Special",0)) {
2047 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_MESSAGE_SPECIAL;
2048 } else if (mystrncasecmp(readvalue,"Ascending",0)) {
2049 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_MESSAGE_ASCENDING;
2050 } else if (mystrncasecmp(readvalue,"Personal",0)) {
2051 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_MESSAGE_PERSONAL;
2052 } else if (mystrncasecmp(readvalue,"VibrateFirst",0)) {
2053 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_VIBRATION_FIRST;
2054 } else if (mystrncasecmp(readvalue,"Auto",0)) {
2055 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_LIGHTS_AUTO;
2056 } else if (mystrncasecmp(readvalue,"5Seconds",0)) {
2057 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_SAVER_TIMEOUT_5SEC;
2058 } else if (mystrncasecmp(readvalue,"20Seconds",0)) {
2059 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_SAVER_TIMEOUT_20SEC;
2060 } else if (mystrncasecmp(readvalue,"1Minute",0)) {
2061 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_SAVER_TIMEOUT_1MIN;
2062 } else if (mystrncasecmp(readvalue,"2Minutes",0)) {
2063 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_SAVER_TIMEOUT_2MIN;
2064 } else if (mystrncasecmp(readvalue,"5Minutes",0)) {
2065 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_SAVER_TIMEOUT_5MIN;
2066 } else if (mystrncasecmp(readvalue,"10Minutes",0)) {
2067 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_SAVER_TIMEOUT_10MIN;
2068 } else if (mystrncasecmp(readvalue,"On",0)) {
2069 switch (Profile->FeatureID[Profile->FeaturesNumber]) {
2070 case Profile_AutoAnswer:
2071 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_AUTOANSWER_ON;
2072 break;
2073 case Profile_WarningTone:
2074 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_WARNING_ON;
2075 break;
2076 case Profile_ScreenSaver:
2077 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_SAVER_ON;
2078 break;
2079 default:
2080 Profile->FeatureValue[Profile->FeaturesNumber]=PROFILE_VIBRATION_ON;
2081 break;
2083 } else unknown = true;
2085 if (!unknown) Profile->FeaturesNumber++;
2090 static void ReadFMStationEntry(INI_Section *file_info, char *section, GSM_FMStation *FMStation, bool UseUnicode)
2092 unsigned char buffer[10000], *readvalue;
2094 FMStation->Location = 0;
2095 FMStation->Frequency = 0;
2097 sprintf(buffer,"Location");
2098 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2099 if (readvalue!=NULL) FMStation->Location = atoi(readvalue);
2101 sprintf(buffer,"StationName");
2102 ReadBackupText(file_info, section, buffer, FMStation->StationName,UseUnicode);
2104 sprintf(buffer,"Frequency");
2105 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2106 if (readvalue!=NULL) StringToDouble(readvalue, &FMStation->Frequency);
2109 static void ReadGPRSPointEntry(INI_Section *file_info, char *section, GSM_GPRSAccessPoint *GPRSPoint, bool UseUnicode)
2111 unsigned char buffer[10000], *readvalue;
2113 GPRSPoint->Name[0] = 0;
2114 GPRSPoint->Name[1] = 0;
2115 GPRSPoint->URL[0] = 0;
2116 GPRSPoint->URL[1] = 0;
2117 GPRSPoint->Location = 0;
2119 GPRSPoint->Active = false;
2120 sprintf(buffer,"Active");
2121 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2122 if (readvalue!=NULL) {
2123 if (mystrncasecmp(readvalue,"Yes",0)) GPRSPoint->Active = true;
2126 sprintf(buffer,"Location");
2127 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
2128 if (readvalue!=NULL) GPRSPoint->Location = atoi(readvalue);
2130 sprintf(buffer,"Name");
2131 ReadBackupText(file_info, section, buffer, GPRSPoint->Name,UseUnicode);
2133 sprintf(buffer,"URL");
2134 ReadBackupText(file_info, section, buffer, GPRSPoint->URL,UseUnicode);
2137 static void ReadNoteEntry(INI_Section *file_info, char *section, GSM_NoteEntry *Note, bool UseUnicode)
2139 unsigned char buffer[100];
2141 sprintf(buffer,"Text");
2142 ReadBackupText(file_info, section, buffer, Note->Text,UseUnicode);
2145 GSM_Error LoadBackup(char *FileName, GSM_Backup *backup, bool UseUnicode)
2147 INI_Section *file_info, *h;
2148 char buffer[100], *readvalue;
2149 int num;
2150 GSM_MemoryEntry PBK;
2151 bool found;
2153 file_info = INI_ReadFile(FileName, UseUnicode);
2155 sprintf(buffer,"Backup");
2156 if (UseUnicode) EncodeUnicode(buffer,"Backup",6);
2158 readvalue = ReadCFGText(file_info, buffer, "Format", UseUnicode);
2159 /* Did we read anything? */
2160 if (readvalue == NULL) return GE_FILENOTSUPPORTED;
2161 /* Is this format version supported ? */
2162 if (strcmp(readvalue,"1.01")!=0 && strcmp(readvalue,"1.02")!=0 &&
2163 strcmp(readvalue,"1.03")!=0) return GE_FILENOTSUPPORTED;
2165 readvalue = ReadCFGText(file_info, buffer, "IMEI", UseUnicode);
2166 if (readvalue!=NULL) strcpy(backup->IMEI,readvalue);
2167 readvalue = ReadCFGText(file_info, buffer, "Phone", UseUnicode);
2168 if (readvalue!=NULL) strcpy(backup->Model,readvalue);
2169 readvalue = ReadCFGText(file_info, buffer, "DateTime", UseUnicode);
2170 if (readvalue!=NULL) {
2171 ReadVCALDateTime(readvalue, &backup->DateTime);
2172 backup->DateTimeAvailable = true;
2175 sprintf(buffer,"Checksum");
2176 if (UseUnicode) EncodeUnicode(buffer,"Checksum",8);
2177 readvalue = ReadCFGText(file_info, buffer, "MD5", UseUnicode);
2178 if (readvalue!=NULL) strcpy(backup->MD5Original,readvalue);
2180 num = 0;
2181 for (h = file_info; h != NULL; h = h->Next) {
2182 found = false;
2183 if (UseUnicode) {
2184 EncodeUnicode(buffer,"Profile",7);
2185 if (mywstrncasecmp(buffer, h->SectionName, 7)) found = true;
2186 } else {
2187 if (mystrncasecmp("Profile", h->SectionName, 7)) found = true;
2189 if (found) {
2190 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
2191 if (readvalue==NULL) break;
2192 if (num < GSM_BACKUP_MAX_PROFILES) {
2193 backup->Profiles[num] = malloc(sizeof(GSM_Profile));
2194 if (backup->Profiles[num] == NULL) return GE_MOREMEMORY;
2195 backup->Profiles[num + 1] = NULL;
2196 } else {
2197 dbgprintf("Increase GSM_BACKUP_MAX_PROFILES\n");
2198 return GE_MOREMEMORY;
2200 ReadProfileEntry(file_info, h->SectionName, backup->Profiles[num], UseUnicode);
2201 num++;
2204 num = 0;
2205 for (h = file_info; h != NULL; h = h->Next) {
2206 found = false;
2207 if (UseUnicode) {
2208 EncodeUnicode(buffer,"PhonePBK",8);
2209 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2210 } else {
2211 if (mystrncasecmp("PhonePBK", h->SectionName, 8)) found = true;
2213 if (found) {
2214 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
2215 if (readvalue==NULL) break;
2216 if (num < GSM_BACKUP_MAX_PHONEPHONEBOOK) {
2217 backup->PhonePhonebook[num] = malloc(sizeof(GSM_MemoryEntry));
2218 if (backup->PhonePhonebook[num] == NULL) return GE_MOREMEMORY;
2219 backup->PhonePhonebook[num + 1] = NULL;
2220 } else {
2221 dbgprintf("Increase GSM_BACKUP_MAX_PHONEPHONEBOOK\n");
2222 return GE_MOREMEMORY;
2224 backup->PhonePhonebook[num]->Location = atoi (readvalue);
2225 backup->PhonePhonebook[num]->MemoryType = GMT_ME;
2226 ReadPbkEntry(file_info, h->SectionName, backup->PhonePhonebook[num],UseUnicode);
2227 dbgprintf("number of entries = %i\n",backup->PhonePhonebook[num]->EntriesNum);
2228 num++;
2231 num = 0;
2232 while (0) {
2233 if (backup->PhonePhonebook[num] == NULL) break;
2234 if (backup->PhonePhonebook[num+1] != NULL) {
2235 if (backup->PhonePhonebook[num+1]->Location < backup->PhonePhonebook[num]->Location) {
2236 memcpy(&PBK,backup->PhonePhonebook[num+1],sizeof(GSM_MemoryEntry));
2237 memcpy(backup->PhonePhonebook[num+1],backup->PhonePhonebook[num],sizeof(GSM_MemoryEntry));
2238 memcpy(backup->PhonePhonebook[num],&PBK,sizeof(GSM_MemoryEntry));
2239 num = 0;
2240 continue;
2243 num++;
2245 num = 0;
2246 for (h = file_info; h != NULL; h = h->Next) {
2247 found = false;
2248 if (UseUnicode) {
2249 EncodeUnicode(buffer,"SIMPBK",6);
2250 if (mywstrncasecmp(buffer, h->SectionName, 6)) found = true;
2251 } else {
2252 if (mystrncasecmp("SIMPBK", h->SectionName, 6)) found = true;
2254 if (found) {
2255 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
2256 if (readvalue==NULL) break;
2257 if (num < GSM_BACKUP_MAX_SIMPHONEBOOK) {
2258 backup->SIMPhonebook[num] = malloc(sizeof(GSM_MemoryEntry));
2259 if (backup->SIMPhonebook[num] == NULL) return GE_MOREMEMORY;
2260 backup->SIMPhonebook[num + 1] = NULL;
2261 } else {
2262 dbgprintf("Increase GSM_BACKUP_MAX_SIMPHONEBOOK\n");
2263 return GE_MOREMEMORY;
2265 backup->SIMPhonebook[num]->Location = atoi (readvalue);
2266 backup->SIMPhonebook[num]->MemoryType = GMT_SM;
2267 ReadPbkEntry(file_info, h->SectionName, backup->SIMPhonebook[num],UseUnicode);
2268 num++;
2271 num = 0;
2272 while (0) {
2273 if (backup->SIMPhonebook[num] == NULL) break;
2274 if (backup->SIMPhonebook[num+1] != NULL) {
2275 if (backup->SIMPhonebook[num+1]->Location < backup->SIMPhonebook[num]->Location) {
2276 memcpy(&PBK,backup->SIMPhonebook[num+1],sizeof(GSM_MemoryEntry));
2277 memcpy(backup->SIMPhonebook[num+1],backup->SIMPhonebook[num],sizeof(GSM_MemoryEntry));
2278 memcpy(backup->SIMPhonebook[num],&PBK,sizeof(GSM_MemoryEntry));
2279 num = 0;
2280 continue;
2283 num++;
2285 num = 0;
2286 for (h = file_info; h != NULL; h = h->Next) {
2287 found = false;
2288 if (UseUnicode) {
2289 EncodeUnicode(buffer,"Calendar",8);
2290 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2291 } else {
2292 if (mystrncasecmp("Calendar", h->SectionName, 8)) found = true;
2294 if (found) {
2295 readvalue = ReadCFGText(file_info, h->SectionName, "Type", UseUnicode);
2296 if (readvalue==NULL) break;
2297 if (num < GSM_MAXCALENDARTODONOTES) {
2298 backup->Calendar[num] = malloc(sizeof(GSM_CalendarEntry));
2299 if (backup->Calendar[num] == NULL) return GE_MOREMEMORY;
2300 backup->Calendar[num + 1] = NULL;
2301 } else {
2302 dbgprintf("Increase GSM_MAXCALENDARTODONOTES\n");
2303 return GE_MOREMEMORY;
2305 backup->Calendar[num]->Location = num + 1;
2306 ReadCalendarEntry(file_info, h->SectionName, backup->Calendar[num],UseUnicode);
2307 num++;
2310 num = 0;
2311 for (h = file_info; h != NULL; h = h->Next) {
2312 found = false;
2313 if (UseUnicode) {
2314 EncodeUnicode(buffer,"Caller",6);
2315 if (mywstrncasecmp(buffer, h->SectionName, 6)) found = true;
2316 } else {
2317 if (mystrncasecmp("Caller", h->SectionName, 6)) found = true;
2319 if (found) {
2320 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
2321 if (readvalue==NULL) break;
2322 if (num < GSM_BACKUP_MAX_CALLER) {
2323 backup->CallerLogos[num] = malloc(sizeof(GSM_Bitmap));
2324 if (backup->CallerLogos[num] == NULL) return GE_MOREMEMORY;
2325 backup->CallerLogos[num + 1] = NULL;
2326 } else {
2327 dbgprintf("Increase GSM_BACKUP_MAX_CALLER\n");
2328 return GE_MOREMEMORY;
2330 backup->CallerLogos[num]->Location = atoi (readvalue);
2331 ReadCallerEntry(file_info, h->SectionName, backup->CallerLogos[num],UseUnicode);
2332 num++;
2335 num = 0;
2336 for (h = file_info; h != NULL; h = h->Next) {
2337 found = false;
2338 if (UseUnicode) {
2339 EncodeUnicode(buffer,"SMSC",4);
2340 if (mywstrncasecmp(buffer, h->SectionName, 4)) found = true;
2341 } else {
2342 if (mystrncasecmp("SMSC", h->SectionName, 4)) found = true;
2344 if (found) {
2345 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
2346 if (readvalue==NULL) break;
2347 if (num < GSM_BACKUP_MAX_SMSC) {
2348 backup->SMSC[num] = malloc(sizeof(GSM_SMSC));
2349 if (backup->SMSC[num] == NULL) return GE_MOREMEMORY;
2350 backup->SMSC[num + 1] = NULL;
2351 } else {
2352 dbgprintf("Increase GSM_BACKUP_MAX_SMSC\n");
2353 return GE_MOREMEMORY;
2355 backup->SMSC[num]->Location = atoi (readvalue);
2356 ReadSMSCEntry(file_info, h->SectionName, backup->SMSC[num],UseUnicode);
2357 num++;
2360 num = 0;
2361 for (h = file_info; h != NULL; h = h->Next) {
2362 found = false;
2363 if (UseUnicode) {
2364 EncodeUnicode(buffer,"WAPBookmark",11);
2365 if (mywstrncasecmp(buffer, h->SectionName, 11)) found = true;
2366 if (!found) {
2367 EncodeUnicode(buffer,"Bookmark",8);
2368 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2370 } else {
2371 if (mystrncasecmp("WAPBookmark", h->SectionName, 11)) found = true;
2372 if (!found) {
2373 if (mystrncasecmp("Bookmark", h->SectionName, 8)) found = true;
2376 if (found) {
2377 readvalue = ReadCFGText(file_info, h->SectionName, "URL", UseUnicode);
2378 if (readvalue==NULL) break;
2379 if (num < GSM_BACKUP_MAX_WAPBOOKMARK) {
2380 backup->WAPBookmark[num] = malloc(sizeof(GSM_WAPBookmark));
2381 if (backup->WAPBookmark[num] == NULL) return GE_MOREMEMORY;
2382 backup->WAPBookmark[num + 1] = NULL;
2383 } else {
2384 dbgprintf("Increase GSM_BACKUP_MAX_WAPBOOKMARK\n");
2385 return GE_MOREMEMORY;
2387 backup->WAPBookmark[num]->Location = num + 1;
2388 ReadWAPBookmarkEntry(file_info, h->SectionName, backup->WAPBookmark[num],UseUnicode);
2389 num++;
2392 num = 0;
2393 for (h = file_info; h != NULL; h = h->Next) {
2394 found = false;
2395 if (UseUnicode) {
2396 EncodeUnicode(buffer,"WAPSettings",11);
2397 if (mywstrncasecmp(buffer, h->SectionName, 11)) found = true;
2398 if (!found) {
2399 EncodeUnicode(buffer,"Settings",8);
2400 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2402 } else {
2403 if (mystrncasecmp("WAPSettings", h->SectionName, 11)) found = true;
2404 if (!found) {
2405 if (mystrncasecmp("Settings", h->SectionName, 8)) found = true;
2408 if (found) {
2409 readvalue = ReadCFGText(file_info, h->SectionName, "Title00", UseUnicode);
2410 if (readvalue==NULL) break;
2411 if (num < GSM_BACKUP_MAX_WAPSETTINGS) {
2412 backup->WAPSettings[num] = malloc(sizeof(GSM_MultiWAPSettings));
2413 if (backup->WAPSettings[num] == NULL) return GE_MOREMEMORY;
2414 backup->WAPSettings[num + 1] = NULL;
2415 } else {
2416 dbgprintf("Increase GSM_BACKUP_MAX_WAPSETTINGS\n");
2417 return GE_MOREMEMORY;
2419 backup->WAPSettings[num]->Location = num + 1;
2420 dbgprintf("reading wap settings\n");
2421 ReadWAPSettingsEntry(file_info, h->SectionName, backup->WAPSettings[num],UseUnicode);
2422 num++;
2425 num = 0;
2426 for (h = file_info; h != NULL; h = h->Next) {
2427 found = false;
2428 if (UseUnicode) {
2429 EncodeUnicode(buffer,"MMSSettings",8);
2430 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2431 } else {
2432 if (mystrncasecmp("MMSSettings", h->SectionName, 8)) found = true;
2434 if (found) {
2435 readvalue = ReadCFGText(file_info, h->SectionName, "Title00", UseUnicode);
2436 if (readvalue==NULL) break;
2437 if (num < GSM_BACKUP_MAX_MMSSETTINGS) {
2438 backup->MMSSettings[num] = malloc(sizeof(GSM_MultiWAPSettings));
2439 if (backup->MMSSettings[num] == NULL) return GE_MOREMEMORY;
2440 backup->MMSSettings[num + 1] = NULL;
2441 } else {
2442 dbgprintf("Increase GSM_BACKUP_MAX_MMSSETTINGS\n");
2443 return GE_MOREMEMORY;
2445 backup->MMSSettings[num]->Location = num + 1;
2446 dbgprintf("reading mms settings\n");
2447 ReadWAPSettingsEntry(file_info, h->SectionName, backup->MMSSettings[num],UseUnicode);
2448 num++;
2451 num = 0;
2452 for (h = file_info; h != NULL; h = h->Next) {
2453 found = false;
2454 if (UseUnicode) {
2455 EncodeUnicode(buffer,"Ringtone",8);
2456 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2457 } else {
2458 if (mystrncasecmp("Ringtone", h->SectionName, 8)) found = true;
2460 if (found) {
2461 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
2462 if (readvalue==NULL) break;
2463 if (num < GSM_BACKUP_MAX_RINGTONES) {
2464 backup->Ringtone[num] = malloc(sizeof(GSM_Ringtone));
2465 if (backup->Ringtone[num] == NULL) return GE_MOREMEMORY;
2466 backup->Ringtone[num + 1] = NULL;
2467 } else {
2468 dbgprintf("Increase GSM_BACKUP_MAX_RINGTONES\n");
2469 return GE_MOREMEMORY;
2471 ReadRingtoneEntry(file_info, h->SectionName, backup->Ringtone[num],UseUnicode);
2472 num++;
2475 num = 0;
2476 for (h = file_info; h != NULL; h = h->Next) {
2477 found = false;
2478 if (UseUnicode) {
2479 EncodeUnicode(buffer,"TODO",4);
2480 if (mywstrncasecmp(buffer, h->SectionName, 4)) found = true;
2481 } else {
2482 if (mystrncasecmp("TODO", h->SectionName, 4)) found = true;
2484 if (found) {
2485 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
2486 if (readvalue==NULL) break;
2487 if (num < GSM_MAXCALENDARTODONOTES) {
2488 backup->ToDo[num] = malloc(sizeof(GSM_ToDoEntry));
2489 if (backup->ToDo[num] == NULL) return GE_MOREMEMORY;
2490 backup->ToDo[num + 1] = NULL;
2491 } else {
2492 dbgprintf("Increase GSM_MAXCALENDARTODONOTES\n");
2493 return GE_MOREMEMORY;
2495 backup->ToDo[num]->Location = num + 1;
2496 ReadToDoEntry(file_info, h->SectionName, backup->ToDo[num],UseUnicode);
2497 num++;
2500 sprintf(buffer,"Startup");
2501 readvalue = ReadCFGText(file_info, buffer, "Text", UseUnicode);
2502 if (readvalue==NULL) {
2503 readvalue = ReadCFGText(file_info, buffer, "Width", UseUnicode);
2505 if (readvalue!=NULL) {
2506 backup->StartupLogo = malloc(sizeof(GSM_Bitmap));
2507 if (backup->StartupLogo == NULL) return GE_MOREMEMORY;
2508 ReadStartupEntry(file_info, buffer, backup->StartupLogo,UseUnicode);
2510 sprintf(buffer,"Operator");
2511 readvalue = ReadCFGText(file_info, buffer, "Network", UseUnicode);
2512 if (readvalue!=NULL) {
2513 backup->OperatorLogo = malloc(sizeof(GSM_Bitmap));
2514 if (backup->OperatorLogo == NULL) return GE_MOREMEMORY;
2515 ReadOperatorEntry(file_info, buffer, backup->OperatorLogo,UseUnicode);
2517 num = 0;
2518 for (h = file_info; h != NULL; h = h->Next) {
2519 found = false;
2520 if (UseUnicode) {
2521 EncodeUnicode(buffer,"FMStation",9);
2522 if (mywstrncasecmp(buffer, h->SectionName, 9)) found = true;
2523 } else {
2524 if (mystrncasecmp("FMStation", h->SectionName, 9)) found = true;
2526 if (found) {
2527 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
2528 if (readvalue==NULL) break;
2529 if (num < GSM_BACKUP_MAX_FMSTATIONS) {
2530 backup->FMStation[num] = malloc(sizeof(GSM_FMStation));
2531 if (backup->FMStation[num] == NULL) return GE_MOREMEMORY;
2532 backup->FMStation[num + 1] = NULL;
2533 } else {
2534 dbgprintf("Increase GSM_BACKUP_MAX_FMSTATIONS\n");
2535 return GE_MOREMEMORY;
2537 backup->FMStation[num]->Location = num + 1;
2538 ReadFMStationEntry(file_info, h->SectionName, backup->FMStation[num],UseUnicode);
2539 num++;
2542 num = 0;
2543 for (h = file_info; h != NULL; h = h->Next) {
2544 found = false;
2545 if (UseUnicode) {
2546 EncodeUnicode(buffer,"GPRSPoint",9);
2547 if (mywstrncasecmp(buffer, h->SectionName, 9)) found = true;
2548 } else {
2549 if (mystrncasecmp("GPRSPoint", h->SectionName, 9)) found = true;
2551 if (found) {
2552 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
2553 if (readvalue==NULL) break;
2554 if (num < GSM_BACKUP_MAX_GPRSPOINT) {
2555 backup->GPRSPoint[num] = malloc(sizeof(GSM_GPRSAccessPoint));
2556 if (backup->GPRSPoint[num] == NULL) return GE_MOREMEMORY;
2557 backup->GPRSPoint[num + 1] = NULL;
2558 } else {
2559 dbgprintf("Increase GSM_BACKUP_MAX_GPRSPOINT\n");
2560 return GE_MOREMEMORY;
2562 backup->GPRSPoint[num]->Location = num + 1;
2563 ReadGPRSPointEntry(file_info, h->SectionName, backup->GPRSPoint[num],UseUnicode);
2564 num++;
2567 num = 0;
2568 for (h = file_info; h != NULL; h = h->Next) {
2569 found = false;
2570 if (UseUnicode) {
2571 EncodeUnicode(buffer,"Note",4);
2572 if (mywstrncasecmp(buffer, h->SectionName, 4)) found = true;
2573 } else {
2574 if (mystrncasecmp("Note", h->SectionName, 4)) found = true;
2576 if (found) {
2577 readvalue = ReadCFGText(file_info, h->SectionName, "Text", UseUnicode);
2578 if (readvalue==NULL) break;
2579 if (num < GSM_BACKUP_MAX_NOTE) {
2580 backup->Note[num] = malloc(sizeof(GSM_NoteEntry));
2581 if (backup->Note[num] == NULL) return GE_MOREMEMORY;
2582 backup->Note[num + 1] = NULL;
2583 } else {
2584 dbgprintf("Increase GSM_BACKUP_MAX_NOTE\n");
2585 return GE_MOREMEMORY;
2587 ReadNoteEntry(file_info, h->SectionName, backup->Note[num],UseUnicode);
2588 num++;
2591 if (backup->MD5Original[0]!=0) {
2592 FindBackupChecksum(FileName, UseUnicode, backup->MD5Calculated);
2595 return GE_NONE;
2598 /* ---------------------- backup files for SMS ----------------------------- */
2600 static void ReadSMSBackupEntry(INI_Section *file_info, char *section, GSM_SMSMessage *SMS)
2602 unsigned char buffer[10000], *readvalue;
2604 GSM_SetDefaultSMSData(SMS);
2606 SMS->PDU = SMS_Submit;
2607 SMS->SMSC.Location = 0;
2608 sprintf(buffer,"SMSC");
2609 ReadBackupText(file_info, section, buffer, SMS->SMSC.Number, false);
2610 sprintf(buffer,"ReplySMSC");
2611 SMS->ReplyViaSameSMSC = false;
2612 readvalue = ReadCFGText(file_info, section, buffer, false);
2613 if (readvalue!=NULL) {
2614 if (mystrncasecmp(readvalue,"True",0)) SMS->ReplyViaSameSMSC = true;
2616 sprintf(buffer,"Class");
2617 SMS->Class = -1;
2618 readvalue = ReadCFGText(file_info, section, buffer, false);
2619 if (readvalue!=NULL) SMS->Class = atoi(readvalue);
2620 sprintf(buffer,"Sent");
2621 readvalue = ReadCFGText(file_info, section, buffer, false);
2622 if (readvalue!=NULL) {
2623 ReadVCALDateTime(readvalue, &SMS->DateTime);
2624 SMS->PDU = SMS_Deliver;
2626 sprintf(buffer,"RejectDuplicates");
2627 SMS->RejectDuplicates = false;
2628 readvalue = ReadCFGText(file_info, section, buffer, false);
2629 if (readvalue!=NULL) {
2630 if (mystrncasecmp(readvalue,"True",0)) SMS->RejectDuplicates = true;
2632 sprintf(buffer,"ReplaceMessage");
2633 SMS->ReplaceMessage = 0;
2634 readvalue = ReadCFGText(file_info, section, buffer, false);
2635 if (readvalue!=NULL) SMS->ReplaceMessage = atoi(readvalue);
2636 sprintf(buffer,"MessageReference");
2637 SMS->MessageReference = 0;
2638 readvalue = ReadCFGText(file_info, section, buffer, false);
2639 if (readvalue!=NULL) SMS->MessageReference = atoi(readvalue);
2640 sprintf(buffer,"State");
2641 SMS->State = GSM_UnRead;
2642 readvalue = ReadCFGText(file_info, section, buffer, false);
2643 if (readvalue!=NULL) {
2644 if (mystrncasecmp(readvalue,"Read",0)) SMS->State = GSM_Read;
2645 else if (mystrncasecmp(readvalue,"Sent",0)) SMS->State = GSM_Sent;
2646 else if (mystrncasecmp(readvalue,"UnSent",0)) SMS->State = GSM_UnSent;
2648 sprintf(buffer,"Number");
2649 ReadBackupText(file_info, section, buffer, SMS->Number, false);
2650 sprintf(buffer,"Name");
2651 ReadBackupText(file_info, section, buffer, SMS->Name, false);
2652 sprintf(buffer,"Length");
2653 SMS->Length = 0;
2654 readvalue = ReadCFGText(file_info, section, buffer, false);
2655 if (readvalue!=NULL) SMS->Length = atoi(readvalue);
2656 sprintf(buffer,"Coding");
2657 SMS->Coding = GSM_Coding_Default;
2658 readvalue = ReadCFGText(file_info, section, buffer, false);
2659 if (readvalue!=NULL) {
2660 if (mystrncasecmp(readvalue,"Unicode",0)) {
2661 SMS->Coding = GSM_Coding_Unicode;
2662 } else if (mystrncasecmp(readvalue,"8bit",0)) {
2663 SMS->Coding = GSM_Coding_8bit;
2666 ReadLinkedBackupText(file_info, section, "Text", buffer, false);
2667 DecodeHexBin (SMS->Text, buffer, strlen(buffer));
2668 SMS->Text[strlen(buffer)/2] = 0;
2669 SMS->Text[strlen(buffer)/2+1] = 0;
2670 sprintf(buffer,"Folder");
2671 readvalue = ReadCFGText(file_info, section, buffer, false);
2672 if (readvalue!=NULL) SMS->Folder = atoi(readvalue);
2673 SMS->UDH.Type = UDH_NoUDH;
2674 SMS->UDH.Length = 0;
2675 SMS->UDH.ID8bit = -1;
2676 SMS->UDH.ID16bit = -1;
2677 SMS->UDH.PartNumber = -1;
2678 SMS->UDH.AllParts = -1;
2679 sprintf(buffer,"UDH");
2680 readvalue = ReadCFGText(file_info, section, buffer, false);
2681 if (readvalue!=NULL) {
2682 DecodeHexBin (SMS->UDH.Text, readvalue, strlen(readvalue));
2683 SMS->UDH.Length = strlen(readvalue)/2;
2684 GSM_DecodeUDHHeader(&SMS->UDH);
2688 static GSM_Error GSM_ReadSMSBackupTextFile(char *FileName, GSM_SMS_Backup *backup)
2690 INI_Section *file_info, *h;
2691 char *readvalue;
2692 int num;
2694 backup->SMS[0] = NULL;
2696 file_info = INI_ReadFile(FileName, false);
2698 num = 0;
2699 for (h = file_info; h != NULL; h = h->Next) {
2700 if (mystrncasecmp("SMSBackup", h->SectionName, 9)) {
2701 readvalue = ReadCFGText(file_info, h->SectionName, "Number", false);
2702 if (readvalue==NULL) break;
2703 if (num < GSM_BACKUP_MAX_SMS) {
2704 backup->SMS[num] = malloc(sizeof(GSM_SMSMessage));
2705 if (backup->SMS[num] == NULL) return GE_MOREMEMORY;
2706 backup->SMS[num + 1] = NULL;
2707 } else {
2708 dbgprintf("Increase GSM_BACKUP_MAX_SMS\n");
2709 return GE_MOREMEMORY;
2711 backup->SMS[num]->Location = num + 1;
2712 ReadSMSBackupEntry(file_info, h->SectionName, backup->SMS[num]);
2713 num++;
2716 return GE_NONE;
2719 GSM_Error GSM_ReadSMSBackupFile(char *FileName, GSM_SMS_Backup *backup)
2721 FILE *file;
2723 backup->SMS[0] = NULL;
2725 file = fopen(FileName, "rb");
2726 if (file == NULL) return(GE_CANTOPENFILE);
2728 fclose(file);
2730 return GSM_ReadSMSBackupTextFile(FileName, backup);
2733 GSM_Error SaveSMSBackupTextFile(FILE *file, GSM_SMS_Backup *backup)
2735 int i,w,current;
2736 unsigned char buffer[10000];
2737 GSM_DateTime DT;
2739 fprintf(file,"\n# File created by Gammu (www.mwiacek.com) version %s\n",VERSION);
2740 GSM_GetCurrentDateTime (&DT);
2741 fprintf(file,"# Saved %s\n\n",OSDateTime(DT,false));
2743 i=0;
2744 while (backup->SMS[i]!=NULL) {
2745 fprintf(file,"[SMSBackup%03i]\n",i);
2746 switch (backup->SMS[i]->Coding) {
2747 case GSM_Coding_Unicode:
2748 case GSM_Coding_Default:
2749 sprintf(buffer,"%s",DecodeUnicodeString(backup->SMS[i]->Text));
2750 fprintf(file,"#");
2751 current = 0;
2752 for (w=0;w<(int)(strlen(buffer));w++) {
2753 switch (buffer[w]) {
2754 case 10:
2755 fprintf(file,"\n#");
2756 current = 0;
2757 break;
2758 case 13:
2759 break;
2760 default:
2761 if (isprint(buffer[w])) {
2762 fprintf(file,"%c",buffer[w]);
2763 current ++;
2765 if (current == 75) {
2766 fprintf(file,"\n#");
2767 current = 0;
2771 fprintf(file,"\n");
2772 break;
2773 default:
2774 break;
2776 if (backup->SMS[i]->PDU == SMS_Deliver) {
2777 SaveBackupText(file, "SMSC", backup->SMS[i]->SMSC.Number, false);
2778 if (backup->SMS[i]->ReplyViaSameSMSC) fprintf(file,"SMSCReply = true\n");
2779 fprintf(file,"Sent");
2780 SaveVCalDateTime(file,&backup->SMS[i]->DateTime, false);
2782 fprintf(file,"State = ");
2783 switch (backup->SMS[i]->State) {
2784 case GSM_UnRead : fprintf(file,"UnRead\n"); break;
2785 case GSM_Read : fprintf(file,"Read\n"); break;
2786 case GSM_Sent : fprintf(file,"Sent\n"); break;
2787 case GSM_UnSent : fprintf(file,"UnSent\n"); break;
2789 SaveBackupText(file, "Number", backup->SMS[i]->Number, false);
2790 SaveBackupText(file, "Name", backup->SMS[i]->Name, false);
2791 if (backup->SMS[i]->UDH.Type != UDH_NoUDH) {
2792 EncodeHexBin(buffer,backup->SMS[i]->UDH.Text,backup->SMS[i]->UDH.Length);
2793 fprintf(file,"UDH = %s\n",buffer);
2795 switch (backup->SMS[i]->Coding) {
2796 case GSM_Coding_Unicode:
2797 case GSM_Coding_Default:
2798 EncodeHexBin(buffer,backup->SMS[i]->Text,backup->SMS[i]->Length*2);
2799 break;
2800 default:
2801 EncodeHexBin(buffer,backup->SMS[i]->Text,backup->SMS[i]->Length);
2802 break;
2804 SaveLinkedBackupText(file, "Text", buffer, false);
2805 switch (backup->SMS[i]->Coding) {
2806 case GSM_Coding_Unicode : fprintf(file,"Coding = Unicode\n"); break;
2807 case GSM_Coding_Default : fprintf(file,"Coding = Default\n"); break;
2808 case GSM_Coding_8bit : fprintf(file,"Coding = 8bit\n"); break;
2810 fprintf(file,"Folder = %i\n",backup->SMS[i]->Folder);
2811 fprintf(file,"Length = %i\n",backup->SMS[i]->Length);
2812 fprintf(file,"Class = %i\n",backup->SMS[i]->Class);
2813 fprintf(file,"ReplySMSC = ");
2814 if (backup->SMS[i]->ReplyViaSameSMSC) fprintf(file,"True\n"); else fprintf(file,"False\n");
2815 fprintf(file,"RejectDuplicates = ");
2816 if (backup->SMS[i]->RejectDuplicates) fprintf(file,"True\n"); else fprintf(file,"False\n");
2817 fprintf(file,"ReplaceMessage = %i\n",backup->SMS[i]->ReplaceMessage);
2818 fprintf(file,"MessageReference = %i\n",backup->SMS[i]->MessageReference);
2819 fprintf(file,"\n");
2820 i++;
2822 return GE_NONE;
2825 GSM_Error GSM_SaveSMSBackupFile(char *FileName, GSM_SMS_Backup *backup)
2827 FILE *file;
2829 file = fopen(FileName, "wb");
2830 if (file == NULL) return(GE_CANTOPENFILE);
2832 SaveSMSBackupTextFile(file,backup);
2834 fclose(file);
2836 return GE_NONE;
2839 #endif
2841 /* How should editor hadle tabs in this file? Add editor commands here.
2842 * vim: noexpandtab sw=8 ts=8 sts=8: