1 /*
2 carddav.h
3 Copyright (C) 2015  Belledonne Communications SARL
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 */
19 
20 #ifndef LINPHONE_CARDDAV_H
21 #define LINPHONE_CARDDAV_H
22 
23 #include "linphone/core.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 /**
30  * @addtogroup carddav_vcard
31  * @{
32  */
33 
34 typedef struct _LinphoneCardDavContext LinphoneCardDavContext;
35 
36 typedef enum _LinphoneCardDavQueryType {
37 	LinphoneCardDavQueryTypePropfind,
38 	LinphoneCardDavQueryTypeAddressbookQuery,
39 	LinphoneCardDavQueryTypeAddressbookMultiget,
40 	LinphoneCardDavQueryTypePut,
41 	LinphoneCardDavQueryTypeDelete
42 } LinphoneCardDavQueryType;
43 
44 typedef struct _LinphoneCardDavQuery LinphoneCardDavQuery;
45 
46 typedef struct _LinphoneCardDavResponse LinphoneCardDavResponse;
47 
48 /**
49  * Callback used to notify a new contact has been created on the CardDAV server
50 **/
51 typedef void (*LinphoneCardDavContactCreatedCb)(LinphoneCardDavContext *cdc, LinphoneFriend *lf);
52 
53 /**
54  * Callback used to notify a contact has been updated on the CardDAV server
55 **/
56 typedef void (*LinphoneCardDavContactUpdatedCb)(LinphoneCardDavContext *cdc, LinphoneFriend *new_friend, LinphoneFriend *old_friend);
57 
58 /**
59  * Callback used to notify a contact has been removed on the CardDAV server
60 **/
61 typedef void (*LinphoneCardDavContactRemovedCb)(LinphoneCardDavContext *cdc, LinphoneFriend *lf);
62 
63 /**
64  * Callback used to notify a contact has been removed on the CardDAV server
65 **/
66 typedef void (*LinphoneCardDavSynchronizationDoneCb)(LinphoneCardDavContext *cdc, bool_t success, const char *message);
67 
68 /**
69  * Creates a CardDAV context for all related operations
70  * @param lfl LinphoneFriendList object
71  * @return LinphoneCardDavContext object if vCard support is enabled and server URL is available, NULL otherwise
72  */
73 LINPHONE_PUBLIC LinphoneCardDavContext* linphone_carddav_context_new(LinphoneFriendList *lfl);
74 
75 /**
76  * Deletes a LinphoneCardDavContext object
77  * @param cdc LinphoneCardDavContext object
78  */
79 LINPHONE_PUBLIC void linphone_carddav_context_destroy(LinphoneCardDavContext *cdc);
80 
81 /**
82  * Sets a user pointer to the LinphoneCardDAVContext object
83  * @param cdc LinphoneCardDavContext object
84  * @param ud The user data pointer
85  */
86 LINPHONE_PUBLIC void linphone_carddav_set_user_data(LinphoneCardDavContext *cdc, void *ud);
87 
88 /**
89  * Gets the user pointer set in the LinphoneCardDAVContext object
90  * @param cdc LinphoneCardDavContext object
91  * @return The user data pointer if set, NULL otherwise
92  */
93 LINPHONE_PUBLIC void* linphone_carddav_get_user_data(LinphoneCardDavContext *cdc);
94 
95 /**
96  * Starts a synchronization with the remote server to update local friends with server changes
97  * @param cdc LinphoneCardDavContext object
98  */
99 LINPHONE_PUBLIC void linphone_carddav_synchronize(LinphoneCardDavContext *cdc);
100 
101 /**
102  * Sends a LinphoneFriend to the CardDAV server for update or creation
103  * @param cdc LinphoneCardDavContext object
104  * @param lf a LinphoneFriend object to update/create on the server
105  */
106 LINPHONE_PUBLIC void linphone_carddav_put_vcard(LinphoneCardDavContext *cdc, LinphoneFriend *lf);
107 
108 /**
109  * Deletes a LinphoneFriend on the CardDAV server
110  * @param cdc LinphoneCardDavContext object
111  * @param lf a LinphoneFriend object to delete on the server
112  */
113 LINPHONE_PUBLIC void linphone_carddav_delete_vcard(LinphoneCardDavContext *cdc, LinphoneFriend *lf);
114 
115 /**
116  * Set the synchronization done callback.
117  * @param cdc LinphoneCardDavContext object
118  * @param cb The synchronization done callback to be used.
119  */
120 LINPHONE_PUBLIC void linphone_carddav_set_synchronization_done_callback(LinphoneCardDavContext *cdc, LinphoneCardDavSynchronizationDoneCb cb);
121 
122 /**
123  * Set the new contact callback.
124  * @param cdc LinphoneCardDavContext object
125  * @param cb The new contact callback to be used.
126  */
127 LINPHONE_PUBLIC void linphone_carddav_set_new_contact_callback(LinphoneCardDavContext *cdc, LinphoneCardDavContactCreatedCb cb);
128 
129 /**
130  * Set the updated contact callback.
131  * @param cdc LinphoneCardDavContext object
132  * @param cb The updated contact callback to be used.
133  */
134 LINPHONE_PUBLIC void linphone_carddav_set_updated_contact_callback(LinphoneCardDavContext *cdc, LinphoneCardDavContactUpdatedCb cb);
135 
136 /**
137  * Set the removed contact callback.
138  * @param cdc LinphoneCardDavContext object
139  * @param cb The removed contact callback to be used.
140  */
141 LINPHONE_PUBLIC void linphone_carddav_set_removed_contact_callback(LinphoneCardDavContext *cdc, LinphoneCardDavContactRemovedCb cb);
142 
143 /**
144  * Retrieves the current cTag value for the remote server
145  * @param cdc LinphoneCardDavContext object
146  */
147 void linphone_carddav_get_current_ctag(LinphoneCardDavContext *cdc);
148 
149 /**
150  * Retrieves a list of all the vCards on server side to be able to detect changes
151  * @param cdc LinphoneCardDavContext object
152  */
153 void linphone_carddav_fetch_vcards(LinphoneCardDavContext *cdc);
154 
155 /**
156  * Download asked vCards from the server
157  * @param cdc LinphoneCardDavContext object
158  * @param vcards_to_pull a MSList of LinphoneCardDavResponse objects with at least the url field filled
159  */
160 void linphone_carddav_pull_vcards(LinphoneCardDavContext *cdc, MSList *vcards_to_pull);
161 
162 /**
163  * @}
164  */
165 
166 #ifdef __cplusplus
167 }
168 #endif
169 
170 #endif
171