Gammu internals  1.38.0
gsmback.c
Go to the documentation of this file.
1 /* (c) 2002-2004 by Marcin Wiacek & Michal Cihar */
2 
3 #define _GNU_SOURCE
4 #include <string.h>
5 #include <ctype.h>
6 
7 #include "../../phone/nokia/nfunc.h"
8 #include "../../phone/nokia/dct3/n7110.h"
9 #include "../../misc/coding/coding.h"
10 #include "../gsmlogo.h"
11 #include "../gsmmisc.h"
12 #include "../gsmcal.h"
13 #include "gsmback.h"
14 #include "backtext.h"
15 #include "backldif.h"
16 #include "backlmb.h"
17 #include "backvcs.h"
18 #include "backvcf.h"
19 #include "backics.h"
20 #include "backvnt.h"
21 
22 #include "../../../helper/string.h"
23 
24 #ifdef GSM_ENABLE_BACKUP
25 
26 void GSM_FreeBackup(GSM_Backup *backup)
27 {
28  int i;
29 
30  i=0;
31  while (backup->PhonePhonebook[i]!=NULL) {
32  GSM_FreeMemoryEntry(backup->PhonePhonebook[i]);
33  free(backup->PhonePhonebook[i]);
34  backup->PhonePhonebook[i] = NULL;
35  i++;
36  }
37  i=0;
38  while (backup->SIMPhonebook[i]!=NULL) {
39  free(backup->SIMPhonebook[i]);
40  backup->SIMPhonebook[i] = NULL;
41  i++;
42  }
43  i=0;
44  while (backup->Calendar[i]!=NULL) {
45  free(backup->Calendar[i]);
46  backup->Calendar[i] = NULL;
47  i++;
48  }
49  i=0;
50  while (backup->CallerLogos[i]!=NULL) {
51  free(backup->CallerLogos[i]);
52  backup->CallerLogos[i] = NULL;
53  i++;
54  }
55  i=0;
56  while (backup->SMSC[i]!=NULL) {
57  free(backup->SMSC[i]);
58  backup->SMSC[i] = NULL;
59  i++;
60  }
61  i=0;
62  while (backup->WAPBookmark[i]!=NULL) {
63  free(backup->WAPBookmark[i]);
64  backup->WAPBookmark[i] = NULL;
65  i++;
66  }
67  i=0;
68  while (backup->WAPSettings[i]!=NULL) {
69  free(backup->WAPSettings[i]);
70  backup->WAPSettings[i] = NULL;
71  i++;
72  }
73  i=0;
74  while (backup->MMSSettings[i]!=NULL) {
75  free(backup->MMSSettings[i]);
76  backup->MMSSettings[i] = NULL;
77  i++;
78  }
79  i=0;
80  while (backup->SyncMLSettings[i]!=NULL) {
81  free(backup->SyncMLSettings[i]);
82  backup->SyncMLSettings[i] = NULL;
83  i++;
84  }
85  i=0;
86  while (backup->ChatSettings[i]!=NULL) {
87  free(backup->ChatSettings[i]);
88  backup->ChatSettings[i] = NULL;
89  i++;
90  }
91  i=0;
92  while (backup->Ringtone[i]!=NULL) {
93  free(backup->Ringtone[i]);
94  backup->Ringtone[i] = NULL;
95  i++;
96  }
97  i=0;
98  while (backup->ToDo[i]!=NULL) {
99  free(backup->ToDo[i]);
100  backup->ToDo[i] = NULL;
101  i++;
102  }
103  i=0;
104  while (backup->Profiles[i]!=NULL) {
105  free(backup->Profiles[i]);
106  backup->Profiles[i] = NULL;
107  i++;
108  }
109  i=0;
110  while (backup->FMStation[i]!=NULL) {
111  free(backup->FMStation[i]);
112  backup->FMStation[i] = NULL;
113  i++;
114  }
115  if (backup->StartupLogo!=NULL) {
116  free(backup->StartupLogo);
117  backup->StartupLogo = NULL;
118  }
119  if (backup->OperatorLogo!=NULL) {
120  free(backup->OperatorLogo);
121  backup->OperatorLogo = NULL;
122  }
123  i=0;
124  while (backup->GPRSPoint[i]!=NULL) {
125  free(backup->GPRSPoint[i]);
126  backup->GPRSPoint[i] = NULL;
127  i++;
128  }
129  i=0;
130  while (backup->Note[i]!=NULL) {
131  free(backup->Note[i]);
132  backup->Note[i] = NULL;
133  i++;
134  }
135 }
136 
137 GSM_BackupFormat GSM_GuessBackupFormat(const char *FileName, const gboolean UseUnicode) {
138  GSM_BackupFormat Format = -1;
139 
140  if (strcasestr(FileName,".lmb")) {
141  Format = GSM_Backup_LMB;
142  } else if (strcasestr(FileName,".vcs")) {
143  Format = GSM_Backup_VCalendar;
144  } else if (strcasestr(FileName,".vnt")) {
145  Format = GSM_Backup_VNote;
146  } else if (strcasestr(FileName,".vcf")) {
147  Format = GSM_Backup_VCard;
148  } else if (strcasestr(FileName,".ldif")) {
149  Format = GSM_Backup_LDIF;
150  } else if (strcasestr(FileName,".ics")) {
151  Format = GSM_Backup_ICS;
152  } else {
153  if (UseUnicode) {
154  Format = GSM_Backup_GammuUCS2;
155  } else {
156  Format = GSM_Backup_Gammu;
157  }
158  }
159  return Format;
160 }
161 
162 GSM_Error GSM_SaveBackupFile(char *FileName, GSM_Backup *backup, GSM_BackupFormat Format)
163 {
164  if (Format == GSM_Backup_Auto || Format == GSM_Backup_AutoUnicode) {
165  Format = GSM_GuessBackupFormat(FileName, Format == GSM_Backup_AutoUnicode);
166  }
167 
168  switch (Format) {
169  case GSM_Backup_LMB:
170  return SaveLMB(FileName,backup);
171  case GSM_Backup_VCalendar:
172  return SaveVCalendar(FileName,backup);
173  case GSM_Backup_VCard:
174  return SaveVCard(FileName,backup);
175  case GSM_Backup_LDIF:
176  return SaveLDIF(FileName,backup);
177  case GSM_Backup_ICS:
178  return SaveICS(FileName,backup);
179  case GSM_Backup_Gammu:
180  return SaveBackup(FileName,backup, FALSE);
181  case GSM_Backup_GammuUCS2:
182  return SaveBackup(FileName,backup, TRUE);
183  case GSM_Backup_VNote:
184  return SaveVNT(FileName,backup);
185  default:
186  return ERR_FILENOTSUPPORTED;
187  }
188 }
189 
190 GSM_Error GSM_ReadBackupFile(const char *FileName, GSM_Backup *backup, GSM_BackupFormat Format)
191 {
192  GSM_ClearBackup(backup);
193 
194  if (Format == GSM_Backup_Auto || Format == GSM_Backup_AutoUnicode) {
195  Format = GSM_GuessBackupFormat(FileName, Format == GSM_Backup_AutoUnicode);
196  }
197 
198  switch (Format) {
199  case GSM_Backup_LMB:
200  return LoadLMB(FileName,backup);
201  case GSM_Backup_VCalendar:
202  return LoadVCalendar(FileName,backup);
203  case GSM_Backup_VCard:
204  return LoadVCard(FileName,backup);
205  case GSM_Backup_VNote:
206  return LoadVNT(FileName,backup);
207  case GSM_Backup_LDIF:
208  return LoadLDIF(FileName,backup);
209  case GSM_Backup_ICS:
210  return LoadICS(FileName,backup);
211  case GSM_Backup_Gammu:
212  return LoadBackup(FileName,backup);
213  case GSM_Backup_GammuUCS2:
214  return LoadBackup(FileName,backup);
215  default:
216  return ERR_FILENOTSUPPORTED;
217  }
218 }
219 
220 void GSM_ClearBackup(GSM_Backup *backup)
221 {
222  backup->PhonePhonebook [0] = NULL;
223  backup->SIMPhonebook [0] = NULL;
224  backup->Calendar [0] = NULL;
225  backup->CallerLogos [0] = NULL;
226  backup->SMSC [0] = NULL;
227  backup->WAPBookmark [0] = NULL;
228  backup->WAPSettings [0] = NULL;
229  backup->MMSSettings [0] = NULL;
230  backup->SyncMLSettings [0] = NULL;
231  backup->ChatSettings [0] = NULL;
232  backup->Ringtone [0] = NULL;
233  backup->Profiles [0] = NULL;
234  backup->ToDo [0] = NULL;
235  backup->GPRSPoint [0] = NULL;
236  backup->FMStation [0] = NULL;
237  backup->Note [0] = NULL;
238  backup->StartupLogo = NULL;
239  backup->OperatorLogo = NULL;
240 
241  backup->Creator [0] = 0;
242  backup->IMEI [0] = 0;
243  backup->Model [0] = 0;
244  backup->DateTimeAvailable = FALSE;
245  backup->MD5Original [0] = 0;
246  backup->MD5Calculated [0] = 0;
247 }
248 
249 void GSM_GetBackupFormatFeatures(GSM_BackupFormat Format, GSM_Backup_Info *info)
250 {
251  info->UseUnicode = FALSE;
252  info->IMEI = FALSE;
253  info->Model = FALSE;
254  info->DateTime = FALSE;
255  info->PhonePhonebook = FALSE;
256  info->SIMPhonebook = FALSE;
257  info->ToDo = FALSE;
258  info->Calendar = FALSE;
259  info->CallerLogos = FALSE;
260  info->SMSC = FALSE;
261  info->WAPBookmark = FALSE;
262  info->WAPSettings = FALSE;
263  info->MMSSettings = FALSE;
264  info->SyncMLSettings = FALSE;
265  info->ChatSettings = FALSE;
266  info->Ringtone = FALSE;
267  info->StartupLogo = FALSE;
268  info->OperatorLogo = FALSE;
269  info->Profiles = FALSE;
270  info->FMStation = FALSE;
271  info->GPRSPoint = FALSE;
272  info->Note = FALSE;
273 
274  switch (Format) {
275  case GSM_Backup_LMB:
276  info->PhonePhonebook = TRUE;
277  info->SIMPhonebook = TRUE;
278  info->CallerLogos = TRUE;
279  info->StartupLogo = TRUE;
280  break;
281  case GSM_Backup_VCalendar:
282  info->ToDo = TRUE;
283  info->Calendar = TRUE;
284  break;
285  case GSM_Backup_VCard:
286  info->PhonePhonebook = TRUE;
287  info->SIMPhonebook = TRUE;
288  break;
289  case GSM_Backup_VNote:
290  info->Note = TRUE;
291  break;
292  case GSM_Backup_LDIF:
293  info->PhonePhonebook = TRUE;
294  break;
295  case GSM_Backup_ICS:
296  info->ToDo = TRUE;
297  info->Calendar = TRUE;
298  break;
299  case GSM_Backup_Gammu:
300  case GSM_Backup_GammuUCS2:
301  info->UseUnicode = TRUE;
302  info->IMEI = TRUE;
303  info->Model = TRUE;
304  info->DateTime = TRUE;
305  info->PhonePhonebook = TRUE;
306  info->SIMPhonebook = TRUE;
307  info->ToDo = TRUE;
308  info->Calendar = TRUE;
309  info->CallerLogos = TRUE;
310  info->SMSC = TRUE;
311  info->WAPBookmark = TRUE;
312  info->WAPSettings = TRUE;
313  info->MMSSettings = TRUE;
314  info->SyncMLSettings = TRUE;
315  info->ChatSettings = TRUE;
316  info->Ringtone = TRUE;
317  info->StartupLogo = TRUE;
318  info->OperatorLogo = TRUE;
319  info->Profiles = TRUE;
320  info->FMStation = TRUE;
321  info->GPRSPoint = TRUE;
322  info->Note = TRUE;
323  break;
324  default:
325  break;
326  }
327 }
328 
329 void GSM_GetBackupFileFeatures(GSM_BackupFormat Format, GSM_Backup_Info *info, GSM_Backup *backup)
330 {
331  GSM_GetBackupFormatFeatures(Format, info);
332 
333  if (info->PhonePhonebook && backup->PhonePhonebook[0] == NULL) info->PhonePhonebook = FALSE;
334  if (info->SIMPhonebook && backup->SIMPhonebook[0] == NULL) info->SIMPhonebook = FALSE;
335  if (info->Calendar && backup->Calendar[0] == NULL) info->Calendar = FALSE;
336  if (info->ToDo && backup->ToDo[0] == NULL) info->ToDo = FALSE;
337  if (info->WAPBookmark && backup->WAPBookmark[0] == NULL) info->WAPBookmark = FALSE;
338  if (info->WAPSettings && backup->WAPSettings[0] == NULL) info->WAPSettings = FALSE;
339  if (info->MMSSettings && backup->MMSSettings[0] == NULL) info->MMSSettings = FALSE;
340  if (info->FMStation && backup->FMStation[0] == NULL) info->FMStation = FALSE;
341  if (info->GPRSPoint && backup->GPRSPoint[0] == NULL) info->GPRSPoint = FALSE;
342  if (info->Profiles && backup->Profiles[0] == NULL) info->Profiles = FALSE;
343  /* .... */
344 }
345 
346 #endif
347 
348 /* How should editor hadle tabs in this file? Add editor commands here.
349  * vim: noexpandtab sw=8 ts=8 sts=8:
350  */
GSM_Error
Definition: gammu-error.h:23
void GSM_FreeMemoryEntry(GSM_MemoryEntry *Entry)
Definition: gsmpbk.c:1089
int gboolean
Definition: gammu-types.h:23
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28