Gammu internals  1.38.0
backics.c
Go to the documentation of this file.
1 /* (c) 2003 by Marcin Wiacek */
2 
3 #include <string.h>
4 #include <ctype.h>
5 
6 #include <gammu-config.h>
7 
8 #include "../../misc/coding/coding.h"
9 #include "../../debug.h"
10 #include "../gsmlogo.h"
11 #include "../gsmmisc.h"
12 #include "backics.h"
13 #include "backvcs.h"
14 
15 #ifdef GSM_ENABLE_BACKUP
16 
20 #define chk_fwrite(data, size, count, file) \
21  if (fwrite(data, size, count, file) != count) goto fail;
22 
23 GSM_Error SaveICS(const char *FileName, GSM_Backup *backup)
24 {
25  int i;
26  size_t Length = 0;
27  unsigned char Buffer[1000];
28  FILE *file;
29  GSM_Error error;
30 
31  file = fopen(FileName, "wb");
32  if (file == NULL) return ERR_CANTOPENFILE;
33 
34  Length=sprintf(Buffer, "BEGIN:VCALENDAR%c%c",13,10);
35  Length+=sprintf(Buffer+Length, "VERSION:2.0%c%c",13,10);
36  chk_fwrite(Buffer,1,Length,file);
37 
38  i=0;
39  while (backup->Calendar[i]!=NULL) {
40  sprintf(Buffer, "%c%c",13,10);
41  chk_fwrite(Buffer,1,2,file);
42  Length = 0;
43  error = GSM_EncodeVCALENDAR(Buffer, sizeof(Buffer),&Length,backup->Calendar[i],FALSE,Mozilla_iCalendar);
44  if (error != ERR_NONE) {
45  fclose(file);
46  return error;
47  }
48  chk_fwrite(Buffer,1,Length,file);
49  i++;
50  }
51  i=0;
52  while (backup->ToDo[i]!=NULL) {
53  sprintf(Buffer, "%c%c",13,10);
54  chk_fwrite(Buffer,1,2,file);
55  Length = 0;
56  error = GSM_EncodeVTODO(Buffer, sizeof(Buffer), &Length,backup->ToDo[i],FALSE,Mozilla_VToDo);
57  if (error != ERR_NONE) {
58  fclose(file);
59  return error;
60  }
61  chk_fwrite(Buffer,1,Length,file);
62  i++;
63  }
64 
65  Length=sprintf(Buffer, "%c%cEND:VCALENDAR%c%c",13,10,13,10);
66  chk_fwrite(Buffer,1,Length,file);
67 
68  fclose(file);
69  return ERR_NONE;
70 fail:
71  fclose(file);
72  return ERR_WRITING_FILE;
73 }
74 
75 GSM_Error LoadICS(const char *FileName, GSM_Backup *backup)
76 {
77  return LoadVCalendarPrivate(FileName, backup, Mozilla_iCalendar, Mozilla_VToDo);
78 }
79 
80 #endif
81 
82 /* How should editor hadle tabs in this file? Add editor commands here.
83  * vim: noexpandtab sw=8 ts=8 sts=8:
84  */
GSM_Error GSM_EncodeVCALENDAR(char *Buffer, const size_t buff_len, size_t *Length, GSM_CalendarEntry *note, const gboolean header, const GSM_VCalendarVersion Version)
Definition: gsmcal.c:814
GSM_Error
Definition: gammu-error.h:23
#define chk_fwrite(data, size, count, file)
Definition: gsmlogo.c:20
#define FALSE
Definition: gammu-types.h:25
GSM_Error GSM_EncodeVTODO(char *Buffer, const size_t buff_len, size_t *Length, const GSM_ToDoEntry *note, const gboolean header, const GSM_VToDoVersion Version)
Definition: gsmcal.c:1038