1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2017 Red Hat, Inc. (www.redhat.com)
4  *
5  * This library is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12  * for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #if !defined (__LIBEDATA_BOOK_H_INSIDE__) && !defined (LIBEDATA_BOOK_COMPILATION)
19 #error "Only <libedata-book/libedata-book.h> should be included directly."
20 #endif
21 
22 #ifndef E_BOOK_META_BACKEND_H
23 #define E_BOOK_META_BACKEND_H
24 
25 #include <libebackend/libebackend.h>
26 #include <libedata-book/e-book-backend-sync.h>
27 #include <libedata-book/e-book-cache.h>
28 #include <libebook-contacts/libebook-contacts.h>
29 
30 /* Standard GObject macros */
31 #define E_TYPE_BOOK_META_BACKEND \
32 	(e_book_meta_backend_get_type ())
33 #define E_BOOK_META_BACKEND(obj) \
34 	(G_TYPE_CHECK_INSTANCE_CAST \
35 	((obj), E_TYPE_BOOK_META_BACKEND, EBookMetaBackend))
36 #define E_BOOK_META_BACKEND_CLASS(cls) \
37 	(G_TYPE_CHECK_CLASS_CAST \
38 	((cls), E_TYPE_BOOK_META_BACKEND, EBookMetaBackendClass))
39 #define E_IS_BOOK_META_BACKEND(obj) \
40 	(G_TYPE_CHECK_INSTANCE_TYPE \
41 	((obj), E_TYPE_BOOK_META_BACKEND))
42 #define E_IS_BOOK_META_BACKEND_CLASS(cls) \
43 	(G_TYPE_CHECK_CLASS_TYPE \
44 	((cls), E_TYPE_BOOK_META_BACKEND))
45 #define E_BOOK_META_BACKEND_GET_CLASS(obj) \
46 	(G_TYPE_INSTANCE_GET_CLASS \
47 	((obj), E_TYPE_BOOK_META_BACKEND, EBookMetaBackendClass))
48 
49 G_BEGIN_DECLS
50 
51 typedef struct _EBookMetaBackendInfo {
52 	gchar *uid;
53 	gchar *revision;
54 	gchar *object;
55 	gchar *extra;
56 } EBookMetaBackendInfo;
57 
58 #define E_TYPE_BOOK_META_BACKEND_INFO (e_book_meta_backend_info_get_type ())
59 
60 GType		e_book_meta_backend_info_get_type
61 						(void) G_GNUC_CONST;
62 EBookMetaBackendInfo *
63 		e_book_meta_backend_info_new	(const gchar *uid,
64 						 const gchar *revision,
65 						 const gchar *object,
66 						 const gchar *extra);
67 EBookMetaBackendInfo *
68 		e_book_meta_backend_info_copy	(const EBookMetaBackendInfo *src);
69 void		e_book_meta_backend_info_free	(gpointer ptr /* EBookMetaBackendInfo * */);
70 
71 typedef struct _EBookMetaBackend EBookMetaBackend;
72 typedef struct _EBookMetaBackendClass EBookMetaBackendClass;
73 typedef struct _EBookMetaBackendPrivate EBookMetaBackendPrivate;
74 
75 /**
76  * EBookMetaBackend:
77  *
78  * Contains only private data that should be read and manipulated using
79  * the functions below.
80  *
81  * Since: 3.26
82  **/
83 struct _EBookMetaBackend {
84 	/*< private >*/
85 	EBookBackendSync parent;
86 	EBookMetaBackendPrivate *priv;
87 };
88 
89 /**
90  * EBookMetaBackendClass:
91  *
92  * Class structure for the #EBookMetaBackend class.
93  *
94  * Since: 3.26
95  */
96 struct _EBookMetaBackendClass {
97 	/*< private >*/
98 	EBookBackendSyncClass parent_class;
99 
100 	/* For Direct Read Access */
101 	const gchar *backend_module_filename;
102 	const gchar *backend_factory_type_name;
103 
104 	/* Virtual methods */
105 	gboolean	(* connect_sync)	(EBookMetaBackend *meta_backend,
106 						 const ENamedParameters *credentials,
107 						 ESourceAuthenticationResult *out_auth_result,
108 						 gchar **out_certificate_pem,
109 						 GTlsCertificateFlags *out_certificate_errors,
110 						 GCancellable *cancellable,
111 						 GError **error);
112 	gboolean	(* disconnect_sync)	(EBookMetaBackend *meta_backend,
113 						 GCancellable *cancellable,
114 						 GError **error);
115 
116 	gboolean	(* get_changes_sync)	(EBookMetaBackend *meta_backend,
117 						 const gchar *last_sync_tag,
118 						 gboolean is_repeat,
119 						 gchar **out_new_sync_tag,
120 						 gboolean *out_repeat,
121 						 GSList **out_created_objects, /* EBookMetaBackendInfo * */
122 						 GSList **out_modified_objects, /* EBookMetaBackendInfo * */
123 						 GSList **out_removed_objects, /* EBookMetaBackendInfo * */
124 						 GCancellable *cancellable,
125 						 GError **error);
126 	gboolean	(* list_existing_sync)	(EBookMetaBackend *meta_backend,
127 						 gchar **out_new_sync_tag,
128 						 GSList **out_existing_objects, /* EBookMetaBackendInfo * */
129 						 GCancellable *cancellable,
130 						 GError **error);
131 	gboolean	(* load_contact_sync)	(EBookMetaBackend *meta_backend,
132 						 const gchar *uid,
133 						 const gchar *extra,
134 						 EContact **out_contact,
135 						 gchar **out_extra,
136 						 GCancellable *cancellable,
137 						 GError **error);
138 	gboolean	(* save_contact_sync)	(EBookMetaBackend *meta_backend,
139 						 gboolean overwrite_existing,
140 						 EConflictResolution conflict_resolution,
141 						 /* const */ EContact *contact,
142 						 const gchar *extra,
143 						 guint32 opflags, /* bit-or of EBookOperationFlags */
144 						 gchar **out_new_uid,
145 						 gchar **out_new_extra,
146 						 GCancellable *cancellable,
147 						 GError **error);
148 	gboolean	(* remove_contact_sync)	(EBookMetaBackend *meta_backend,
149 						 EConflictResolution conflict_resolution,
150 						 const gchar *uid,
151 						 const gchar *extra,
152 						 const gchar *object,
153 						 guint32 opflags, /* bit-or of EBookOperationFlags */
154 						 GCancellable *cancellable,
155 						 GError **error);
156 	gboolean	(* search_sync)		(EBookMetaBackend *meta_backend,
157 						 const gchar *expr,
158 						 gboolean meta_contact,
159 						 GSList **out_contacts, /* EContact * */
160 						 GCancellable *cancellable,
161 						 GError **error);
162 	gboolean	(* search_uids_sync)	(EBookMetaBackend *meta_backend,
163 						 const gchar *expr,
164 						 GSList **out_uids, /* gchar * */
165 						 GCancellable *cancellable,
166 						 GError **error);
167 	gboolean	(* requires_reconnect)	(EBookMetaBackend *meta_backend);
168 
169 	/* Signals */
170 	void		(* source_changed)	(EBookMetaBackend *meta_backend);
171 
172 	gboolean	(* get_ssl_error_details)
173 						(EBookMetaBackend *meta_backend,
174 						 gchar **out_certificate_pem,
175 						 GTlsCertificateFlags *out_certificate_errors);
176 
177 	/* For Direct Read Access - directory with the backend_module_filename,
178 	   when it differs from the default module directory */
179 	const gchar *backend_module_directory;
180 
181 	/* Padding for future expansion */
182 	gpointer reserved[8];
183 };
184 
185 GType		e_book_meta_backend_get_type	(void) G_GNUC_CONST;
186 
187 const gchar *	e_book_meta_backend_get_capabilities
188 						(EBookMetaBackend *meta_backend);
189 void		e_book_meta_backend_set_ever_connected
190 						(EBookMetaBackend *meta_backend,
191 						 gboolean value);
192 gboolean	e_book_meta_backend_get_ever_connected
193 						(EBookMetaBackend *meta_backend);
194 void		e_book_meta_backend_set_connected_writable
195 						(EBookMetaBackend *meta_backend,
196 						 gboolean value);
197 gboolean	e_book_meta_backend_get_connected_writable
198 						(EBookMetaBackend *meta_backend);
199 gchar *		e_book_meta_backend_dup_sync_tag(EBookMetaBackend *meta_backend);
200 void		e_book_meta_backend_set_cache	(EBookMetaBackend *meta_backend,
201 						 EBookCache *cache);
202 EBookCache *	e_book_meta_backend_ref_cache	(EBookMetaBackend *meta_backend);
203 gboolean	e_book_meta_backend_inline_local_photos_sync
204 						(EBookMetaBackend *meta_backend,
205 						 EContact *contact,
206 						 GCancellable *cancellable,
207 						 GError **error);
208 gboolean	e_book_meta_backend_store_inline_photos_sync
209 						(EBookMetaBackend *meta_backend,
210 						 EContact *contact,
211 						 GCancellable *cancellable,
212 						 GError **error);
213 gboolean	e_book_meta_backend_empty_cache_sync
214 						(EBookMetaBackend *meta_backend,
215 						 GCancellable *cancellable,
216 						 GError **error);
217 void		e_book_meta_backend_schedule_refresh
218 						(EBookMetaBackend *meta_backend);
219 gboolean	e_book_meta_backend_refresh_sync
220 						(EBookMetaBackend *meta_backend,
221 						 GCancellable *cancellable,
222 						 GError **error);
223 gboolean	e_book_meta_backend_ensure_connected_sync
224 						(EBookMetaBackend *meta_backend,
225 						 GCancellable *cancellable,
226 						 GError **error);
227 gboolean	e_book_meta_backend_split_changes_sync
228 						(EBookMetaBackend *meta_backend,
229 						 GSList *objects, /* EBookMetaBackendInfo * */
230 						 GSList **out_created_objects, /* EBookMetaBackendInfo * */
231 						 GSList **out_modified_objects, /* EBookMetaBackendInfo * */
232 						 GSList **out_removed_objects, /* EBookMetaBackendInfo * */
233 						 GCancellable *cancellable,
234 						 GError **error);
235 gboolean	e_book_meta_backend_process_changes_sync
236 						(EBookMetaBackend *meta_backend,
237 						 const GSList *created_objects, /* EBookMetaBackendInfo * */
238 						 const GSList *modified_objects, /* EBookMetaBackendInfo * */
239 						 const GSList *removed_objects, /* EBookMetaBackendInfo * */
240 						 GCancellable *cancellable,
241 						 GError **error);
242 gboolean	e_book_meta_backend_connect_sync(EBookMetaBackend *meta_backend,
243 						 const ENamedParameters *credentials,
244 						 ESourceAuthenticationResult *out_auth_result,
245 						 gchar **out_certificate_pem,
246 						 GTlsCertificateFlags *out_certificate_errors,
247 						 GCancellable *cancellable,
248 						 GError **error);
249 gboolean	e_book_meta_backend_disconnect_sync
250 						(EBookMetaBackend *meta_backend,
251 						 GCancellable *cancellable,
252 						 GError **error);
253 gboolean	e_book_meta_backend_get_changes_sync
254 						(EBookMetaBackend *meta_backend,
255 						 const gchar *last_sync_tag,
256 						 gboolean is_repeat,
257 						 gchar **out_new_sync_tag,
258 						 gboolean *out_repeat,
259 						 GSList **out_created_objects, /* EBookMetaBackendInfo * */
260 						 GSList **out_modified_objects, /* EBookMetaBackendInfo * */
261 						 GSList **out_removed_objects, /* EBookMetaBackendInfo * */
262 						 GCancellable *cancellable,
263 						 GError **error);
264 gboolean	e_book_meta_backend_list_existing_sync
265 						(EBookMetaBackend *meta_backend,
266 						 gchar **out_new_sync_tag,
267 						 GSList **out_existing_objects, /* EBookMetaBackendInfo * */
268 						 GCancellable *cancellable,
269 						 GError **error);
270 gboolean	e_book_meta_backend_load_contact_sync
271 						(EBookMetaBackend *meta_backend,
272 						 const gchar *uid,
273 						 const gchar *extra,
274 						 EContact **out_contact,
275 						 gchar **out_extra,
276 						 GCancellable *cancellable,
277 						 GError **error);
278 gboolean	e_book_meta_backend_save_contact_sync
279 						(EBookMetaBackend *meta_backend,
280 						 gboolean overwrite_existing,
281 						 EConflictResolution conflict_resolution,
282 						 /* const */ EContact *contact,
283 						 const gchar *extra,
284 						 guint32 opflags, /* bit-or of EBookOperationFlags */
285 						 gchar **out_new_uid,
286 						 gchar **out_new_extra,
287 						 GCancellable *cancellable,
288 						 GError **error);
289 gboolean	e_book_meta_backend_remove_contact_sync
290 						(EBookMetaBackend *meta_backend,
291 						 EConflictResolution conflict_resolution,
292 						 const gchar *uid,
293 						 const gchar *extra,
294 						 const gchar *object,
295 						 guint32 opflags, /* bit-or of EBookOperationFlags */
296 						 GCancellable *cancellable,
297 						 GError **error);
298 gboolean	e_book_meta_backend_search_sync	(EBookMetaBackend *meta_backend,
299 						 const gchar *expr,
300 						 gboolean meta_contact,
301 						 GSList **out_contacts, /* EContact * */
302 						 GCancellable *cancellable,
303 						 GError **error);
304 gboolean	e_book_meta_backend_search_uids_sync
305 						(EBookMetaBackend *meta_backend,
306 						 const gchar *expr,
307 						 GSList **out_uids, /* gchar * */
308 						 GCancellable *cancellable,
309 						 GError **error);
310 gboolean	e_book_meta_backend_requires_reconnect
311 						(EBookMetaBackend *meta_backend);
312 gboolean	e_book_meta_backend_get_ssl_error_details
313 						(EBookMetaBackend *meta_backend,
314 						 gchar **out_certificate_pem,
315 						 GTlsCertificateFlags *out_certificate_errors);
316 
317 G_END_DECLS
318 
319 #endif /* E_BOOK_META_BACKEND_H */
320