]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * caldav.h | |
3 | * | |
4 | * Copyright 2016 Michael Rasmussen <mir@datanom.net> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 3 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
19 | * MA 02110-1301, USA. | |
20 | */ | |
21 | ||
22 | #ifndef __CALDAV_H__ | |
23 | #define __CALDAV_H__ | |
24 | ||
25 | #include <glib.h> | |
26 | ||
27 | G_BEGIN_DECLS | |
28 | ||
29 | typedef enum { | |
30 | VUNKNOWN, | |
31 | VEVENT, | |
32 | VTODO, | |
33 | VFREEBUSY, | |
34 | VJOURNAL, | |
35 | } Component; | |
36 | ||
37 | typedef struct { | |
38 | guint status; /* Status code from the request */ | |
39 | GSList* headers; /* List of headers in the response */ | |
40 | gpointer data; /* Either gchar* or GSList* (Calendar) or GSList* (options). */ | |
41 | /* If adding or updating a component a successful */ | |
42 | /* request will return the ETag in data */ | |
43 | } CaldavResponse; | |
44 | ||
45 | typedef enum { | |
46 | UNKNOWN, | |
47 | ADDOBJECTS, | |
48 | CALENDARINFO, | |
49 | CHANGEINFO, | |
50 | DELETEOBJECTS, | |
51 | DISCOVER, | |
52 | GETALLOBJECTS, | |
53 | GETOBJECTS, | |
54 | LOCKING, | |
55 | UNLOCKING, | |
56 | OPTIONSINFO, | |
57 | SIMPLEGET, | |
58 | UPDATEOBJECTS, | |
59 | FREEBUSY, | |
60 | } Operation; | |
61 | ||
62 | typedef struct { | |
63 | gchar* href; | |
64 | gchar* data; | |
65 | } HrefData; | |
66 | ||
67 | typedef guint (*Executor)(gpointer runtime); | |
68 | typedef struct { | |
69 | FILE* file; /* Where to write output. If file is NULL only output will be in 'output' */ | |
70 | gchar* username; /* Account to use */ | |
71 | gchar* password; /* Password for the account */ | |
72 | gchar* url; /* URL to caldav server */ | |
73 | gboolean debug; /* Show debug */ | |
74 | Operation* operation; /* Which operation to execute */ | |
75 | CaldavResponse* output; /* Structure containing the response */ | |
76 | Executor executor; /* Function which executes the request */ | |
77 | gboolean default_executor; /* Using default executors or custom executors */ | |
78 | gchar* etag; /* For If-Match */ | |
79 | gchar* component; /* The data for UPDATEOBJECTS or ADDOBJECTS */ | |
80 | GSList* hrefs; /* For GETOBJECTS: list of HrefData */ | |
81 | GSList* options; /* List of supported options by this caldav server */ | |
82 | GDateTime* start; /* Start time interval in ISO 8601 local time. */ | |
83 | /* 2017-01-13T13:13:13. For freebusy or get operations */ | |
84 | GDateTime* finish; /* End time interval in ISO 8601 local time. */ | |
85 | /* 2017-01-13T13:13:13. For freebusy or get operations */ | |
86 | } Runtime; | |
87 | ||
88 | typedef struct { | |
89 | gchar* url; | |
90 | gchar* displayname; | |
91 | gchar* ctag; | |
92 | GSList* components; /* list of Components */ | |
93 | } Calendar; | |
94 | ||
95 | /** | |
96 | * Return a new Runtime structure all zeroed out. | |
97 | * @return NULL or a new Runtime | |
98 | */ | |
99 | Runtime* runtime_new(); | |
100 | ||
101 | /** | |
102 | * Free a previously created Runtime structure. | |
103 | * @param runtime | |
104 | */ | |
105 | void runtime_free(Runtime* runtime); | |
106 | ||
107 | /** | |
108 | * Make a deep copy of a Runtime. | |
109 | * @param runtime | |
110 | * @return Runtime | |
111 | */ | |
112 | Runtime* runtime_copy(Runtime* runtime); | |
113 | ||
114 | /** | |
115 | * Execute the Runtime | |
116 | * @param runtime | |
117 | * @return guint | |
118 | */ | |
119 | guint execute(Runtime* runtime); | |
120 | ||
121 | /** | |
122 | * Make a deep copy of a Calendar structure | |
123 | * @param cal | |
124 | * @return a deep copy of the Calendar | |
125 | */ | |
126 | Calendar* calendar_copy(Calendar* cal); | |
127 | ||
128 | /** | |
129 | * Free previously created Calendar. | |
130 | * @param cal | |
131 | */ | |
132 | void calendar_free(Calendar* cal); | |
133 | ||
134 | /** | |
135 | * Dump Calendar to FILE. | |
136 | * @param file | |
137 | * @param cal | |
138 | */ | |
139 | void calendar_dump(FILE* file, Calendar* cal); | |
140 | ||
141 | /** | |
142 | * Test whether Component is equal to Component | |
143 | * @param value | |
144 | * @param component | |
145 | * @return TRUE or FALSE | |
146 | */ | |
147 | gboolean is_component(const gchar* value, Component component); | |
148 | ||
149 | /** | |
150 | * Convert Component to its string representation | |
151 | * @param component | |
152 | * @return String | |
153 | */ | |
154 | gchar* component_to_string(Component component); | |
155 | ||
156 | /** | |
157 | * Convert a String representation of a component to Component. | |
158 | * @param value | |
159 | * @return Component | |
160 | */ | |
161 | Component string_to_component(const gchar* value); | |
162 | ||
163 | /** | |
164 | * Get error as String from Runtime. | |
165 | * @param runtime | |
166 | * @return String | |
167 | */ | |
168 | gchar* status_str(Runtime* runtime); | |
169 | ||
170 | /** | |
171 | * Deep copy of a GSList containing Strings to another GSList. | |
172 | * @param list | |
173 | * @return GSList | |
174 | */ | |
175 | GSList* slist_copy_gchar(GSList* list); | |
176 | ||
177 | /** | |
178 | * Free a GSList of Strings. | |
179 | * @param list | |
180 | */ | |
181 | void slist_free_gchar(GSList* list); | |
182 | ||
183 | /** | |
184 | * Create a new HrefData structure. | |
185 | * @param href | |
186 | * @param data | |
187 | * @return HrefData | |
188 | */ | |
189 | HrefData* href_data_new(const gchar* href, const gchar* data); | |
190 | ||
191 | /** | |
192 | * Free a HrefData structure. | |
193 | * @param href_data | |
194 | */ | |
195 | void href_data_free(HrefData* href_data); | |
196 | ||
197 | /** | |
198 | * Find HTTP header in GSList of HTTP headers. | |
199 | * @param list | |
200 | * @param header | |
201 | * @return String | |
202 | */ | |
203 | gchar* find_header(GSList* list, const gchar* header); | |
204 | ||
205 | /** | |
206 | * Test whether caldav server supports option. | |
207 | * @param runtime | |
208 | * @param option | |
209 | * @return TRUE or FALSE | |
210 | */ | |
211 | gboolean has_option(Runtime* runtime, const gchar* option); | |
212 | ||
213 | /** | |
214 | * Convert a string representation of an ISO 8601 date to GDateTime. | |
215 | * @param datetime | |
216 | * @return GDateTime | |
217 | */ | |
218 | GDateTime* get_date_time_from_string(const gchar* datetime); | |
219 | ||
220 | G_END_DECLS | |
221 | ||
222 | #endif | |
223 |