Fix build breaks in contact
[profile/ivi/wrt-plugins-tizen.git] / src / platform / Tizen / Contact / query-svc / query-type.h
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /**
18  * @file                query-type.h
19  * @author      JihwaPark (82-32-3016262, jh7979.park@samsung.com)
20  * @version      1.0(2010.10.05)
21  * @brief       This file has internal structure and logging APIs
22  */
23
24
25 #ifndef _QUERY_TYPE_H
26 #define _QUERY_TYPE_H
27
28 #define LOG_TAG "QUERY_SVC"
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <getopt.h>
33 #include <string.h>
34 #include "glib.h"
35 #include <glib-object.h>
36
37 #include <time.h>
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <unistd.h>
41 #include <fcntl.h>
42
43 #include "db-util.h"
44 #include "query-service.h"
45 #include <dlog.h>
46
47 #define PROJECTION_FIELD_LEN 64
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif /* __cplusplus */
52
53 //#define ADVANCED_USE_DLOG_MESSAGE
54 //#define CHECK_PERFORMANCE
55
56 #ifdef ADVANCED_USE_DLOG_MESSAGE
57 #define ADVANCED_SVC_TRACE(fmt, arg...) \
58         SLOGD("\n[QUERY_SVC]%s %d: " fmt "", __FUNCTION__, __LINE__, ##arg);
59 #else
60 #define ADVANCED_SVC_TRACE(fmt, arg...) \
61 //      fprintf(stderr, "\n[QUERY_SVC]%s %d: " fmt "", __FUNCTION__, __LINE__, ##arg);
62 #endif
63
64 #ifdef CHECK_PERFORMANCE
65 #define PERFORMANCE_TRACE(fmt, arg...) \
66         fprintf(stderr, "\n[QUERY_SVC]%s %d: " fmt "", __FUNCTION__, __LINE__, ##arg);
67 #else
68 #define PERFORMANCE_TRACE(fmt, arg...)
69 #endif
70
71 #define ADVANCED_SVC_ERROR_TRACE(fmt, arg...) \
72         fprintf(stderr, "\n[AdvancedSvc]%s %d: " fmt "", __FUNCTION__, __LINE__, ##arg);
73
74 #define ADVANCED_RETURN_VAL(eval, expr, ret_val, X)\
75         if (!(eval)) \
76         {\
77                 expr; \
78                 {ADVANCED_SVC_TRACE X;}\
79                 return ret_val;\
80         } else {;}
81
82 #define ADVANCED_CATCH_SET_ERROR(eval, expr, error_val, X) \
83         if (!(eval)) \
84         {\
85                 expr; \
86                 error_code = (error_val);\
87                 {ADVANCED_SVC_TRACE X;}\
88                 goto CATCH;\
89         } else {;}
90
91 #define ADVANCED_CATCH_SET_ERROR_POINTER(eval, expr, error_val, X) \
92         if (!(eval)) \
93         {\
94                 expr; \
95                 *error_code = (error_val);\
96                 {ADVANCED_SVC_TRACE X;}\
97                 goto CATCH;\
98         } else {;}
99
100 #define OBJ_FREE(obj) if(obj != NULL) { free(obj); \
101         (obj) = NULL; \
102 }
103 /****************************************************************************************************/
104 /*                                                                       GLOBAL STRUCTURE DECLARATION                                                                   */
105 /****************************************************************************************************/
106 #define _TABLE_SQLITE_SEQ "sqlite_sequence"                             // auto generated table
107 #define QUERY_MAX_LEN 2048
108 #define MAX_NUMBER_TYPE 14
109 #define MAX_EMAIL_TYPE 3
110 #define MAX_ADDRESS_TYPE 7
111
112 typedef enum
113 {
114         EXTRA_INFO_TYPE_FIELD = 0,
115         EXTRA_INFO_TYPE_CONDITION,
116 }extra_info_type;
117
118 typedef enum
119 {
120         ALIAS_INVALID = 0,
121         ALIAS_A,
122         ALIAS_B,
123         ALIAS_C,
124         ALIAS_D,
125         ALIAS_E,
126         ALIAS_F,
127         ALIAS_G,
128         ALIAS_H,
129         ALIAS_I,
130         ALIAS_J,
131         ALIAS_K,
132         ALIAS_L,
133         ALIAS_M,
134         ALIAS_N,
135         ALIAS_O,
136         ALIAS_P,
137         ALIAS_Q,
138         ALIAS_R,
139         ALIAS_S,
140         ALIAS_T,
141         ALIAS_U,
142         ALIAS_V,
143         ALIAS_W,
144         ALIAS_X,
145         ALIAS_Y,
146         ALIAS_Z,
147         ALIAS_MAX
148 }alias_key_e;
149
150 typedef enum
151 {
152         DATATYPE_INVALID = 0x00000000,
153         DATATYPE_NAME = 0x00000001,
154         DATATYPE_NUMBER = 0x00000002,
155         DATATYPE_EMAIL = 0x00000004,
156         DATATYPE_URL = 0x00000008,
157         DATATYPE_NICK_NAME = 0x00000010,
158         DATATYPE_ADDRESS = 0x00000020,
159         DATATYPE_ORGANIZATION = 0x00000040,
160         DATATYPE_BIRTH_DAY = 0x00000080,
161         DATATYPE_ANNIVERSARY = 0x0000100,
162         DATATYPE_IM_ADDR = 0x0000200,
163 //      DATATYPE_LBS_INFO = 0x00000400,
164         DATATYPE_CATEGORY = 0x00000800,
165         DATATYPE_X_ATTRIBUTE = 0x80000000,
166 }predefine_datatype;
167
168 typedef enum
169 {
170         DB_DATATYPE_INVALID = 0,
171         DB_DATATYPE_NAME,
172         DB_DATATYPE_ADDRESS,
173         DB_DATATYPE_IM,
174         DB_DATATYPE_URL,
175         DB_DATATYPE_EVENT,
176         DB_DATATYPE_ORGANIZATION,
177         DB_DATATYPE_NICK_NAME,
178         DB_DATATYPE_NUMBER,
179         DB_DATATYPE_EMAIL,
180
181 //      DB_DATATYPE_LBS_INFO,
182 //      DB_DATATYPE_CATEGORY,
183         DB_DATATYPE_MAX = 100,
184 }db_datatype;
185
186 typedef enum
187 {
188         NONE    = 0x00000000,
189         HOME    = 0x00000001,
190         WORK    = 0x00000002,
191         VOICE   = 0x00000004,
192         FAX     = 0x00000008,
193         MSG     = 0x00000010,
194         CELL    = 0x00000020,
195         PAGER   = 0x00000040,
196         BBS     = 0x00000080,
197         MODEM   = 0x00000100,
198         CAR     = 0x00000200,
199         ISDN    = 0x00000400,
200         VIDEO   = 0x00000800,
201         PCS     = 0x00001000,
202 }number_type;
203
204 static char* number_type_str[MAX_NUMBER_TYPE] =
205 {
206         "NONE",
207         "HOME",
208         "WORK",
209         "VOICE",
210         "FAX",
211         "MSG",
212         "CELL",
213         "PAGER",
214         "BBS",
215         "MODEM",
216         "CAR",
217         "ISDN",
218         "VIDEO",
219         "PCS",
220 };
221
222 typedef enum
223 {
224         EMAIL_TYPE_NONE         = 0x00000000,
225         EMAIL_HOME                      = 0x00000001,
226         EMAIL_WORK                      = 0x00000002,
227 }email_type;
228
229 static char* email_type_str[MAX_EMAIL_TYPE] =
230 {
231         "NONE",
232         "HOME",
233         "WORK",
234 };
235
236 typedef enum
237 {
238         URL_TYPE_NONE = 0,
239         URL_HOME,
240         URL_WORK,
241         URL_TYPE_MAX
242 }url_type;
243
244 static char* url_type_str[URL_TYPE_MAX] =
245 {
246         "NONE",
247         "HOME",
248         "WORK",
249 };
250
251 typedef enum
252 {
253         EVENT_BIRTHDAY = 0,
254         EVENT_ANNIVERSARY,
255         EVENT_TYPE_MAX
256 }event_type;
257
258 static char* event_type_str[EVENT_TYPE_MAX] =
259 {
260         "BIRTHDAY",
261         "ANNIVERSARY",
262 };
263
264 typedef enum
265 {
266         ADDRESS_TYPE_NONE               = 0x00000000,
267         ADDRESS_TYPE_HOME               = 0x00000001,
268         ADDRESS_TYPE_WORK               = 0x00000002,
269         ADDRESS_TYPE_DOM                = 0x00000004,
270         ADDRESS_TYPE_INTL               = 0x00000008,
271         ADDRESS_TYPE_POSTAL             = 0x00000010,
272         ADDRESS_TYPE_PARCEL     = 0x00000020,
273 }address_type;
274
275 static char* addr_type_str[MAX_ADDRESS_TYPE] =
276 {
277         "NONE",
278         "HOME",
279         "WORK",
280         "DOM",
281         "INTL",
282         "POSTAL",
283         "PARCEL",
284 };
285
286 static char* is_favorite_str[2] =
287 {
288         "FALSE",
289         "TRUE",
290 };
291
292 typedef enum
293 {
294         NORMAL_CASE = 0,
295         ONLY_CONTACT_ID_FIELD,
296 }projection_type;
297
298 typedef enum
299 {
300         INVALID_TABLE_LIST = 0,
301         ONLY_PERSON,
302         ONLY_CONTACT,
303         ONLY_DATA,
304         JOIN_PERSON_DATA,
305         JOIN_CONTACT_DATA,
306         ONLY_DATA_FROM_PERSON_QUERY,
307 //      JOIN_PERSON_CONTACT_DATA,
308 }target_table_e;
309
310 typedef enum
311 {
312         INVALID_TABLE = 0x00000000,
313         PERSON_TABLE = 0x00000001,
314         CONTACT_TABLE = 0x00000002,
315         DATA_TABLE = 0x00000004,
316 }tables_e;
317
318 typedef struct
319 {
320         char* contact_id;
321         char* is_self;
322         char* contact_id_for_name;
323         char* contact_id_for_photo;
324         char* contactid_for_ringtone;
325         char* prefix;
326         char* first_name;
327         char* middle_name;
328         char* last_name;
329         char* phonetic_name;
330         char* display_name;
331         char* photo_URI;
332         char* last_updated_timestamp;
333         char* is_favorite;
334         char* send_to_voicemail;
335         char* ringtone;
336 }person_contact_t;
337
338 typedef struct
339 {
340         char* contact_id;
341         char* ringtone;
342         char* note;
343         char* is_favorite;
344         char* photo_uri;
345         char* birth_day;
346         char* last_updated_time_stamp;
347         char* read_only;
348         char* send_to_voice_mail;
349         char* latitude;
350         char* longitude;
351         char* account_id;
352         char* uid;
353 }raw_contact_t;
354
355 typedef struct
356 {
357         char* first_name;
358         char* middle_name;
359         char* last_name;
360         char* prefix;
361         char* phonetic_name;
362         char* display_name;
363 }name_t;
364
365 typedef struct
366 {
367         char* nick_name;
368 }nick_name_t;
369
370 typedef struct
371 {
372         char* number;
373         char* number_type;
374         char* number_label; // not use
375 }number_t;
376
377 typedef struct
378 {
379         char* email_addr;
380         char* email_type;
381         char* email_label; // not use
382 }email_t;
383
384 typedef struct
385 {
386         char* url_addr;
387         char* url_type;
388         char* url_label; // not use
389 }url_t;
390
391 typedef struct
392 {
393         char* country;
394         char* region;
395         char* county;
396         char* city;
397         char* street;
398         char* postal_code;
399         char* addtional;
400         char* type;
401 }address_t;
402
403 typedef struct
404 {
405         char* organization_name;
406         char* department;
407         char* office;
408         char* title;
409         char* role;
410         char* logo_uri;
411 }organization_t;
412
413 typedef struct
414 {
415         char* type;
416         char* date;
417         char* label;
418 }event_info_t;
419
420 typedef struct
421 {
422         char* category;
423 }category_t;
424
425 typedef struct
426 {
427         int datatype_id;
428         char* data1;
429         char* data2;
430         char* data3;
431         char* data4;
432         char* data5;
433         char* data6;
434         char* data7;
435         char* data8;
436         char* data9;
437         char* data10;
438 }x_info_t;
439
440 typedef struct
441 {
442         person_contact_t* person_info;
443         raw_contact_t* raw_contact_info;
444         name_t* name_info;
445
446         GList* nickname_list;
447         GList* number_list;
448         GList* email_list;
449         GList* url_list;
450         GList* address_list;
451         GList* organization_list;
452         GList* event_list;
453         GList* category_list;
454         GList* x_list;
455
456         nick_name_t* nick_info;
457         number_t* num_info;
458         email_t* email_info;
459         url_t* url_info;
460         address_t* address_info;
461         organization_t* organization_info;
462         event_info_t* event_info;
463         x_info_t* x_info;
464
465         int get_name;
466         int get_raw_contact_info;
467         int get_person_info;
468 }contact_t;
469
470 typedef struct
471 {
472         int is_occupied;
473         contact_t* contact_info;
474 }result_t;
475
476 typedef struct
477 {
478         db_datatype datatype;
479         char* field;
480 }datatype_t;
481
482 typedef struct
483 {
484         char* field;
485 }projection_t;
486
487 typedef struct
488 {
489         int ordered_pos;
490 }ordering_list_t;
491
492 typedef struct
493 {
494         int contact_id;
495 }mapping_list_t;
496
497 typedef struct
498 {
499         contact_attribute_e attribute;
500         int int_value;
501         double real_value;
502         char* value;
503         int x_attribute;
504         int indices_filter;
505 }condition_val_t;
506
507 typedef struct
508 {
509         alias_key_e alias;
510         char* table;
511 }condition_table_t;
512
513 typedef struct
514 {
515         alias_key_e current_alias;
516         char* column_name;
517         char* condition;
518         db_datatype datatype;
519 }condition_list_t;
520
521 typedef struct
522 {
523         char* name;
524 }condition_category_t;
525
526
527 typedef struct
528 {
529         int group_id;
530         int contact_id;
531         char* name;
532         int sibling;
533 }categories_info;
534
535 typedef enum
536 {
537         INVALID_FIELDS = 0x00000000,
538         CATEGORIES = 0x00000001
539 }extra_contact_info;
540
541 typedef sqlite3_stmt* stmt;
542
543 typedef enum
544 {
545         INIT_FETCH = 0,
546         NEXT_ROW_FETCH,
547 }fetching_state;
548
549 typedef struct
550 {
551         query_type_e query_type;
552         stmt    hstmt;
553
554 // result set
555         int pos;                                //array index of ordering list
556         int is_optimized_query;
557
558 // query
559         predefine_datatype      assigned_datatype;
560         GList* datatype_list;
561
562         GList* projection;
563         GList* new_projection; //use making result set
564
565         GString* table_list;
566         tables_e query_table;
567         target_table_e join_table;
568
569         char* query_string;
570
571         result_t* result_set;
572         int old_contact_id;
573         mapping_list_t* mapping_id_to_result_set;
574
575         extra_contact_info extra_info;
576         categories_info* category;
577         int category_total_count;
578         int next_count;
579         int category_pos;
580         int attribute_list[ATTRIBUTE_MAX];
581         int x_attribute_list[X_DATA_MAX];
582
583 // especially for query to person
584         int person_field;
585
586 // set condition
587         GString* condition_text;
588         GString* use_normal_field_key;
589         GString* use_contact_table_id;
590         GList* condition_value;
591         alias_key_e current_alias;
592         predefine_datatype condition_datatype;
593         int optimize_condition;
594         GList* condition_list;
595         GList* condition_table_list;
596         char* condition_category;
597         char* condition_category_op;
598
599         extra_contact_info condition_extra_info;
600
601 // set order by
602         ordering_list_t* ordering_list;
603         GString* order;
604         contact_attribute_e order_field;
605         order_e ordering;
606         mapping_list_t* full_ordered_contact_id;
607         int total_count;
608
609 // set limit
610         int start_pos;
611         int window_size;
612         int limit_iter;
613
614 // the others
615         int total_result_set_count;
616         int return_array_pos;
617         predefine_datatype current_datatype;
618
619 // performance
620         predefine_datatype      all_datatype_in_query;
621
622 // x-attribute
623         fetching_state x_fetching;
624
625 // indices
626         GString* id_list;
627         int is_first_id_in_list;
628 }advanced_handle_t;
629
630 #ifdef __cplusplus
631 }
632 #endif /* __cplusplus */
633
634 #endif // _QUERY_TYPE_H
635