Diffstat (limited to 'gammu/emb/common/service/backup/backvcs.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | gammu/emb/common/service/backup/backvcs.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/gammu/emb/common/service/backup/backvcs.c b/gammu/emb/common/service/backup/backvcs.c new file mode 100644 index 0000000..332e718 --- a/dev/null +++ b/gammu/emb/common/service/backup/backvcs.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /* (c) 2003 by Marcin Wiacek */ | ||
2 | |||
3 | #include <string.h> | ||
4 | #include <ctype.h> | ||
5 | |||
6 | #include "../../phone/nokia/nfunc.h" | ||
7 | #include "../../phone/nokia/dct3/n7110.h" | ||
8 | #include "../../misc/coding/coding.h" | ||
9 | #include "../gsmlogo.h" | ||
10 | #include "../gsmmisc.h" | ||
11 | #include "backvcs.h" | ||
12 | |||
13 | #ifdef GSM_ENABLE_BACKUP | ||
14 | |||
15 | GSM_Error SaveVCalendar(char *FileName, GSM_Backup *backup) | ||
16 | { | ||
17 | int i, Length = 0; | ||
18 | unsigned char Buffer[1000]; | ||
19 | FILE *file; | ||
20 | |||
21 | file = fopen(FileName, "wb"); | ||
22 | if (file == NULL) return ERR_CANTOPENFILE; | ||
23 | |||
24 | Length=sprintf(Buffer, "BEGIN:VCALENDAR%c%c",13,10); | ||
25 | Length+=sprintf(Buffer+Length, "VERSION:1.0%c%c",13,10); | ||
26 | fwrite(Buffer,1,Length,file); | ||
27 | |||
28 | i=0; | ||
29 | while (backup->Calendar[i]!=NULL) { | ||
30 | sprintf(Buffer, "%c%c",13,10); | ||
31 | fwrite(Buffer,1,2,file); | ||
32 | Length = 0; | ||
33 | GSM_EncodeVCALENDAR(Buffer,&Length,backup->Calendar[i],false,Nokia_VCalendar); | ||
34 | fwrite(Buffer,1,Length,file); | ||
35 | i++; | ||
36 | } | ||
37 | i=0; | ||
38 | while (backup->ToDo[i]!=NULL) { | ||
39 | sprintf(Buffer, "%c%c",13,10); | ||
40 | fwrite(Buffer,1,2,file); | ||
41 | Length = 0; | ||
42 | GSM_EncodeVTODO(Buffer,&Length,backup->ToDo[i],false,Nokia_VToDo); | ||
43 | fwrite(Buffer,1,Length,file); | ||
44 | i++; | ||
45 | } | ||
46 | |||
47 | Length=sprintf(Buffer, "%c%cEND:VCALENDAR%c%c",13,10,13,10); | ||
48 | fwrite(Buffer,1,Length,file); | ||
49 | |||
50 | fclose(file); | ||
51 | return ERR_NONE; | ||
52 | } | ||
53 | |||
54 | GSM_Error LoadVCalendar(char *FileName, GSM_Backup *backup) | ||
55 | { | ||
56 | GSM_File File; | ||
57 | GSM_Error error; | ||
58 | GSM_CalendarEntryCalendar; | ||
59 | GSM_ToDoEntry ToDo; | ||
60 | int numCal = 0, numToDo = 0, Pos; | ||
61 | |||
62 | File.Buffer = NULL; | ||
63 | error = GSM_ReadFile(FileName, &File); | ||
64 | if (error != ERR_NONE) return error; | ||
65 | |||
66 | Pos = 0; | ||
67 | while (1) { | ||
68 | error = GSM_DecodeVCALENDAR_VTODO(File.Buffer, &Pos, &Calendar, &ToDo, Nokia_VCalendar, Nokia_VToDo); | ||
69 | if (error == ERR_EMPTY) break; | ||
70 | if (error != ERR_NONE) return error; | ||
71 | if (Calendar.EntriesNum != 0) { | ||
72 | if (numCal < GSM_MAXCALENDARTODONOTES) { | ||
73 | backup->Calendar[numCal] = malloc(sizeof(GSM_CalendarEntry)); | ||
74 | if (backup->Calendar[numCal] == NULL) return ERR_MOREMEMORY; | ||
75 | backup->Calendar[numCal + 1] = NULL; | ||
76 | } else { | ||
77 | dbgprintf("Increase GSM_MAXCALENDARTODONOTES\n"); | ||
78 | return ERR_MOREMEMORY; | ||
79 | } | ||
80 | memcpy(backup->Calendar[numCal],&Calendar,sizeof(GSM_CalendarEntry)); | ||
81 | backup->Calendar[numCal]->Location = numCal + 1; | ||
82 | numCal++; | ||
83 | } | ||
84 | if (ToDo.EntriesNum != 0) { | ||
85 | if (numToDo < GSM_MAXCALENDARTODONOTES) { | ||
86 | backup->ToDo[numToDo] = malloc(sizeof(GSM_ToDoEntry)); | ||
87 | if (backup->ToDo[numToDo] == NULL) return ERR_MOREMEMORY; | ||
88 | backup->ToDo[numToDo + 1] = NULL; | ||
89 | } else { | ||
90 | dbgprintf("Increase GSM_MAXCALENDARTODONOTES\n"); | ||
91 | return ERR_MOREMEMORY; | ||
92 | } | ||
93 | memcpy(backup->ToDo[numToDo],&ToDo,sizeof(GSM_ToDoEntry)); | ||
94 | backup->ToDo[numToDo]->Location = numToDo + 1; | ||
95 | numToDo++; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | return ERR_NONE; | ||
100 | } | ||
101 | |||
102 | #endif | ||
103 | |||
104 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
105 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
106 | */ | ||