remove uncovered code
[platform/core/pim/contacts-service.git] / common / ctsvc_struct.h
1 /*
2  * Contacts Service
3  *
4  * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef __CTSVC_STRUCT_H__
21 #define __CTSVC_STRUCT_H__
22
23 #include <stdbool.h>
24 #include <stdlib.h>
25 #include <glib.h>
26 #include <string.h>
27 #include <tzplatform_config.h>
28
29 #include "contacts_views.h"
30
31 #define CTSVC_SOCK_PATH "/run/user/%d/system_share"
32 #define CTSVC_IMG_FULL_PATH_SIZE_MAX 1024               /* current max length file path is 256 */
33 #define CTSVC_PATH_MAX_LEN 1024
34 #define CTSVC_STR_SHORT_LEN 1024
35 #define STRING_EQUAL 0
36
37 #define SAFE_STR(src) (src) ? src : ""
38 #define SAFE_STRDUP(src) (src) ? strdup(src) : NULL
39 #define SAFE_STRLEN(src) ((src) ? strlen(src) : 0)
40 #define FREEandSTRDUP(dest, src) \
41         do { \
42                 free(dest);\
43                 if (src) dest = strdup(src);\
44                 else dest = NULL; \
45         } while (0)
46 #define GET_STR(copy, str)      (copy) ? (SAFE_STRDUP(str)) : (str)
47 #define CHECK_DIRTY_STR(src1, src2, is_dirty) \
48         do { \
49                 if (src1 && NULL == src2) \
50                         *is_dirty = true; \
51                 else if (NULL == src1 && src2) \
52                         *is_dirty = true; \
53                 else if (src1 && src2 && 0 != strcmp(src1, src2)) \
54                         *is_dirty = true; \
55         } while (0)
56 #define CHECK_DIRTY_VAL(src1, src2, is_dirty) \
57         do { \
58                 if (src1 != src2) \
59                         *is_dirty = true; \
60         } while (0)
61
62 enum {
63         CTSVC_PERMISSION_CONTACT_NONE = 0x0,
64         CTSVC_PERMISSION_CONTACT_READ = 0x1,
65         CTSVC_PERMISSION_CONTACT_WRITE = 0x2,
66         CTSVC_PERMISSION_PHONELOG_READ = 0x4,
67         CTSVC_PERMISSION_PHONELOG_WRITE = 0x8,
68 };
69
70 typedef enum {
71         CTSVC_RECORD_INVALID = -1,
72         CTSVC_RECORD_ADDRESSBOOK,
73         CTSVC_RECORD_GROUP,
74         CTSVC_RECORD_PERSON,
75         CTSVC_RECORD_CONTACT,
76         CTSVC_RECORD_MY_PROFILE,
77         CTSVC_RECORD_SIMPLE_CONTACT,
78         CTSVC_RECORD_NAME,
79         CTSVC_RECORD_COMPANY,
80         CTSVC_RECORD_NOTE,
81         CTSVC_RECORD_NUMBER,
82         CTSVC_RECORD_EMAIL,
83         CTSVC_RECORD_URL,
84         CTSVC_RECORD_EVENT,
85         CTSVC_RECORD_NICKNAME,
86         CTSVC_RECORD_ADDRESS,
87         CTSVC_RECORD_MESSENGER,
88         CTSVC_RECORD_GROUP_RELATION,
89         CTSVC_RECORD_ACTIVITY,
90         CTSVC_RECORD_ACTIVITY_PHOTO,
91         CTSVC_RECORD_PROFILE,
92         CTSVC_RECORD_RELATIONSHIP,
93         CTSVC_RECORD_IMAGE,
94         CTSVC_RECORD_EXTENSION,
95         CTSVC_RECORD_UPDATED_INFO,
96         CTSVC_RECORD_PHONELOG,
97         CTSVC_RECORD_SPEEDDIAL,
98         CTSVC_RECORD_SDN,
99         CTSVC_RECORD_RESULT,
100         CTSVC_RECORD_SIP,
101 } ctsvc_record_type_e;
102
103 typedef enum {
104         CTSVC_FILTER_BOOL,
105         CTSVC_FILTER_INT,
106         CTSVC_FILTER_LLI,
107         CTSVC_FILTER_STR,
108         CTSVC_FILTER_DOUBLE,
109         CTSVC_FILTER_COMPOSITE,
110 } ctsvc_filter_type_e;
111
112 typedef struct {
113         unsigned int property_id;
114         int property_type;
115         void *fields;
116 } property_info_s;
117
118 typedef int (*__ctsvc_record_create_cb)(contacts_record_h *out_record);
119 typedef int (*__ctsvc_record_destroy_cb)(contacts_record_h record, bool delete_child);
120 typedef int (*__ctsvc_record_clone_cb)(contacts_record_h record, contacts_record_h *out_record);
121
122 typedef int (*__ctsvc_record_get_str_cb)(contacts_record_h record, unsigned int property_id, char **out_str);
123 typedef int (*__ctsvc_record_get_str_p_cb)(contacts_record_h record, unsigned int property_id, char **out_str);
124 typedef int (*__ctsvc_record_get_int_cb)(contacts_record_h record, unsigned int property_id, int *out_value);
125 typedef int (*__ctsvc_record_get_bool_cb)(contacts_record_h record, unsigned int property_id, bool *value);
126 typedef int (*__ctsvc_record_get_lli_cb)(contacts_record_h record, unsigned int property_id, long long int *value);
127 typedef int (*__ctsvc_record_get_double_cb)(contacts_record_h record, unsigned int property_id, double *value);
128
129 typedef int (*__ctsvc_record_set_str_cb)(contacts_record_h record, unsigned int property_id, const char *value, bool *is_dirty);
130 typedef int (*__ctsvc_record_set_int_cb)(contacts_record_h record, unsigned int property_id, int value, bool *is_dirty);
131 typedef int (*__ctsvc_record_set_bool_cb)(contacts_record_h record, unsigned int property_id, bool value, bool *is_dirty);
132 typedef int (*__ctsvc_record_set_lli_cb)(contacts_record_h record, unsigned int property_id, long long int value, bool *is_dirty);
133 typedef int (*__ctsvc_record_set_double_cb)(contacts_record_h record, unsigned int property_id, double value, bool *is_dirty);
134
135 typedef int (*__ctsvc_record_add_child_record_cb)(contacts_record_h record, unsigned int property_id, contacts_record_h child_record);
136 typedef int (*__ctsvc_record_remove_child_record_cb)(contacts_record_h record, unsigned int property_id, contacts_record_h child_record);
137 typedef int (*__ctsvc_record_get_child_record_count_cb)(contacts_record_h record, unsigned int property_id, int *count);
138 typedef int (*__ctsvc_record_get_child_record_at_p_cb)(contacts_record_h record, unsigned int property_id, int index, contacts_record_h *out_record);
139 typedef int (*__ctsvc_record_clone_child_record_list_cb)(contacts_record_h record, unsigned int property_id, contacts_list_h *out_list);
140
141 typedef struct {
142         __ctsvc_record_create_cb create;
143         __ctsvc_record_destroy_cb destroy;
144         __ctsvc_record_clone_cb clone;
145         __ctsvc_record_get_str_cb get_str;
146         __ctsvc_record_get_str_p_cb get_str_p;
147         __ctsvc_record_get_int_cb get_int;
148         __ctsvc_record_get_bool_cb get_bool;
149         __ctsvc_record_get_lli_cb get_lli;
150         __ctsvc_record_get_double_cb get_double;
151         __ctsvc_record_set_str_cb set_str;
152         __ctsvc_record_set_int_cb set_int;
153         __ctsvc_record_set_bool_cb set_bool;
154         __ctsvc_record_set_lli_cb set_lli;
155         __ctsvc_record_set_double_cb set_double;
156         __ctsvc_record_add_child_record_cb add_child_record;
157         __ctsvc_record_remove_child_record_cb remove_child_record;
158         __ctsvc_record_get_child_record_count_cb get_child_record_count;
159         __ctsvc_record_get_child_record_at_p_cb get_child_record_at_p;
160         __ctsvc_record_clone_child_record_list_cb clone_child_record_list;
161 } ctsvc_record_plugin_cb_s;
162
163 typedef struct {
164         int r_type;
165         const ctsvc_record_plugin_cb_s *plugin_cbs;
166         const char *view_uri;
167         unsigned int property_max_count;
168         unsigned char *properties_flags;
169         unsigned char property_flag;
170 } ctsvc_record_s;
171
172 typedef struct {
173         int filter_type;
174 } ctsvc_filter_s;
175
176 typedef struct {
177         int filter_type;
178         char *view_uri;
179         GSList *filter_ops; /* ctsvc_filter_operator_e op; */
180         GSList *filters;    /* ctsvc_filter_h l_filter; */
181         property_info_s *properties;
182         unsigned int property_count;
183 } ctsvc_composite_filter_s;
184
185 typedef struct {
186         int filter_type;
187         int property_id;
188         int match;
189         union {
190                 bool b;
191                 int i;
192                 char *s;
193                 long long int l;
194                 double d;
195         } value;
196 } ctsvc_attribute_filter_s;
197
198 typedef struct {
199         char *view_uri;
200         ctsvc_composite_filter_s *filter;
201         unsigned int *projection;
202         unsigned int projection_count;
203         unsigned int sort_property_id;
204         bool sort_asc;
205         property_info_s *properties;
206         unsigned int property_count;
207         bool distinct;
208 } ctsvc_query_s;
209
210 typedef struct {
211         int l_type;
212         int count;
213         GList *records;
214         GList *deleted_records;
215         GList *cursor;
216 } ctsvc_list_s;
217
218 typedef struct {
219         ctsvc_record_s base;
220         int id;
221         char *name;
222         int account_id;
223         int mode;
224 } ctsvc_addressbook_s;
225
226 typedef struct {
227         ctsvc_record_s base;
228         int id;
229         int addressbook_id;
230         bool is_read_only;
231         char *name;
232         char *extra_data;
233         char *ringtone_path;
234         char *vibration;
235         char *image_thumbnail_path;
236         char *message_alert;
237 } ctsvc_group_s;
238
239 typedef struct {
240         ctsvc_record_s base;
241         bool is_favorite;
242         bool has_phonenumber;
243         bool has_email;
244         int person_id;
245         int name_contact_id;
246         char *display_name;
247         char *display_name_index;
248         char *image_thumbnail_path;
249         char *ringtone_path;
250         char *vibration;
251         char *message_alert;
252         char *status;
253         int link_count;
254         char *addressbook_ids;
255         int snippet_type;
256         char *snippet_string;
257         double favorite_prio;
258 } ctsvc_person_s;
259
260 typedef struct {
261         ctsvc_record_s base;
262         bool is_favorite;
263         int changed_time;
264         bool has_phonenumber;
265         bool has_email;
266         int person_id;
267         int contact_id;
268         int addressbook_id;
269         char *image_thumbnail_path;
270         char *ringtone_path;
271         char *vibration;
272         char *message_alert;
273         char *display_name;
274         char *uid;
275         int display_source_type;
276 } ctsvc_simple_contact_s;
277
278 typedef struct {
279         ctsvc_record_s base;
280         bool is_default;
281         int id;
282         int contact_id;
283         int language_type;
284         char *first;
285         char *last;
286         char *addition;
287         char *prefix;
288         char *suffix;
289         char *phonetic_first;
290         char *phonetic_middle;
291         char *phonetic_last;
292         char *lookup;
293         char *reverse_lookup;
294 } ctsvc_name_s;
295
296 typedef struct {
297         ctsvc_record_s base;
298         bool is_default;
299         int id;
300         int contact_id;
301         int type;
302         char *label;
303         char *number;
304         char *cleaned;     /* internally used */
305         char *normalized;  /* internally used */
306         char *lookup;      /* internally used : for min match */
307 } ctsvc_number_s;
308
309 typedef struct {
310         ctsvc_record_s base;
311         bool is_default;
312         int id;
313         int contact_id;
314         int type;
315         char *label;
316         char *email_addr;
317 } ctsvc_email_s;
318
319 typedef struct {
320         ctsvc_record_s base;
321         int id;
322         int contact_id;
323         int type;
324         char *label;
325         char *url;
326 } ctsvc_url_s;
327
328 typedef struct {
329         ctsvc_record_s base;
330         bool is_default;
331         int id;
332         int contact_id;
333         int type;
334         char *label;
335         char *pobox;
336         char *postalcode;
337         char *region;
338         char *locality;
339         char *street;
340         char *extended;
341         char *country;
342 } ctsvc_address_s;
343
344 typedef struct {
345         ctsvc_record_s base;
346         int id;
347         int contact_id;
348         int type;
349         char *label;
350         int date;
351         bool is_leap_month;  /* deprecated */
352         int calendar_type;
353 } ctsvc_event_s;
354
355 typedef struct {
356         ctsvc_record_s base;
357         int id;
358         int contact_id;
359         int type;
360         char *label;
361         char *im_id;
362 } ctsvc_messenger_s;
363
364 typedef struct {
365         ctsvc_record_s base;
366         int id;
367         int contact_id;
368         int group_id;
369         char *group_name;
370 } ctsvc_group_relation_s;
371
372 typedef struct {
373         ctsvc_record_s base;
374         int id;
375         int contact_id;
376         int type;
377         char *label;
378         char *nickname;
379 } ctsvc_nickname_s;
380
381 typedef struct {
382         ctsvc_record_s base;
383         int id;
384         int contact_id;
385         char *uid;
386         char *text;
387         int  order;
388         char *service_operation;
389         char *mime;
390         char *app_id;
391         char *uri;
392         char *category;
393         char *extra_data;
394 } ctsvc_profile_s;
395
396 typedef struct {
397         ctsvc_record_s base;
398         int id;
399         int contact_id;
400         int type;
401         char *label;
402         char *name;
403 } ctsvc_relationship_s;
404
405 typedef struct {
406         ctsvc_record_s base;
407         bool is_vcard;
408         bool is_default;
409         int id;
410         int contact_id;
411         int type;
412         char *label;
413         char *path;
414 } ctsvc_image_s;
415
416 typedef struct {
417         ctsvc_record_s base;
418         int id;
419         int contact_id;
420         char *note;
421 } ctsvc_note_s;
422
423 typedef struct {
424         ctsvc_record_s base;
425         int id;
426         int contact_id;
427         char *source_name;
428         char *status;
429         int timestamp;
430         ctsvc_list_s *photos;
431         char *service_operation;
432         char *uri;
433 } ctsvc_activity_s;
434
435 typedef struct {
436         ctsvc_record_s base;
437         int id;
438         int activity_id;
439         char *photo_url;
440         int sort_index;
441 } ctsvc_activity_photo_s;
442
443 typedef struct {
444         ctsvc_record_s base;
445         int id;
446         int contact_id;
447         bool is_default;
448         bool is_vcard;
449         int type;
450         char *label;
451         char *name;
452         char *department;
453         char *job_title;
454         char *role;
455         char *assistant_name;
456         char *logo;
457         char *location;
458         char *description;
459         char *phonetic_name;
460 } ctsvc_company_s;
461
462 typedef struct {
463         ctsvc_record_s base;
464         int id;
465         char *address;
466         int person_id; /* person id */
467         int log_time;
468         int log_type;
469         int extra_data1; /* duration, message_id */
470         char *extra_data2; /*short message*/
471         int sim_slot_no;
472 } ctsvc_phonelog_s;
473
474 typedef struct {
475         ctsvc_record_s base;
476         int id;
477         int contact_id;
478         int data1;
479         char *data2;
480         char *data3;
481         char *data4;
482         char *data5;
483         char *data6;
484         char *data7;
485         char *data8;
486         char *data9;
487         char *data10;
488         char *data11;
489         char *data12;
490 } ctsvc_extension_s;
491
492 typedef struct {
493         ctsvc_record_s base;
494         bool is_favorite;
495         int id;
496         int person_id;
497         int changed_time;
498         int changed_ver;   /* internally used, check when updating contact */
499         int addressbook_id;
500         int link_mode;
501         bool has_phonenumber;
502         bool has_email;
503         char *display_name;
504         char *reverse_display_name;
505         int display_source_type;
506         int display_name_language;
507         int reverse_display_name_language;
508         char *sort_name;
509         char *reverse_sort_name;
510         char *sortkey;
511         char *reverse_sortkey;
512         char *uid;
513         char *image_thumbnail_path;
514         char *ringtone_path;
515         char *vibration;
516         char *message_alert;
517         ctsvc_list_s *name;
518         ctsvc_list_s *note;
519         ctsvc_list_s *company;
520         ctsvc_list_s *numbers;
521         ctsvc_list_s *emails;
522         ctsvc_list_s *grouprelations;
523         ctsvc_list_s *events;
524         ctsvc_list_s *messengers;
525         ctsvc_list_s *postal_addrs;
526         ctsvc_list_s *urls;
527         ctsvc_list_s *nicknames;
528         ctsvc_list_s *profiles;
529         ctsvc_list_s *relationships;
530         ctsvc_list_s *images;
531         ctsvc_list_s *extensions;
532         ctsvc_list_s *sips;
533 } ctsvc_contact_s;
534
535 typedef struct {
536         ctsvc_record_s base;
537         int id;
538         int addressbook_id;
539         int changed_time;
540         char *display_name;
541         char *reverse_display_name;
542         char *uid;
543         char *image_thumbnail_path;
544         ctsvc_list_s *name;
545         ctsvc_list_s *note;
546         ctsvc_list_s *company;
547         ctsvc_list_s *numbers;
548         ctsvc_list_s *emails;
549         ctsvc_list_s *events;
550         ctsvc_list_s *messengers;
551         ctsvc_list_s *postal_addrs;
552         ctsvc_list_s *urls;
553         ctsvc_list_s *nicknames;
554         ctsvc_list_s *profiles;
555         ctsvc_list_s *relationships;
556         ctsvc_list_s *images;
557         ctsvc_list_s *extensions;
558         ctsvc_list_s *sips;
559 } ctsvc_my_profile_s;
560
561 typedef struct {
562         ctsvc_record_s base;
563         int id;
564         char *name;
565         char *number;
566         int sim_slot_no;
567 } ctsvc_sdn_s;
568
569 typedef struct {
570         ctsvc_record_s base;
571         int changed_type;
572         int id;
573         int changed_ver;
574         int addressbook_id;
575         bool image_changed;
576         int last_changed_type;  /* it is used for _contacts_my_profile_updated_info */
577 } ctsvc_updated_info_s;
578
579 typedef struct {
580         ctsvc_record_s base;
581         int id;
582         int number_id;
583         int person_id;
584         char *display_name;
585         char *image_thumbnail_path;
586         int number_type;
587         char *label;
588         char *number;
589         int dial_number;
590 } ctsvc_speeddial_s;
591
592 typedef struct {
593         ctsvc_record_s base;
594         int id;
595         int contact_id;
596         char *address;
597         int type;
598         char *label;
599 } ctsvc_sip_s;
600
601 typedef struct {
602         int property_id;
603         int type;
604         union {
605                 bool b;
606                 int i;
607                 char *s;
608                 long long int l;
609                 double d;
610         } value;
611 } ctsvc_result_value_s;
612
613 typedef struct {
614         ctsvc_record_s base;
615         GSList *values;
616 } ctsvc_result_s;
617
618 typedef struct {
619         int version;
620         int connection_count;
621 } ctsvc_base_s;
622
623 #endif /* __CTSVC_STRUCT_H__ */