tizen_2.0_build
authorJeesun Kim <iamjs.kim@samsung.com>
Mon, 27 Aug 2012 08:20:10 +0000 (17:20 +0900)
committerJeesun Kim <iamjs.kim@samsung.com>
Mon, 27 Aug 2012 08:20:10 +0000 (17:20 +0900)
21 files changed:
debian/changelog
include/calendar-svc-provider.h
include/cals-internal.h
packaging/libslp-calendar.spec
schema/schema.sql
src/cals-alarm.c
src/cals-db.c
src/cals-db.h
src/cals-event.c
src/cals-ical.c
src/cals-instance.c
src/cals-provider.c
src/cals-schedule.c
src/cals-sqlite.c
src/cals-struct.c
src/cals-struct.h
src/cals-time.c
src/cals-time.h
src/cals-todo.c
src/cals-typedef.h
src/cals-utils.c

index 29dfc1f45c236e0147a405d50a29da9a45d79b5c..e605b1d918969520f638e076285e5c0e0d2fd5f1 100644 (file)
@@ -1,3 +1,43 @@
+libslp-calendar (0.1.13-41) unstable; urgency=low
+
+  * added calendar_id when updated list is returned.
+  * Git: magnolia/framework/pim/calendar-service
+  * Tag: libslp-calendar_0.1.13-41
+
+ -- Jeesun Kim <iamjs.kim@samsung.com>  Mon, 20 Aug 2012 20:08:46 +0900
+
+libslp-calendar (0.1.13-40) unstable; urgency=low
+
+  * Add vcalendar importing alarm, repeat for ver 1.
+  * Git: magnolia/framework/pim/calendar-service
+  * Tag: libslp-calendar_0.1.13-40
+
+ -- Jeesun Kim <iamjs.kim@samsung.com>  Mon, 20 Aug 2012 10:19:12 +0900
+
+libslp-calendar (0.1.13-39) unstable; urgency=low
+
+  * Add calendar ipc server/client
+  * Git: magnolia/framework/pim/calendar-service
+  * Tag: libslp-calendar_0.1.13-39
+
+ -- tw123.kim <tw123.kim@samsung.com>  Mon, 14 Aug 2012 17:27:13 +0900
+
+libslp-calendar (0.1.13-38) unstable; urgency=low
+
+  * fixed buffer overflow in smartsearch_excl api.
+  * Git: magnolia/framework/pim/calendar-service
+  * Tag: libslp-calendar_0.1.13-38
+
+ -- Jeesun Kim <iamjs.kim@samsung.com>  Mon, 13 Aug 2012 17:27:13 +0900
+
+libslp-calendar (0.1.13-37) unstable; urgency=low
+
+  * delete extra instance created by multi weekday set.
+  * Git: magnolia/framework/pim/calendar-service
+  * Tag: libslp-calendar_0.1.13-37
+
+ -- Jeesun Kim <iamjs.kim@samsung.com>  Wed, 08 Aug 2012 09:17:16 +0900
+
 libslp-calendar (0.1.13-36) unstable; urgency=low
 
   * fixed: s1-6347.
index a07d23f2169be142d6ec0af3b2f4866aa6dd750a..f83d8ff9e08e5ff8e31288f68f610834d3aa1e92 100755 (executable)
@@ -452,6 +452,7 @@ enum SEARCHFIELD {
 #define CALS_STRUCT_UPDATED_INT_VERSION "version"                /**< Version of schedule */
 #define CALS_STRUCT_UPDATED_INT_TYPE "updated_type"      /**< Type of schedule update #cals_updated_type */
 #define CALS_STRUCT_UPDATED_INT_ID "updated_id"      /**< id of updated schedule */
+#define CALS_STRUCT_UPDATED_INT_CALENDAR_ID "updated_calendar_id"      /**< id of updated schedule */
 /**
  * @}
  */
index cc12ee1e8fd1f774808c8257b8c7836baf268439..2e7bccca52672e9aae46488cced81f363f06ca0d 100755 (executable)
 
 //#define CALS_DEBUGGING
 #ifdef CALS_DEBUGGING
-#define CALS_FN_CALL DBG(">>>>>>>>%s called", __FUNCTION__)
-#define CALS_FN_END DBG("<<<<<<<<%s ended", __FUNCTION__)
-#define CALS_DBG(fmt, arg...) DBG("%d " fmt, __LINE__, ##arg)
+    #if defined(CALS_IPC_SERVER)
+    #define CALS_FN_CALL DBG("SERVER:>>>>>>>>%s called", __FUNCTION__)
+    #define CALS_FN_END DBG("SERVER:<<<<<<<<%s ended", __FUNCTION__)
+    #elif defined(CALS_IPC_CLIENT)
+    #define CALS_FN_CALL DBG("CLIENT:>>>>>>>>%s called", __FUNCTION__)
+    #define CALS_FN_END DBG("CLIENT:<<<<<<<<%s ended", __FUNCTION__)
+    #else
+    #define CALS_FN_CALL DBG(">>>>>>>>%s called", __FUNCTION__)
+    #define CALS_FN_END DBG("<<<<<<<<%s ended", __FUNCTION__)
+    #endif
+
+    #if defined(CALS_IPC_SERVER)
+    #define CALS_DBG(fmt, arg...) DBG("SERVER:%d " fmt, __LINE__, ##arg)
+    #elif defined(CALS_IPC_CLIENT)
+    #define CALS_DBG(fmt, arg...) DBG("CLIENT:%d " fmt, __LINE__, ##arg)
+    #else
+    #define CALS_DBG(fmt, arg...) DBG("%d " fmt, __LINE__, ##arg)
+    #endif
 #else /* CALS_DEBUGGING */
 #define CALS_FN_CALL
 #define CALS_FN_END
index c8841b60b7bfe8f5a7b77544006e36a526155afd..367f2f68caae89680e00876f46daeb238add86bd 100644 (file)
@@ -1,7 +1,7 @@
 Name:       libslp-calendar
 Summary:    DB library for calendar
 Version:    0.1.13
-Release:    36
+Release:    41
 Group:      System/Libraries
 License:    Apache 2.0
 Source0:    %{name}-%{version}.tar.gz
index 7f4ed7f9f75c3b24397d56214e7eaa7b67170fef..c307b2423dfaa871b6ad14603236db3f7df5fe3b 100755 (executable)
@@ -75,6 +75,16 @@ CREATE INDEX sch_idx1 ON schedule_table(type);
 CREATE TRIGGER trg_sch_del AFTER DELETE ON schedule_table
  BEGIN
    DELETE FROM alarm_table WHERE event_id = old.id;
+   DELETE FROM normal_instance_table WHERE event_id = (SELECT rowid FROM schedule_table WHERE original_event_id = old.id);
+   DELETE FROM allday_instance_table WHERE event_id = (SELECT rowid FROM schedule_table WHERE original_event_id = old.id);
+   DELETE FROM schedule_table WHERE original_event_id = old.id;
+ END;
+
+CREATE TRIGGER trig_original_mod AFTER UPDATE OF is_deleted ON schedule_table
+ BEGIN
+   DELETE FROM normal_instance_table WHERE event_id = (SELECT rowid FROM schedule_table WHERE original_event_id = old.id);
+   DELETE FROM allday_instance_table WHERE event_id = (SELECT rowid FROM schedule_table WHERE original_event_id = old.id);
+   UPDATE schedule_table SET is_deleted = 1 WHERE original_event_id = old.id;
  END;
 
 CREATE TABLE rrule_table
@@ -220,5 +230,5 @@ ver INTEGER PRIMARY KEY
 );
 INSERT INTO version_table VALUES(0);
 
-INSERT INTO calendar_table VALUES(0,0,0,0,'Default event calendar',0,0,'224.167.79.255',0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,-1,0,3);
-INSERT INTO calendar_table VALUES(0,0,0,0,'Default todo calendar',0,0,'224.167.79.255',0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,-1,0,3);
+INSERT INTO calendar_table VALUES(0,0,0,0,'Default event calendar',0,0,'224.167.79.255',0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,-1,0,1);
+INSERT INTO calendar_table VALUES(0,0,0,0,'Default todo calendar',0,0,'41.177.227.255',0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,-1,0,2);
index 11625412135f3c9af6484523c67a12b9913b49bd..bca858e3c7fd4e0987e5364581fdbf1141834e2c 100755 (executable)
@@ -31,6 +31,7 @@
 
 #define PKG_CALENDAR_APP "org.tizen.calendar"
 
+
 int cals_alarm_remove(int type, int related_id)
 {
        int ret;
index 5ab9c22eca1d1cf447443eb574a98d6476a2222e..5a897ff737d018d38b78581425a688b03d531e62 100755 (executable)
 #include "cals-schedule.h"
 #include "cals-db.h"
 
+#ifdef CALS_IPC_SERVER
+extern __thread sqlite3 *calendar_db_handle;
+#else
 extern sqlite3 *calendar_db_handle;
+#endif
 
 static bool __check_record_index_valid(int index)
 {
@@ -67,53 +71,124 @@ bool cal_db_service_free_participant(cal_participant_info_t* paritcipant_info, i
        return true;
 }
 
-bool cal_db_service_free_full_record(cal_sch_full_t *sch_full_record, int *error_code)
+int cals_db_free_alarm(cal_sch_full_t *record)
 {
-       retex_if(error_code == NULL, ,"error_code is NULL.");
-       retex_if(sch_full_record == NULL, *error_code = CAL_ERR_ARG_INVALID,"sch_full_record is NULL.");
-       cal_value *value = NULL;
-       GList *head;
-
-       CAL_FREE(sch_full_record->summary);
-       CAL_FREE(sch_full_record->description);
-       CAL_FREE(sch_full_record->location);
-       CAL_FREE(sch_full_record->categories);
-       CAL_FREE(sch_full_record->uid);
-       CAL_FREE(sch_full_record->organizer_name);
-       CAL_FREE(sch_full_record->organizer_email);
-       CAL_FREE(sch_full_record->gcal_id);
-       CAL_FREE(sch_full_record->updated);
-       CAL_FREE(sch_full_record->location_summary);
-       CAL_FREE(sch_full_record->etag);
-       CAL_FREE(sch_full_record->edit_uri);
-       CAL_FREE(sch_full_record->gevent_id);
-
-       if (sch_full_record->attendee_list)
-       {
-               head = sch_full_record->attendee_list;
-               while (sch_full_record->attendee_list)
-               {
-                       value = sch_full_record->attendee_list->data;
-                       if(NULL != value)
-                       {
-                               if(NULL != value->user_data)
-                               {
-                                       cal_db_service_free_participant((cal_participant_info_t*)value->user_data,error_code);
-                                       CAL_FREE(value->user_data);
-
-                               }
-                               CAL_FREE(value);
-                       }
-                       sch_full_record->attendee_list = sch_full_record->attendee_list->next;
+       CALS_FN_CALL;
+       GList *l;
+       cal_value *cv;
+       cal_alarm_info_t *ai;
+
+       if (record == NULL) {
+               ERR("Invalid argument: record is NULL");
+               return -1;
+       }
+
+       if (record->alarm_list == NULL) {
+               DBG("No alarm list to free");
+               return 0;
+       }
+
+       l = record->alarm_list;
+       while (l) {
+               cv = (cal_value *)l->data;
+               if (cv == NULL) {
+                       l = g_list_next(l);
+                       continue;
+               }
+
+               ai = (cal_alarm_info_t *)cv->user_data;
+               if (ai == NULL) {
+                       l = g_list_next(l);
+                       continue;
                }
-               g_list_free(head);
-               sch_full_record->attendee_list = NULL;
+
+               CAL_FREE(ai->alarm_tone);
+               CAL_FREE(ai->alarm_description);
+               CAL_FREE(ai);
+
+               CAL_FREE(cv);
+
+               l = g_list_next(l);
        }
-       return true;
+       g_list_free(record->alarm_list);
+       record->alarm_list = NULL;
 
-CATCH:
+       return 0;
+}
 
-       return false;
+int cals_db_free_attendee(cal_sch_full_t *record)
+{
+       CALS_FN_CALL;
+       GList *l;
+       cal_value *cv;
+       cal_participant_info_t *pi;
+
+       if (record == NULL) {
+               ERR("Invalid argument: record is NULL");
+               return -1;
+       }
+
+       if (record->attendee_list == NULL) {
+               DBG("No attendee list to free");
+               return 0;
+       }
+
+       l = record->attendee_list;
+       while (l) {
+               cv = (cal_value *)l->data;
+               if (cv == NULL) {
+                       l = g_list_next(l);
+                       continue;
+               }
+
+               pi = (cal_participant_info_t *)cv->user_data;
+               if (pi == NULL) {
+                       l = g_list_next(l);
+                       continue;
+               }
+
+               CAL_FREE(pi->attendee_email);
+               CAL_FREE(pi->attendee_number);
+               CAL_FREE(pi->attendee_name);
+               CAL_FREE(pi);
+
+               CAL_FREE(cv);
+
+               l = g_list_next(l);
+       }
+       g_list_free(record->attendee_list);
+       record->attendee_list = NULL;
+
+       return 0;
+}
+
+int cal_db_service_free_full_record(cal_sch_full_t *record)
+{
+       if (record == NULL) {
+               ERR("Invalid argument: record is NULL");
+               return -1;
+       }
+
+       CAL_FREE(record->dtstart_tzid);
+       CAL_FREE(record->dtend_tzid);
+       CAL_FREE(record->summary);
+       CAL_FREE(record->description);
+       CAL_FREE(record->location);
+       CAL_FREE(record->categories);
+       CAL_FREE(record->uid);
+       CAL_FREE(record->organizer_name);
+       CAL_FREE(record->organizer_email);
+       CAL_FREE(record->gcal_id);
+       CAL_FREE(record->updated);
+       CAL_FREE(record->location_summary);
+       CAL_FREE(record->etag);
+       CAL_FREE(record->edit_uri);
+       CAL_FREE(record->gevent_id);
+
+       cals_db_free_alarm(record);
+       cals_db_free_attendee(record);
+
+       return 0;
 }
 
 /************************************************************************************************
index 08cca5a179f50f3ae961169863e059e27f19ea8a..84e3cc288c9d9620bdb28e435a316c9906dd69cd 100755 (executable)
  *
  * @return             This function returns initialized record.
  * @param[in]  sch_full_record Points the field information for schedule table' s record.
- * @param[out] error_code      Points the error code.
  * @exception  CAL_ERR_ARG_INVALID.
  */
-bool cal_db_service_free_full_record(cal_sch_full_t *sch_full_record, int *error_code);
+int cal_db_service_free_full_record(cal_sch_full_t *sch_full_record);
 
 
 /**
index 3599f10aaf3da1843a16ed216e7965f36cf99f6e..52e4ba964e7461c09420d41d0445c08b222a169c 100755 (executable)
 #include "cals-schedule.h"
 #include "cals-time.h"
 
-
-int cals_event_init(cal_sch_full_t *sch_full_record)
-{
-       retvm_if(NULL == sch_full_record, CAL_ERR_ARG_INVALID , "sch_full_record is NULL");
-
-       memset(sch_full_record,0,sizeof(cal_sch_full_t));
-
-       sch_full_record->cal_type = CALS_SCH_TYPE_EVENT;
-       sch_full_record->meeting_status = CALS_EVENT_STATUS_NONE;
-       sch_full_record->calendar_id = DEFAULT_EVENT_CALENDAR_ID;
-
-       sch_full_record->index = CALS_INVALID_ID;
-       sch_full_record->timezone = -1;
-       sch_full_record->contact_id = CALS_INVALID_ID;
-       sch_full_record->calendar_type = CAL_PHONE_CALENDAR;
-       sch_full_record->attendee_list = NULL;
-       sch_full_record->busy_status = 2;
-       sch_full_record->summary = NULL;
-       sch_full_record->description = NULL;
-       sch_full_record->location= NULL;
-       sch_full_record->categories = NULL;
-       sch_full_record->exdate = NULL;
-       sch_full_record->organizer_email = NULL;
-       sch_full_record->organizer_name = NULL;
-       sch_full_record->uid= NULL;
-       sch_full_record->gcal_id = NULL;
-       sch_full_record->location_summary = NULL;
-       sch_full_record->etag = NULL;
-       sch_full_record->edit_uri = NULL;
-       sch_full_record->gevent_id = NULL;
-       sch_full_record->original_event_id = CALS_INVALID_ID;
-
-       sch_full_record->sync_status = CAL_SYNC_STATUS_NEW;
-       sch_full_record->account_id = -1;
-       sch_full_record->is_deleted = 0;
-       sch_full_record->latitude = 1000; // set default 1000 out of range(-180 ~ 180)
-       sch_full_record->longitude = 1000; // set default 1000 out of range(-180 ~ 180)
-       sch_full_record->freq = CALS_FREQ_ONCE;
-
-       return CAL_SUCCESS;
-}
-
 static inline void cals_event_make_condition(int calendar_id,
                time_t start_time, time_t end_time, int all_day, char *dest, int dest_size)
 {
@@ -173,10 +131,10 @@ static inline int cals_event_get_changes(int calendar_id, int version, cal_iter
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT id, changed_ver, created_ver, is_deleted FROM %s "
+                       "SELECT id, changed_ver, created_ver, is_deleted, calendar_id FROM %s "
                        "WHERE changed_ver > %d AND original_event_id = %d AND type = %d %s "
                        "UNION "
-                       "SELECT schedule_id, deleted_ver, -1, 1 FROM %s "
+                       "SELECT schedule_id, deleted_ver, -1, 1, calendar_id FROM %s "
                        "WHERE deleted_ver > %d AND schedule_type = %d %s ",
                        CALS_TABLE_SCHEDULE,
                        version, CALS_INVALID_ID, CALS_SCH_TYPE_EVENT, buf,
@@ -199,6 +157,7 @@ static inline int cals_event_get_changes(int calendar_id, int version, cal_iter
                } else {
                        result->type = CALS_UPDATED_TYPE_MODIFIED;
                }
+               result->calendar_id = sqlite3_column_int(stmt, 4);
 
                if (iter->info->head == NULL) {
                        iter->info->head = result;
@@ -555,14 +514,14 @@ API int calendar_svc_event_delete_normal_instance(int event_id, long long int dt
        } else {
                DBG("append exdate");
                len = strlen(exdate);
-               p = calloc(len + strlen(", ") + len_datetime + 1, sizeof(char));
+               p = calloc(len + strlen(",") + len_datetime + 1, sizeof(char));
                if (p == NULL) {
                        ERR("Failed to calloc");
                        sqlite3_finalize(stmt);
                        return CAL_ERR_OUT_OF_MEMORY;
                }
                str_datetime =  cals_time_get_str_datetime(NULL, dtstart_utime);
-               snprintf(p, len + 2 + len_datetime + 1, "%s, %s",
+               snprintf(p, len + strlen(",") + len_datetime + 1, "%s,%s",
                                exdate, str_datetime);
        }
        if (str_datetime) free(str_datetime);
@@ -654,13 +613,13 @@ API int calendar_svc_event_delete_allday_instance(int event_id, int dtstart_year
        } else {
                DBG("append exdate");
                len = strlen(exdate);
-               p = calloc(len + strlen(", ") + len_datetime + 1, sizeof(char));
+               p = calloc(len + strlen(",") + len_datetime + 1, sizeof(char));
                if (p == NULL) {
                        ERR("Failed to calloc");
                        sqlite3_finalize(stmt);
                        return CAL_ERR_OUT_OF_MEMORY;
                }
-               snprintf(p, len + 2 + len_datetime + 1, "%s, %s",
+               snprintf(p, len + strlen(",") + len_datetime + 1, "%s,%s",
                                exdate, buf);
        }
        sqlite3_finalize(stmt);
index a1bf9923ec2189048c474476e979808581fb0c32..7bad90aecb32c58707f2864930cea4cec587e4d0 100755 (executable)
@@ -121,10 +121,51 @@ int cals_func_summary(int ver, cal_sch_full_t *sch, void *data);
 int cals_func_transp(int ver, cal_sch_full_t *sch, void *data);
 int cals_func_url(int ver, cal_sch_full_t *sch, void *data);
 int cals_func_recurid(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_rrule(int ver, cal_sch_full_t *sch, void *data);
+int cals_func_rrule1(int ver, cal_sch_full_t *sch, void *data);
 int cals_func_dtend(int ver, cal_sch_full_t *sch, void *data);
 int cals_func_duration(int ver, cal_sch_full_t *sch, void *data);
 int cals_func_attach(int ver, cal_sch_full_t *sch, void *data);
+
+
+enum {
+       ATTENDEE_CUTYPE = 0x0,
+       ATTENDEE_MEMBER,
+       ATTENDEE_ROLE,
+       ATTENDEE_PARTSTAT,
+       ATTENDEE_RSVP,
+       ATTENDEE_DELTO,
+       ATTENDEE_DELFROM,
+       ATTENDEE_SENTBY,
+       ATTENDEE_CN,
+       ATTENDEE_DIR,
+       ATTENDEE_MAX,
+};
+
+int cals_func_attendee_cutype(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_member(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_role(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_partstat(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_rsvp(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_delto(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_delfrom(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_sentby(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_cn(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_dir(cal_sch_full_t *sch, void *data);
+
+struct _vala_func _attendee_list[ATTENDEE_MAX] =
+{
+       { "CUTYPE=", cals_func_attendee_cutype },
+       { "MEMBER=", cals_func_attendee_member },
+       { "ROLE=", cals_func_attendee_role },
+       { "PARTSTAT=", cals_func_attendee_partstat },
+       { "RSVP=", cals_func_attendee_rsvp },
+       { "DELTO=", cals_func_attendee_delto },
+       { "DELFROM=", cals_func_attendee_delfrom },
+       { "SENTBY=", cals_func_attendee_sentby },
+       { "CN=", cals_func_attendee_cn },
+       { "DIR=", cals_func_attendee_dir }
+};
+
 int cals_func_attendee(int ver, cal_sch_full_t *sch, void *data);
 int cals_func_categories(int ver, cal_sch_full_t *sch, void *data);
 int cals_func_comment(int ver, cal_sch_full_t *sch, void *data);
@@ -134,6 +175,7 @@ int cals_func_rstatus(int ver, cal_sch_full_t *sch, void *data);
 int cals_func_related(int ver, cal_sch_full_t *sch, void *data);
 int cals_func_resources(int ver, cal_sch_full_t *sch, void *data);
 int cals_func_rdate(int ver, cal_sch_full_t *sch, void *data);
+int cals_func_aalarm(int ver, cal_sch_full_t *sch, void *data);
 
 /* for vcalendar version 1.0 */
 int cals_ver1_func_rrule(cal_sch_full_t *sch, void *data);
@@ -160,7 +202,7 @@ enum {
        VEVE_DTEND,
 //     VEVE_DURATION,
 //     VEVE_ATTACH,
-//     VEVE_ATTENDEE,
+       VEVE_ATTENDEE,
        VEVE_CATEGORIES,
 //     VEVE_COMMENT,
 //     VEVE_CONTACT,
@@ -169,6 +211,7 @@ enum {
 //     VEVE_RELATED,
 //     VEVE_RESOURCES,
 //     VEVE_RDATE,
+       VEVE_AALARM,    /* for ver 1.0 */
        VEVE_MAX,
 };
 
@@ -191,12 +234,12 @@ struct _veve_func _veve_list[VEVE_MAX] =
 //     { "TRANSP", cals_func_transp },
 //     { "URL", cals_func_url },
 //     { "RECURID", cals_func_recurid },
-       { "RRULE", cals_func_rrule },
+       { "RRULE", cals_func_rrule1 },
        { "DTEND", cals_func_dtend },
 //     { "DURATION", cals_func_duration },
 //     { "ATTACH", cals_func_attach },
-//     { "ATTENDEE", cals_func_attendee },
-       { "CATEGORIES", cals_func_categories }//,
+       { "ATTENDEE", cals_func_attendee },
+       { "CATEGORIES", cals_func_categories },
 //     { "COMMENT", cals_func_comment },
 //     { "CONTACT", cals_func_contact },
 //     { "EXDATE", cals_func_exdate },
@@ -204,6 +247,7 @@ struct _veve_func _veve_list[VEVE_MAX] =
 //     { "RELATED", cals_func_related },
 //     { "RESOURCES", cals_func_resources },
 //     { "RDATE", cals_func_rdate }
+       { "AALARM", cals_func_aalarm }
 };
 
 int cals_func_action(cal_sch_full_t *sch, void *data);
@@ -288,8 +332,8 @@ struct _rrule_func _rrule_list[RRULE_MAX] =
        { "WKST=", cals_func_wkst }
 };
 
-int cals_func_related_trig(cal_sch_full_t *sch, void *data);
-int cals_func_value(cal_sch_full_t *sch, void *data);
+int cals_func_trig_related(cal_sch_full_t *sch, void *data);
+int cals_func_trig_value(cal_sch_full_t *sch, void *data);
 
 enum {
        TRIG_RELATED = 0x0,
@@ -299,8 +343,8 @@ enum {
 
 struct _vala_func _trig_list[TRIG_MAX] =
 {
-       { "RELATED=", cals_func_related_trig },
-       { "VALUE=", cals_func_value }
+       { "RELATED=", cals_func_trig_related },
+       { "VALUE=", cals_func_trig_value }
 };
 
 int cals_func_charset(int *val, void *data);
@@ -408,6 +452,7 @@ char cals_2hexa_to_1char(char *p)
 
 int cals_quoted_printable_decode(char *p, int *len)
 {
+       CALS_FN_CALL;
        int i = 0, j = 0;
        char ch;
 
@@ -636,7 +681,7 @@ API int calendar_svc_read_schedules(const char *stream, GList **schedules)
        *schedules = l;
        return ret;
 }
-
+#ifndef CALS_IPC_CLIENT
 int cals_do_importing(int calendar_id, char *stream, void *data)
 {
        int ret;
@@ -677,7 +722,7 @@ int cals_do_importing(int calendar_id, char *stream, void *data)
 
        return ret;
 }
-
+#endif
 static const char* cals_get_stream_from_path(const char *path)
 {
        FILE *file;
@@ -742,7 +787,7 @@ int calendar_svc_read_schedules_from_file(const char *path, GList **schedules)
        }
        return 0;
 }
-
+#ifndef CALS_IPC_CLIENT
 int cals_import_schedules(const char *path, int calendar_id)
 {
        FILE *file;
@@ -805,7 +850,7 @@ API int calendar_svc_calendar_import(const char *path, int calendar_id)
        ret = cals_import_schedules(path, calendar_id);
        return ret;
 }
-
+#endif
 
 
 // func ////////////////////////////////////////////////////////
@@ -1098,7 +1143,7 @@ int cals_func_dtstart(int ver, cal_sch_full_t *sch, void *data)
                p++;
                sch->dtstart_tzid = strdup(buf);
        } else {
-               sch->dtstart_tzid = strdup("Europe/London");
+               sch->dtstart_tzid = strdup(CALS_TZID_0);
        }
 
        if (!strncmp(p, "VALUE=", strlen("VALUE="))) {
@@ -1162,41 +1207,105 @@ int cals_func_created(int ver, cal_sch_full_t *sch, void *data)
        return 0;
 }
 
-int cals_func_description(int ver, cal_sch_full_t *sch, void *data)
+int _work_description_property(cal_sch_full_t *sch, char *buf)
 {
-       char *p = (char *)data;
-       int encoding = 0;
+       int i;
+       int ret = 0;
 
-       while (*p != '\n' && *p != '\r' && *p != '\0') {
-               if ( *p == ':') {
-                       p++;
-                       if (encoding == ENCODE_BASE64) {
-                               gsize len;
-                               sch->description = strdup((char *)g_base64_decode(p, &len));
+       for (i = 0; i < TEXT_MAX; i++) {
+               if (!strncmp(buf, _optional_list[i].prop, strlen(_optional_list[i].prop))) {
+                       _optional_list[i].func(&ret, buf);
+                       break;
+               }
+       }
+       return ret;
+}
 
-                       } else if (encoding == ENCODE_QUOTED_PRINTABLE) {
-                               if (ver == 1) {
-                                       int len;
-                                       cals_quoted_printable_decode(p, &len);
-                                       sch->description = strdup(p);
-                               } else {
-                                       CALS_DBG("only ver1.0 supports quoted printable\n");
-                                       sch->summary = strdup(p);
-                               }
+int _work_description_switch(int me, int mode, char *buf, int *charset, int *encoding)
+{
+       CALS_FN_CALL;
+       switch (mode) {
+       case 1:
+       case 2:
+               if (!strncmp(buf, "CHARSET=UTF-8", strlen("CHARSET=UTF-8"))) {
+                       DBG("CHARSET=UTF-8");
+                       *charset = 1;
+
+               } else if (!strncmp(buf, "CHARSET=UTF-16",
+                                       strlen("CHARSET=UTF-16"))) {
+                       DBG("CHARSET=UTF-16");
+                       *charset = 1;
+
+               } else if (!strncmp(buf, "ENCODING=BASE64",
+                                       strlen("ENCODING=BASE64"))) {
+                       DBG("ENCODE_BASE64");
+                       *encoding = ENCODE_BASE64;
+
+               } else if (!strncmp(buf, "ENCODING=QUOTED-PRINTABLE",
+                                       strlen("ENCODING=QUOTED-PRINTABLE"))) {
+                       DBG("ENCODE_QUOTED_PRINTABLE");
+                       *encoding = ENCODE_QUOTED_PRINTABLE;
 
-                       } else {
-                               sch->description = strdup(p);
+               } else {
 
-                       }
+               }
+               mode = 0;
+               break;
+       default:
+               mode = me;
+               break;
+       }
+       return mode;
+}
 
-               } else if (*p == ';') {
-                       p++;
-                       cals_get_optional_parameter(p, &encoding);
+int cals_func_description(int ver, cal_sch_full_t *sch, void *data)
+{
+       CALS_FN_CALL;
+       int i, j;
+       int len;
+       int out;
+       int mode;
+       int charset, encoding;
+       char buf[64] = {0};
+       char *p = (char *)data;
 
-               } else {
-                       p++;
+       i = j = 0;
+       out = 0;
+       mode = 0;
+       charset = encoding = 0;
+       while (p[i] != '\0') {
+               switch (p[i]) {
+               case ':':
+                       mode = 1;
+                       out = 1;
+                       break;
+
+               case ';':
+                       buf[j] = '\0';
+                       mode = _work_description_switch(2, mode, buf, &charset, &encoding);
+                       j = 0;
+                       break;
+
+               default:
+                       buf[j] = p[i];
+                       j++;
+                       break;
                }
+               i++;
+
+               if (out) {
+                       DBG("out");
+                       break;
+               }
+       }
+       _work_description_switch(0, mode, buf, &charset, &encoding);
+
+       DBG("charset(%d) encoding(%d)", charset, encoding);
+       if (encoding) {
+               cals_quoted_printable_decode(p+i, &len);
        }
+       sch->description = strdup(p+i);
+
        return 0;
 }
 
@@ -1309,39 +1418,51 @@ int cals_func_status(int ver, cal_sch_full_t *sch, void *data)
 
 int cals_func_summary(int ver, cal_sch_full_t *sch, void *data)
 {
+       CALS_FN_CALL;
+       int i, j;
+       int len;
+       int out;
+       int mode;
+       int charset, encoding;
+       char buf[64] = {0};
        char *p = (char *)data;
-       int encoding = 0;
 
-       while (*p != '\n' && *p != '\r' && *p != '\0') {
-               if ( *p == ':') {
-                       p++;
-                       if (encoding == ENCODE_BASE64) {
-                               gsize len;
-                               sch->summary = strdup((char *)g_base64_decode(p, &len));
-
-                       } else if (encoding == ENCODE_QUOTED_PRINTABLE) {
-                               if (ver == 1) {
-                                       int len;
-                                       cals_quoted_printable_decode(p, &len);
-                                       sch->summary = strdup(p);
-                               } else {
-                                       CALS_DBG("only ver1.0 supports quoted printable\n");
-                                       sch->summary = strdup(p);
-                               }
+       i = j = 0;
+       out = 0;
+       mode = 0;
+       charset = encoding = 0;
+       while (p[i] != '\0') {
+               switch (p[i]) {
+               case ':':
+                       mode = 1;
+                       out = 1;
+                       break;
 
-                       } else {
-                               sch->summary = strdup(p);
-                       }
+               case ';':
+                       buf[j] = '\0';
+                       mode = _work_description_switch(2, mode, buf, &charset, &encoding);
+                       j = 0;
                        break;
 
-               } else if (*p == ';') {
-                       p++;
-                       cals_get_optional_parameter(p, &encoding);
+               default:
+                       buf[j] = p[i];
+                       j++;
+                       break;
+               }
+               i++;
 
-               } else {
-                       p++;
+               if (out) {
+                       break;
                }
        }
+       _work_description_switch(0, mode, buf, &charset, &encoding);
+
+       DBG("charset(%d) encoding(%d)", charset, encoding);
+       if (encoding) {
+               cals_quoted_printable_decode(p+i, &len);
+       }
+       sch->summary = strdup(p+i);
+
        DBG("ver(%d)summary(%s)\n", ver, sch->summary);
 
        return 0;
@@ -1375,6 +1496,7 @@ int cals_func_rrule(int ver, cal_sch_full_t *sch, void *data)
 
                        switch (ver) {
                        case 1:
+                               DBG("version 2");
                                for (i = 0; i < RRULE_MAX; i++) {
                                        if (!strncmp(p, _rrule_list[i].prop, strlen(_rrule_list[i].prop))) {
                                                int j = 0;
@@ -1395,6 +1517,7 @@ int cals_func_rrule(int ver, cal_sch_full_t *sch, void *data)
                                break;
 
                        case 2:
+                               DBG("version 1");
                                /* Suppose vcalendar 1.0, if p == data */
                                if ((p - 1) == (char *)data) {
                                        cals_ver1_func_rrule(sch, p);
@@ -1409,6 +1532,214 @@ int cals_func_rrule(int ver, cal_sch_full_t *sch, void *data)
        return 0;
 }
 
+int cals_func_rrule1(int ver, cal_sch_full_t *sch, void *data)
+{
+       int i, j, k;
+       int mode;
+       int version = 0;
+       char buf[64] = {0};
+       char *p = (char *)data;
+
+       i = j = 0;
+       mode = 0;
+
+       if (strstr(p, "FREQ=")) {
+               DBG("This is version 2");
+               version = 2;
+       } else {
+               DBG("This is version 1");
+               version = 1;
+       }
+
+       if (version == 2) {
+               i = j = 0;
+               sch->interval = 1;
+               /* this is for ver 2 */
+               while (p[i] != '\0') {
+                       DBG("[%c](%d)", p[i], i);
+                       switch (p[i]) {
+                       case ':':
+                       case ';':
+                               DBG("%d", __LINE__);
+                               buf[j] = '\0';
+                               if (strlen(buf) < 1) {
+                                       break;
+                               }
+
+                               for (k = 0; k < RRULE_MAX; k++) {
+                                       if (!strncmp(buf, _rrule_list[k].prop, strlen(_rrule_list[k].prop))) {
+                                               _rrule_list[k].func(sch, buf + strlen(_rrule_list[k].prop));
+                                               break;
+                                       }
+                               }
+                               j = 0;
+                               break;
+
+                       default:
+                               DBG("%d", __LINE__);
+                               buf[j] = p[i];
+                               j++;
+                               break;
+                       }
+                       i++;
+               }
+
+               buf[j] = '\0';
+               for (i = 0; i < RRULE_MAX; i++) {
+                       if (!strncmp(buf, _rrule_list[i].prop, strlen(_rrule_list[i].prop))) {
+                               version = 2;
+                               _rrule_list[i].func(sch, buf + strlen(_rrule_list[i].prop));
+                               break;
+                       }
+               }
+               return 0;
+       }
+
+       /* this is for ver 1 */
+       int interval;
+       int out = 0;
+       char by[64] = {0};
+       char _by[64] = {0};
+       char date[8] = {0};
+       int tmp;
+       int is_wday = 0;
+       int y, mon, d, h, min, s;
+       char t, z;
+       i = 0;
+       mode = 0;
+       interval = 0;
+       while (p[i] != '\0') {
+               switch (p[i]) {
+               case ':':
+               case ' ':
+                       if (mode == 0) {
+                               DBG("in mode 1");
+                               mode = 1;
+
+                       } else if (mode == 1) {
+                               DBG("in mode 2");
+                               mode = 2;
+                               buf[j] = '\0';
+                               if (buf[0] == 'D') {
+                                       sch->freq = CALS_FREQ_DAILY;
+
+                               } else if (buf[0] == 'W') {
+                                       sch->freq = CALS_FREQ_WEEKLY;
+
+                               } else if (buf[0] == 'M') {
+                                       sch->freq = CALS_FREQ_MONTHLY;
+
+                               } else if (buf[0] == 'Y') {
+                                       sch->freq = CALS_FREQ_YEARLY;
+
+                               } else {
+                                       sch->freq = CALS_FREQ_ONCE;
+
+                               }
+
+                               if (buf[1] >= '1' && buf[1] <= '9') {
+                                       sch->interval = atoi(&buf[1]);
+                               } else {
+                                       sch->interval = atoi(&buf[2]);
+                               }
+
+                       } else {
+                               mode = 3;
+                               DBG("in mode 3");
+                               buf[j] = '\0';
+                               if (buf[0] == '#' || strlen(buf) > strlen("YYYYMMDDTHHMMSS")) {
+                                       DBG("end statement[%s]", buf);
+                                       switch (sch->freq) {
+                                       case CALS_FREQ_YEARLY:
+                                               sch->bymonth = strdup(by);
+
+                                               tmp = cals_time_get_val_datetime(sch->dtstart_tzid,
+                                                               sch->dtstart_utime, "mday", &tmp);
+                                               snprintf(date, sizeof(date), "%d", tmp);
+                                               sch->bymonthday = strdup(date);
+
+                                               break;
+
+                                       case CALS_FREQ_MONTHLY:
+                                               tmp = cals_time_get_val_datetime(sch->dtstart_tzid,
+                                                               sch->dtstart_utime, "month", &tmp);
+                                               snprintf(date, sizeof(date), "%d", tmp);
+                                               sch->bymonth = strdup(date);
+
+                                               if (is_wday) {
+                                                       sch->byday = strdup(by);
+                                               } else {
+                                                       sch->bymonthday = strdup(by);
+                                               }
+                                               break;
+
+                                       case CALS_FREQ_WEEKLY:
+                                               sch->byday = strdup(by);
+                                               break;
+
+                                       case CALS_FREQ_DAILY:
+                                               sch->byday = strdup(by);
+                                               break;
+                                       }
+                                       out = 1;
+                                       break;
+                               }
+
+                               DBG("len(%d)", strlen(by));
+                               if (strlen(by) < 1) {
+                                       DBG("ret(%d)", atoi(buf));
+                                       if (buf[0] >= '1' && buf[0] <= '9') {
+                                               DBG("Set digit");
+                                               is_wday = 0;
+                                       } else {
+                                               DBG("Set wday [%s]", buf);
+                                               is_wday = 1;
+                                       }
+                                       DBG("[%s][%s]", by, buf);
+                                       snprintf(_by, sizeof(by), "%s", buf);
+
+                               } else {
+                                       DBG("[%s][%s]", by, buf);
+                                       snprintf(_by, sizeof(by), "%s %s", by, buf);
+                               }
+                               memcpy(by, _by, sizeof(_by));
+                       }
+                       j = 0;
+                       break;
+
+               default:
+                       buf[j] = p[i];
+                       j++;
+                       break;
+               }
+               i++;
+
+               if (out) {
+                       break;
+               }
+       }
+
+       DBG("freq(%d) interval(%d) by[%s]", sch->freq, sch->interval, by);
+
+       if (buf[0] == '#') {
+               DBG("until count");
+               sch->range_type = CALS_RANGE_COUNT;
+               sch->count = atoi(&buf[1]);
+
+       } else {
+               DBG("until time");
+               sch->range_type = CALS_RANGE_UNTIL;
+               sch->until_type = CALS_TIME_UTIME;
+               sscanf(buf, "%4d%2d%2d%c%2d%2d%2d%c",
+                               &y, &mon, &d, &t, &h, &min, &s, &z);
+               sch->until_utime = cals_time_date_to_utime(sch->dtstart_tzid,
+                               y, mon, d, h, min, s);
+
+       }
+
+       return 0;
+}
+
 int cals_func_dtend(int ver, cal_sch_full_t *sch, void *data)
 {
        char *p = (char *)data;
@@ -1434,7 +1765,7 @@ int cals_func_dtend(int ver, cal_sch_full_t *sch, void *data)
                p++;
                sch->dtend_tzid = strdup(buf);
        } else {
-               sch->dtend_tzid = strdup("Europe/London");
+               sch->dtend_tzid = strdup(CALS_TZID_0);
        }
 
        if (!strncmp(p, "VALUE=", strlen("VALUE="))) {
@@ -1489,11 +1820,185 @@ int cals_func_attach(int ver, cal_sch_full_t *sch, void *data)
        return 0;
 }
 
+/////////////////////////////////////////////////////////////////
+int cals_func_attendee_cutype(cal_sch_full_t *sch, void *data)
+{
+       return 0;
+}
+
+int cals_func_attendee_member(cal_sch_full_t *sch, void *data)
+{
+       return 0;
+}
+
+int cals_func_attendee_role(cal_sch_full_t *sch, void *data)
+{
+       return 0;
+}
+
+int cals_func_attendee_partstat(cal_sch_full_t *sch, void *data)
+{
+       return 0;
+}
+
+int cals_func_attendee_rsvp(cal_sch_full_t *sch, void *data)
+{
+       return 0;
+}
+
+int cals_func_attendee_delto(cal_sch_full_t *sch, void *data)
+{
+       return 0;
+}
+
+int cals_func_attendee_delfrom(cal_sch_full_t *sch, void *data)
+{
+       return 0;
+}
+
+int cals_func_attendee_sentby(cal_sch_full_t *sch, void *data)
+{
+       return 0;
+}
+
+int cals_func_attendee_cn(cal_sch_full_t *sch, void *data)
+{
+       CALS_FN_CALL;
+       int i = 0;
+       char *text;
+       char *p = (char *)data;
+       GList *l;
+       cal_value *cv;
+       cal_participant_info_t *pi;
+
+       l = g_list_last(sch->attendee_list);
+       if (l == NULL) {
+               ERR("Failed to get attendee last");
+               return -1;
+       }
+
+       cv = (cal_value *)l->data;
+       pi = (cal_participant_info_t *)cv->user_data;
+
+       while (*p != ':' && *p != '\n' && *p != '\r' && *p != '\0') {
+               i++;
+               p++;
+       }
+
+       text = calloc(i + 1, sizeof(char));
+       if (text == NULL) {
+               ERR("Failed to calloc");
+               return -1;
+       }
+       snprintf(text, i + 1, "%s", (char *)data);
+
+       pi->attendee_name = text;
+       DBG("cn[%s]", text);
+
+       return 0;
+}
+
+int cals_func_attendee_dir(cal_sch_full_t *sch, void *data)
+{
+       CALS_FN_CALL;
+       return 0;
+}
+
+int _work_attendee_mailto(cal_sch_full_t *sch, char *buf)
+{
+       CALS_FN_CALL;
+       return 0;
+}
+
+int _work_attendee_property(cal_sch_full_t *sch, char *buf)
+{
+       CALS_FN_CALL;
+       int i;
+       int len_all, len_prop;
+
+       for (i = 0; i < ATTENDEE_MAX; i++) {
+               if (!strncmp(buf, _attendee_list[i].prop, strlen(_attendee_list[i].prop))) {
+                       len_all = strlen(buf);
+                       len_prop = strlen(_attendee_list[i].prop);
+                       snprintf(buf, len_all - len_prop + 1, "%s", &buf[len_prop]);
+                       _attendee_list[i].func(sch, buf);
+                       break;
+               }
+       }
+       return 0;
+}
+
 int cals_func_attendee(int ver, cal_sch_full_t *sch, void *data)
 {
+       CALS_FN_CALL;
+       int i, j;
+       char *p = (char *)data;
+       cal_value *val;
+
+       val = calendar_svc_value_new(CAL_VALUE_LST_ATTENDEE_LIST);
+       if (val == NULL) {
+               ERR("Failed to new value attendee");
+               return -1;
+       }
+
+       sch->attendee_list = g_list_append(sch->attendee_list, val);
+
+       i = 0;
+       j = 0;
+       int mode = 0;
+       char buf[64] = {0};
+
+       while (p[i] != '\0') {
+               switch (p[i]) {
+               case ':':
+                       /* work mail to */
+                       if (mode) {
+                               buf[j] = '\0';
+                               _work_attendee_mailto(sch, buf);
+                               mode = 0;
+                       } else {
+                               mode = 1;
+                       }
+                       j = 0;
+                       break;
+
+               case ';':
+                       /* work property */
+                       if (mode) {
+                               buf[j] = '\0';
+                               _work_attendee_property(sch, buf);
+                               mode = 0;
+                       } else {
+                               mode = 2;
+                       }
+                       j = 0;
+                       break;
+
+               default:
+                       buf[j] = p[i];
+                       j++;
+                       break;
+               }
+               i++;
+       }
+
+       switch (mode) {
+       case 1:
+               buf[j] = '\0';
+               _work_attendee_mailto(sch, buf);
+               break;
+       case 2:
+               buf[j] = '\0';
+               _work_attendee_property(sch, buf);
+               break;
+       default:
+               break;
+       }
+
        return 0;
 }
 
+
 int cals_func_categories(int ver, cal_sch_full_t *sch, void *data)
 {
        CALS_FN_CALL;
@@ -1535,6 +2040,7 @@ int cals_func_categories(int ver, cal_sch_full_t *sch, void *data)
        return 0;
 }
 
+
 int cals_func_comment(int ver, cal_sch_full_t *sch, void *data)
 {
        return 0;
@@ -1570,6 +2076,127 @@ int cals_func_rdate(int ver, cal_sch_full_t *sch, void *data)
        return 0;
 }
 
+/* for ver 1.0 */
+
+int _work_aalarm_time(cal_sch_full_t *sch, void *data)
+{
+       CALS_FN_CALL;
+       int y, mon, d, h, min, s;
+       long long int lli_a;
+       char t, z;
+       char *p = (char *)data;
+       cal_value *cv;
+       cal_alarm_info_t *al = NULL;
+
+       if (p == NULL) {
+               ERR("Invalid argument");
+               return -1;
+       }
+
+       y = mon = d = h = min = s = 0;
+       sscanf(p, "%04d%02d%02d%c%02d%02d%02d%c",
+                       &y, &mon, &d, &t, &h, &min, &s, &z);
+
+       lli_a = cals_time_date_to_utime(sch->dtstart_tzid, y, mon, d, h, min, s);
+
+       cv = calendar_svc_value_new(CAL_VALUE_LST_ALARM);
+       if (cv == NULL) {
+               ERR("Failed to new value");
+               return -1;
+       }
+       sch->alarm_list = g_list_append(sch->alarm_list, cv);
+
+       al = (cal_alarm_info_t *)cv->user_data;
+       al->remind_tick_unit = CAL_SCH_TIME_UNIT_SPECIFIC;
+       al->alarm_time = lli_a;
+
+       /* work extra */
+       int lli_d;
+       lli_d = sch->dtstart_utime - lli_a;
+       if (lli_d < 60 * 60) {
+               al->remind_tick_unit = CAL_SCH_TIME_UNIT_MIN;
+               al->remind_tick = lli_d / (60);
+
+       } else if (lli_d < 60 * 60 * 24) {
+               al->remind_tick_unit = CAL_SCH_TIME_UNIT_HOUR;
+               al->remind_tick = lli_d / (60 * 60);
+
+       } else if (lli_d < 60 * 60 * 24 * 31) {
+               al->remind_tick_unit = CAL_SCH_TIME_UNIT_DAY;
+               al->remind_tick = lli_d / (60 * 60 * 24);
+
+       } else {
+               al->remind_tick_unit = CAL_SCH_TIME_UNIT_WEEK;
+               al->remind_tick = lli_d / (60 * 60 * 24 * 31);
+
+       }
+       DBG("tick(%d) unit(%d)", al->remind_tick, al->remind_tick_unit);
+       return 0;
+}
+
+int _work_aalarm_property(cal_sch_full_t *sch, void *data)
+{
+       return 0;
+}
+
+int _work_aalarm_switch(int mode, int me, cal_sch_full_t *sch, char *buf)
+{
+       CALS_FN_CALL;
+       switch (mode) {
+       case 1:
+               _work_aalarm_time(sch, buf);
+               mode = 0;
+               break;
+       case 2:
+               _work_aalarm_property(sch, buf);
+               mode = 0;
+               break;
+       default:
+               mode = me;
+               break;
+       }
+       return mode;
+}
+
+int cals_func_aalarm(int ver, cal_sch_full_t *sch, void *data)
+{
+       CALS_FN_CALL;
+       int i, j;
+       int mode = 0;
+       char buf[64] = {0};
+       char *p = (char *)data;
+
+       i = 0;
+       j = 0;
+       while (p[i] != '\0') {
+               switch (p[i]) {
+               case ':':
+                       buf[j] = '\0';
+                       mode = _work_aalarm_switch(mode, 1, sch, buf);
+                       j = 0;
+                       break;
+
+               case ';':
+                       buf[j] = '\0';
+                       mode = _work_aalarm_switch(mode, 2, sch, buf);
+                       j = 0;
+                       break;
+
+               default:
+                       buf[j] = p[i];
+                       j++;
+                       break;
+               }
+               i++;
+       }
+
+       _work_aalarm_switch(mode, 0, sch, buf);
+
+       return 0;
+}
+/* end */
+
+
 enum {
        WEEKNAME2_SA = 0x0,
        WEEKNAME2_FR,
@@ -1585,6 +2212,7 @@ const char weekname2[WEEKNAME2_MAX][3] = {"SA", "FR", "TH", "WE", "TU", "MO", "S
 /* for vcalendar version 1.0 */
 int cals_ver1_func_rrule(cal_sch_full_t *sch, void *data)
 {
+       CALS_FN_CALL;
        char *p = (char *)data;
        int i = 0, j = 0;
        int column = 0, loop = 1;
@@ -1782,9 +2410,9 @@ char *cals_convert_sec_from_duration(char *p, int *dur_t, char *dur)
 int cals_func_trigger(cal_sch_full_t *sch, void *data)
 {
        int i = 0, out = 0;
+
        char *p = (char *)data;
        long long int dtstart_utime;
-       int dur_t;
        cal_value *val;
        cal_alarm_info_t *alarm;
        GList *l;
@@ -1822,8 +2450,7 @@ int cals_func_trigger(cal_sch_full_t *sch, void *data)
                if (out == 1) {
                        break;
                }
-               p = cals_convert_sec_from_duration(p, &dur_t, NULL);
-               alarm->alarm_time = dtstart_utime + (long long int)dur_t;
+               cals_func_trig_related(sch, p);
                break;
        }
        return 0;
@@ -2100,15 +2727,181 @@ int cals_func_wkst(cal_sch_full_t *sch, void *data)
        return 0;
 }
 
-int cals_func_related_trig(cal_sch_full_t *sch, void *data)
+int _get_tick_unit(char *p, int *tick, int *unit)
+{
+       int d, c, i; /* direct, const, i */
+       int t, u; /* tick, unit */
+       char buf[8] = {0};
+
+       t = 0;
+       c = 0;
+       u = CAL_SCH_TIME_UNIT_OFF;
+       while (*p != '\0' && *p != '\n') {
+               switch (*p) {
+               case '+':
+                       d = 1;
+                       break;
+               case '-':
+                       d = -1;
+                       break;
+               case 'P':
+                       i = 0;
+                       break;
+               case 'T':
+                       break;
+               case 'W':
+                       c = atoi(buf);
+                       DBG("W tick(%d)", c);
+                       if (c == 0) break;
+                       u = CAL_SCH_TIME_UNIT_WEEK;
+                       t += c;
+                       i = 0;
+                       break;
+               case 'D':
+                       c = atoi(buf);
+                       DBG("D tick(%d)", c);
+                       if (c == 0) break;
+                       u = CAL_SCH_TIME_UNIT_DAY;
+                       t += c;
+                       i = 0;
+                       break;
+               case 'H':
+                       c = atoi(buf);
+                       DBG("H tick(%d)", c);
+                       if (c == 0) break;
+                       u = CAL_SCH_TIME_UNIT_HOUR;
+                       t += c;
+                       i = 0;
+                       break;
+               case 'M':
+                       c = atoi(buf);
+                       DBG("M tick(%d)", c);
+                       if (c == 0) break;
+                       u = CAL_SCH_TIME_UNIT_MIN;
+                       t += c;
+                       i = 0;
+                       break;
+               case 'S':
+                       i = 0;
+                       break;
+               default:
+                       buf[i] = *p;
+                       i++;
+                       break;
+               }
+               p++;
+       }
+       if (t != c) {
+               u = CAL_SCH_TIME_UNIT_SPECIFIC;
+       }
+       *tick = t;
+       *unit = u;
+       DBG("get tic(%d) unit(%d)", t, u);
+
+       return 0;
+}
+
+int cals_func_trig_related(cal_sch_full_t *sch, void *data)
 {
        CALS_DBG("%s\n", (char *)data);
+
+       int tick, unit;
+       char *p = (char *)data;
+       GList *l;
+       cal_value *cv;
+       cal_alarm_info_t *al = NULL;
+
+       if (p == NULL) {
+               return -1;
+       }
+
+       l = g_list_last(sch->alarm_list);
+       if (l == NULL) {
+               DBG("Faield to get list from alarm list");
+               return 0;
+       }
+
+       cv = (cal_value *)l->data;
+       if (cv == NULL) {
+               ERR("Failed to get cal value");
+               return -1;
+       }
+       al = (cal_alarm_info_t *)cv->user_data;
+       if (al == NULL) {
+               ERR("Failed to get alarm info");
+               return -1;
+       }
+
+       if (!strncmp(p, "START", strlen("START") + 1)) {
+               p += strlen("START") + 1;
+               DBG("related start and value[%s]", p);
+               _get_tick_unit(p, &tick, &unit);
+               al->remind_tick = tick;
+               al->remind_tick_unit = unit;
+
+       } else if (!strncmp(p, "END", strlen("END") +1)) {
+               p += strlen("END") + 1;
+               DBG("related end and value[%s]", p);
+               _get_tick_unit(p, &tick, &unit);
+               al->remind_tick = tick;
+               al->remind_tick_unit = unit;
+
+       } else {
+               DBG("no related and value[%s]", p);
+               _get_tick_unit(p, &tick, &unit);
+               al->remind_tick = tick;
+               al->remind_tick_unit = unit;
+
+       }
+
        return 0;
 }
 
-int cals_func_value(cal_sch_full_t *sch, void *data)
+long long int _get_utime_from_datetime(char *tzid, char *p)
+{
+       int y, mon, d, h, min, s;
+       int len;
+       char t, z;
+       if (p == NULL) {
+               return -1;
+       }
+       len = strlen(p);
+       if (len < strlen("YYYYMMDDTHHMMSS")) {
+               return -1;
+       }
+
+       sscanf(p, "%04d%02d%02d%c%02d%02d%02d%c",
+                       &y, &mon, &d, &t, &h, &min, &s, &z);
+
+       return cals_time_date_to_utime(tzid, y, mon, d, h, min, s);
+}
+
+int cals_func_trig_value(cal_sch_full_t *sch, void *data)
 {
        CALS_DBG("%s\n", (char *)data);
+
+       char *p = (char *)data;
+       GList *l;
+       cal_value *cv;
+       cal_alarm_info_t *al = NULL;
+
+       l = g_list_last(sch->alarm_list);
+       if (l == NULL) {
+               DBG("No alarm");
+               return 0;
+       }
+
+       cv = (cal_value *)l->data;
+       al = (cal_alarm_info_t *)cv->user_data;
+
+       if (!strncmp(p, "DATE-TIME", strlen("DATE-TIME") + 1)) {
+               p += strlen("DATE-TIME") + 1;
+               al->remind_tick_unit = CAL_SCH_TIME_UNIT_SPECIFIC;
+               al->alarm_time = _get_utime_from_datetime(sch->dtstart_tzid, p);
+       } else {
+
+       }
+
        return 0;
 }
 
@@ -2124,9 +2917,11 @@ int cals_func_encoding(int *val, void *data)
        *val = 0;
 
        if (!strncmp(p, "BASE64", strlen("BASE64"))) {
+               DBG("ENCODE_BASE64");
                *val = ENCODE_BASE64;
 
        } else if (!strncmp(p, "QUOTED-PRINTABLE", strlen("QUOTED-PRINTABLE"))){
+               DBG("ENCODE_QUOTED_PRINTABLE");
                *val = ENCODE_QUOTED_PRINTABLE;
 
        }
@@ -2711,7 +3506,7 @@ API int calendar_svc_write_schedules(GList *schedules, char **stream)
        return CAL_SUCCESS;
 }
 
-
+#ifndef CALS_IPC_CLIENT
 API int calendar_svc_calendar_export(int calendar_id, const char *path)
 {
        int fd, r;
@@ -2797,3 +3592,4 @@ API int calendar_svc_calendar_export(int calendar_id, const char *path)
 
        return CAL_SUCCESS;
 }
+#endif
index 54e01f967b5ca351f223511e291f64b473679dd8..9537412ff906085f5c1b0e82e556e0b216be72c5 100644 (file)
@@ -101,7 +101,7 @@ static int months[] = {
        [CALS_DECEMBER] = UCAL_DECEMBER,
 };
 
-static struct day days[] = {
+static struct day wdays[] = {
        [CALS_SUNDAY] = {UCAL_SUNDAY, "SU"},
        [CALS_MONDAY] = {UCAL_MONDAY, "MO"},
        [CALS_TUESDAY] = {UCAL_TUESDAY, "TU"},
@@ -137,7 +137,7 @@ static UCalendar *_ucal_get_cal(const char *tzid, int wkst)
        }
 
        if (wkst >= CALS_SUNDAY && wkst <= CALS_SATURDAY)
-               ucal_setAttribute(cal, UCAL_FIRST_DAY_OF_WEEK, days[wkst].uday);
+               ucal_setAttribute(cal, UCAL_FIRST_DAY_OF_WEEK, wdays[wkst].uday);
 
        return cal;
 }
@@ -174,30 +174,28 @@ static inline void _ucal_set_month(UCalendar *cal, int month)
        ucal_set(cal, UCAL_MONTH, months[month]);
 }
 
-static inline void _ucal_set_day(UCalendar *cal, int day)
-{
-       int woy; /* week of year */
-       int date, date_new; /* date */
-       UErrorCode status = U_ZERO_ERROR;
 
-       if (day == CALS_NODAY)
+static inline void _ucal_set_wday(UCalendar *cal, int wday)
+{
+       if (wday == CALS_NODAY) {
+               DBG("this is wday repeat, so pass this shift");
                return;
-       woy = ucal_get(cal, UCAL_WEEK_OF_YEAR, &status);
-       date = ucal_get(cal, UCAL_DATE, &status);
-       ucal_set(cal, UCAL_DAY_OF_WEEK, days[day].uday);
-       ucal_set(cal, UCAL_WEEK_OF_YEAR, woy);
-       date_new = ucal_get(cal, UCAL_DATE, &status);
-       DBG("date old(%d) new(%d)", date, date_new);
-       if (date_new < date) {
-               ucal_add(cal, UCAL_DATE, 7, &status);
        }
+       ucal_set(cal, UCAL_DAY_OF_WEEK, wdays[wday].uday);
 }
 
-static inline void _ucal_set_week(UCalendar *cal, int week)
+static inline void _ucal_set_week(UCalendar *cal, int week, cal_sch_full_t *sch)
 {
        if (!week)
                return;
-       ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, week);
+
+       switch (inst_info[sch->freq].f) {
+       case UCAL_WEEK_OF_YEAR:
+               return;
+       default:
+               ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, week);
+               break;
+       }
 }
 
 static void _ucal_get_instance(UCalendar *cal,
@@ -232,13 +230,22 @@ static inline int _is_after(struct cals_time *t1, struct cals_time *t2)
        DBG("%d %d %d /%d %d %d", t1->year, t1->month, t1->mday,
                        t2->year, t2->month, t2->mday);
        if (t1->year > t2->year) {
+               DBG("exit year");
                return 1;
-       } else if (t1->month > t2->month) {
-               return 1;
-       } else if (t1->mday > t2->mday) {
-               return 1;
-       } else {
+       } else if (t1->year < t2->year) {
                return 0;
+       } else {
+               if (t1->month > t2->month) {
+                       return 1;
+               } else if (t1->month < t2->month) {
+                       return 0;
+               } else {
+                       if (t1->mday > t2->mday) {
+                               return 1;
+                       } else {
+                               return 0;
+                       }
+               }
        }
 }
 
@@ -308,15 +315,117 @@ int _ucal_del_inundant(int event_id, struct cals_time *st, cal_sch_full_t *sch)
        return 0;
 }
 
+int _shift_to_valid_mday(UCalendar *cal, int mday, int wday, cal_sch_full_t *sch)
+{
+       CALS_FN_CALL;
+       int y, m, d, month;
+       UErrorCode status = U_ZERO_ERROR;
+
+       if (wday != CALS_NODAY) {
+               DBG("this is wday repeat, so pass this shift");
+               return 0;
+       }
+
+       DBG("mday(%d)wday%d)", mday, wday);
+       switch (inst_info[sch->freq].f) {
+       case UCAL_YEAR:
+               month = ucal_get(cal, UCAL_MONTH, &status);
+               d = ucal_get(cal, UCAL_DATE, &status);
+               while (d != mday && y < 9999 ) {
+                       ucal_add(cal, inst_info[sch->freq].f, sch->interval, &status);
+                       ucal_set(cal, UCAL_MONTH, month);
+                       ucal_set(cal, UCAL_DATE, mday);
+                       y = ucal_get(cal, UCAL_YEAR, &status);
+                       m = ucal_get(cal, UCAL_MONTH, &status);
+                       d = ucal_get(cal, UCAL_DATE, &status);
+               }
+               break;
+
+       case UCAL_MONTH:
+               d = ucal_get(cal, UCAL_DATE, &status);
+               while (d != mday && y < 9999 ) {
+                       ucal_set(cal, UCAL_DATE, mday);
+                       y = ucal_get(cal, UCAL_YEAR, &status);
+                       m = ucal_get(cal, UCAL_MONTH, &status);
+                       d = ucal_get(cal, UCAL_DATE, &status);
+               }
+               break;
+       default:
+               break;
+       }
+       DBG("shift to %04d/%02d/%02d and should be same %02d date", y, m, d, mday);
+       return 0;
+}
+
+int _shift_to_valid_wday(UCalendar *cal, int year, int month, int mday, int wday, int week, cal_sch_full_t *sch)
+{
+       CALS_FN_CALL;
+       int y, m, d; /* date */
+       UErrorCode status = U_ZERO_ERROR;
+
+       if (!week)
+               return 0;
+
+       y = ucal_get(cal, UCAL_YEAR, &status);
+       m = ucal_get(cal, UCAL_MONTH, &status) + 1;
+       d = ucal_get(cal, UCAL_DATE, &status);
+       DBG(" got next mday(%d) origin mday(%d)", d, mday);
+
+       switch (inst_info[sch->freq].f) {
+       case UCAL_YEAR:
+               if (y <= year && m <= month && d < mday) {
+                       DBG("less than start date");
+                       ucal_add(cal, UCAL_YEAR, 1, &status);
+               } else if (m < month) {
+                       DBG("mismatched month");
+                       ucal_add(cal, UCAL_MONTH, 1, &status);
+               }
+               _ucal_set_wday(cal, wday);
+               _ucal_set_week(cal, week, sch);
+               break;
+
+       case UCAL_MONTH:
+               if ((m <= month && d < mday) || (m < month)) {
+                       DBG(" so, added 1 week");
+                       ucal_add(cal, UCAL_MONTH, 1, &status);
+                       _ucal_set_mday(cal, 15);
+                       _ucal_set_wday(cal, wday);
+                       _ucal_set_week(cal, week, sch);
+               }
+               break;
+
+       case UCAL_WEEK_OF_YEAR:
+               if (y <= year && m <= month && d < mday) {
+//                     while ((m <= month && d < mday) || (m < month)) {
+//                             ucal_add(cal, UCAL_WEEK_OF_YEAR, 1, &status);
+                               ucal_add(cal, inst_info[sch->freq].f, sch->interval, &status);
+                               m = ucal_get(cal, UCAL_MONTH, &status) + 1;
+                               d = ucal_get(cal, UCAL_DATE, &status);
+//                     }
+               }
+               break;
+       default:
+               break;
+       }
+
+       _print_cal(cal);
+       return 0;
+}
+
+
 static int _insert_instance(UCalendar *cal, int event_id,
-               struct cals_time *st, int dr, int day, int week, cal_sch_full_t *sch)
+               struct cals_time *st, int dr, int wday, int week, cal_sch_full_t *sch)
 {
+       CALS_FN_CALL;
        int r;
        int i;
        int cnt;
        int e_year;
        int e_month;
        int e_mday;
+       int year;
+       int month;
+       int mday;
 
        UCalendar *e_cal;
        UErrorCode status = U_ZERO_ERROR;
@@ -329,12 +438,27 @@ static int _insert_instance(UCalendar *cal, int event_id,
        memset(&until, 0, sizeof(struct cals_time));
        memset(&in, 0, sizeof(struct cals_time));
 
+       year = ucal_get(cal, UCAL_YEAR, &status);
+       month = ucal_get(cal, UCAL_MONTH, &status) + 1;
+       mday = ucal_get(cal, UCAL_DATE, &status);
        cnt = _get_max_count(sch);
        _set_until(&until, sch);
 
        for (i = 0; i < cnt; i++) {
-               _ucal_set_day(cal, day);
-               _ucal_set_week(cal, week);
+               if (wday != CALS_NODAY) {
+                       DBG("set 15th for wday");
+                       switch (inst_info[sch->freq].f) {
+                       case UCAL_YEAR:
+                       case UCAL_MONTH:
+                               _ucal_set_mday(cal, 15);
+                               break;
+                       default:
+                               break;
+                       }
+               }
+               _ucal_set_wday(cal, wday);
+               _ucal_set_week(cal, week, sch);
+               _shift_to_valid_wday(cal, year, month, mday, wday, week, sch);
 
                _ucal_get_instance(cal, st, &in);
                if (sch->freq != CALS_FREQ_ONCE && _is_after(&in, &until)) {
@@ -381,8 +505,10 @@ static int _insert_instance(UCalendar *cal, int event_id,
                }
 
                ucal_add(cal, inst_info[sch->freq].f, sch->interval, &status);
+               _print_cal(cal);
+               _shift_to_valid_mday(cal, mday, wday, sch);
        }
-
+       ucal_close(cal);
        return r;
 }
 
@@ -428,18 +554,52 @@ static inline int _get_month(const char *str)
        return month;
 }
 
-static inline int _get_mday(const char *str)
+static inline int _get_mday(const char *str, int *mday)
 {
-       int mday;
+       int d;
 
        if (!str || !*str)
                return -1;
 
-       mday = atoi(str);
-       if (mday < 1 || mday > 31)
+       d = atoi(str);
+       if (d < 1 || d > 31)
                return -1;
 
-       return mday;
+       *mday = d;
+       return 0;
+}
+
+int _adjust_valid_first_mday(UCalendar *cal, int year, int month, int mday, cal_sch_full_t *sch)
+{
+       CALS_FN_CALL;
+       int caly, calm, cald;
+       UErrorCode status = U_ZERO_ERROR;
+
+       caly = ucal_get(cal, UCAL_YEAR, &status);
+       calm = ucal_get(cal, UCAL_MONTH, &status) + 1;
+       cald = ucal_get(cal, UCAL_DATE, &status);
+
+       if (caly <= year && calm <= month, cald< mday) {
+               switch (inst_info[sch->freq].f) {
+               case UCAL_YEAR:
+                       ucal_add(cal, UCAL_YEAR, 1, &status);
+                       break;
+               case UCAL_MONTH:
+                       ucal_add(cal, UCAL_MONTH, 1, &status);
+                       break;
+               case UCAL_WEEK_OF_YEAR:
+                       ucal_add(cal, UCAL_DATE, 7, &status);
+                       break;
+               default:
+                       break;
+               }
+       }
+       return 0;
+}
+
+int _set_valid_first_mday(UCalendar *cal, struct cals_time *st, cal_sch_full_t *sch)
+{
+       return 0;
 }
 
 static int insert_bymday(int event_id,
@@ -448,11 +608,13 @@ static int insert_bymday(int event_id,
        UCalendar *cal;
        int r;
        int i;
+       int y, m, d;
        int mday;
        char **t;
-       const char *d = ",";
+       const char *dl = ",";
+       UErrorCode status = U_ZERO_ERROR;
 
-       t = g_strsplit(sch->bymonthday, d, -1);
+       t = g_strsplit(sch->bymonthday, dl, -1);
 
        if (!t) {
                ERR("g_strsplit failed");
@@ -460,8 +622,9 @@ static int insert_bymday(int event_id,
        }
 
        for (i = 0; t[i]; ++i) {
-               mday = _get_mday(t[i]);
-               if (mday < 0) {
+               r = _get_mday(t[i], &mday);
+               if (r < 0) {
+                       ERR("Failed to get mday");
                        g_strfreev(t);
                        return CAL_ERR_ARG_INVALID;
                }
@@ -470,10 +633,14 @@ static int insert_bymday(int event_id,
                if (!cal)
                        return CAL_ERR_FAIL;
                _ucal_set_time(cal, st);
+               y = ucal_get(cal, UCAL_YEAR, &status);
+               m = ucal_get(cal, UCAL_MONTH, &status) + 1;
+               d = ucal_get(cal, UCAL_DATE, &status);
                _ucal_set_month(cal, month);
                _ucal_set_mday(cal, mday);
+               _adjust_valid_first_mday(cal, y, m, d, sch);
 
-               r = _insert_instance(cal, event_id, st, dr, CALS_NODAY, 0,  sch);
+               r = _insert_instance(cal, event_id, st, dr, CALS_NODAY, 0, sch);
                if (r) {
                        ERR("_insert_bymday failed (%d)", r);
                        g_strfreev(t);
@@ -499,7 +666,7 @@ static int insert_no_by(int event_id,
        return _insert_instance(cal, event_id, st, dr, CALS_NODAY, 0, sch);
 }
 
-static inline int _get_day(const char *str, int *week, int *day)
+static inline int _get_wday(const char *str, int *week, int *wday)
 {
        int i;
        int d;
@@ -509,42 +676,42 @@ static inline int _get_day(const char *str, int *week, int *day)
                return -1;
 
        if (!sscanf(str, "%d", &d)) {
-               DBG("no week digit");
+               DBG("no digit in front of char, so set 1 as default");
                if (sscanf(str, "%s", buf) != 1) {
-                       ERR("Failed to get day[%s]", str);
+                       ERR("Failed to get wday[%s]", str);
                        return -1;
                }
-               d = 0;
+               d = 1;
        } else {
                if (sscanf(str, "%d%s", &d, buf) != 2) {
-                       ERR("Failed to get day[%s]", str);
+                       ERR("Failed to get wday[%s]", str);
                        return -1;
                }
        }
 
-       *week = d;
+       *week = d > 4 ? -1 : d;
 
        buf[2] = '\0';
-       DBG("[%s] and sets week (%d)", buf, d);
+       DBG("Sets week(%d) wday[%s]", d, buf);
 
-       for (i = 0; i < sizeof(days)/sizeof(struct day); i++) {
-               if (!strncmp(days[i].str, buf, 2)) {
-                       DBG("inserted wday[%s]and set[%s]", days[i].str, buf);
-                       *day = i;
+       for (i = 0; i < sizeof(wdays)/sizeof(struct day); i++) {
+               if (!strncmp(wdays[i].str, buf, 2)) {
+                       DBG("inserted week(%d) wday[%s]", *week, wdays[i].str);
+                       *wday = i;
                        break;
                }
        }
-
        return 0;
 }
 
 static int insert_byday(int event_id,
                struct cals_time *st, int dr, int month, cal_sch_full_t *sch)
 {
+       CALS_FN_CALL;
        UCalendar *cal;
        int r;
        int i;
-       int day;
+       int wday;
        int week;
        char **t;
        const char *d = ",";
@@ -556,14 +723,14 @@ static int insert_byday(int event_id,
                return CAL_ERR_OUT_OF_MEMORY;
        }
 
-       day = 0;
+       wday = 0;
        week = 0;
 
        for (i = 0; t[i]; ++i) {
-               r = _get_day(t[i], &week, &day);
+               r = _get_wday(t[i], &week, &wday);
                if (r < 0) {
+                       ERR("Failed to get wday");
                        g_strfreev(t);
-                       ERR("_get_day failed");
                        return CAL_ERR_ARG_INVALID;
                }
 
@@ -573,7 +740,7 @@ static int insert_byday(int event_id,
                _ucal_set_time(cal, st);
                _ucal_set_month(cal, month);
 
-               r = _insert_instance(cal, event_id, st, dr, day, week, sch);
+               r = _insert_instance(cal, event_id, st, dr, wday, week, sch);
                if (r) {
                        ERR("_insert_bymday failed (%d)", r);
                        g_strfreev(t);
index b9e3d3eaa90dcefe03cbf061275722659087bb51..985752f8011aaff82150c8fac39a4f1a47068849 100755 (executable)
 #include "cals-schedule.h"
 #include "cals-inotify.h"
 
+#ifdef CALS_IPC_SERVER
+extern __thread sqlite3 *calendar_db_handle;
+#else
 extern sqlite3* calendar_db_handle;
+#endif
 
+#ifdef CALS_IPC_SERVER
+static __thread int db_ref_cnt = 0;
+#else
 static int db_ref_cnt = 0;
+#endif
 cal_svc_tm_info_t cal_svc_tm_value;
 
 typedef enum
@@ -192,35 +200,51 @@ API int calendar_svc_connect(void)
        CALS_FN_CALL;
        int ret = 0;
 
+#ifdef CALS_IPC_SERVER
+       DBG("pthread_self=%x, db_ref_cnt=%p", pthread_self(),&db_ref_cnt );
+#endif
        g_type_init();  // added for alarmmgr
 
        if(db_ref_cnt <= 0)
        {
                ret = cals_db_open();
                retvm_if(ret, ret, "cals_db_open() Failed(%d)", ret);
-
+#ifdef CALS_IPC_SERVER
+#else
                ret = cals_inotify_init();
                if(CAL_SUCCESS != ret) {
                        cals_db_close();
                        ERR("cals_inotify_init() Failed(%d)", ret);
                        return ret;
                }
+#endif
                db_ref_cnt = 0;
        }
        db_ref_cnt++;
-
+#ifdef CALS_IPC_SERVER
+    DBG("db_ref_cnt(%d)", db_ref_cnt);
+#endif
        return CAL_SUCCESS;
 }
 
 API int calendar_svc_close(void)
 {
        CALS_FN_CALL;
+#ifdef CALS_IPC_SERVER
+    DBG("db_ref_cnt(%d)", db_ref_cnt);
+    DBG("pthread_self=%x, db_ref_cnt=%p", pthread_self(),&db_ref_cnt );
+#endif
        retvm_if(0 == db_ref_cnt, CAL_ERR_ENV_INVALID,
                        "Calendar service was not connected");
 
        if (db_ref_cnt==1) {
                cals_db_close();
+#ifdef CALS_IPC_SERVER
+               db_ref_cnt = 0;
+               return 1;
+#else
                cals_inotify_close();
+#endif
        }
        db_ref_cnt--;
 
@@ -421,14 +445,18 @@ API int calendar_svc_get(const char *data_type,int index,const char *field_list,
                cal_sch_full_t *sch_record = NULL;
                sch_record = (*record)->user_data;
 
+               /*
+                * is_deleted = 0 is not included in query.
+                * instead, developer should check after getting data.
+                */
                if (field_list) {
                        cals_rearrange_schedule_field(field_list, rearranged, sizeof(rearranged));
                        snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT %s FROM %s WHERE id = %d AND is_deleted = 0 ",
+                                       "SELECT %s FROM %s WHERE id = %d ",
                                        CALS_TABLE_SCHEDULE, rearranged, index);
                } else {
                        snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s WHERE id = %d AND is_deleted = 0 ",
+                                       "SELECT * FROM %s WHERE id = %d ",
                                        CALS_TABLE_SCHEDULE, index);
                }
 
@@ -437,7 +465,15 @@ API int calendar_svc_get(const char *data_type,int index,const char *field_list,
                retex_if(NULL == stmt,,"cals_query_prepare() Failed");
 
                rc = cals_stmt_step(stmt);
-               if (rc != CAL_TRUE) {
+               if (rc == CAL_SUCCESS) {
+                       DBG("stmt done is called. No data(%d)", rc);
+                       sqlite3_finalize(stmt);
+                       if (malloc_inside && *record != NULL) {
+                               calendar_svc_struct_free(record);
+                       }
+                       return CAL_ERR_NO_DATA;
+
+               } else if (rc != CAL_TRUE) {
                        ERR("Failed to step stmt(%d)", rc);
                        sqlite3_finalize(stmt);
                        if (malloc_inside && *record != NULL) {
@@ -482,10 +518,9 @@ API int calendar_svc_get(const char *data_type,int index,const char *field_list,
 
                sch_record->index = index;
 
-               if (0 == strcmp(data_type,CAL_STRUCT_SCHEDULE)) {
-                       cal_db_service_get_participant_info_by_index(index,&(sch_record->attendee_list),&error_code);
-                       cals_get_alarm_info(index, &(sch_record->alarm_list));
-               }
+               cal_db_service_get_participant_info_by_index(index,
+                               &(sch_record->attendee_list),&error_code);
+               cals_get_alarm_info(index, &(sch_record->alarm_list));
        }
        else if(0 == strcmp(data_type,CAL_STRUCT_CALENDAR))
        {
@@ -1197,6 +1232,7 @@ static void cals_iter_get_info_change(cals_updated *cursor, cals_updated *result
        result->type = cursor->type;
        result->id = cursor->id;
        result->ver = cursor->ver;
+       result->calendar_id = cursor->calendar_id;
        return;
 }
 
index 3389b3dcd7385f73ce5b6300a127fa9b259e46b4..35db6a90c2d8b8556dda5da57cc718ea097b9690 100755 (executable)
@@ -357,6 +357,7 @@ int cals_insert_schedule(cal_sch_full_t *sch_record)
 
        if (sch_record->attendee_list)
        {
+               DBG("attendee exists");
                GList *list = g_list_first(sch_record->attendee_list);
                cal_participant_info_t *participant_info = NULL;
 
@@ -374,30 +375,58 @@ int cals_insert_schedule(cal_sch_full_t *sch_record)
                        }
                        list = g_list_next(list);
                }
+       } else {
+               DBG("No attendee exists");
        }
 
        if (sch_record->alarm_list)
        {
+               DBG("alarm exists");
                GList *list = sch_record->alarm_list;
                cal_alarm_info_t *alarm_info = NULL;
 
                while (list)
                {
                        cvalue = list->data;
-                       if (cvalue)
+                       if (cvalue == NULL) {
+                               ERR("Failed to fine value");
+                               break;
+                       }
+
+                       alarm_info = cvalue->user_data;
+                       if (alarm_info == NULL) {
+                               ERR("Failed to find alarm info");
+                               break;
+                       }
+
+                       if(alarm_info->is_deleted == 0)
                        {
-                               alarm_info = cvalue->user_data;
-                               if(alarm_info->is_deleted == 0)
+                               DBG("type(%d) tick(%d) unit(%d)",
+                                               sch_record->cal_type,
+                                               alarm_info->remind_tick,
+                                               alarm_info->remind_tick_unit);
+                               if (alarm_info->remind_tick != CALS_INVALID_ID)
                                {
-                                       if (alarm_info->remind_tick != CALS_INVALID_ID)
-                                       {
+                                       switch (sch_record->cal_type) {
+                                       case CALS_SCH_TYPE_EVENT:
                                                ret = cals_alarm_add(index, alarm_info, &st);
                                                warn_if(CAL_SUCCESS != ret, "cals_alarm_add() Failed(%d)", ret);
+                                               break;
+                                       case CALS_SCH_TYPE_TODO:
+                                               if (sch_record->dtend_utime == CALS_TODO_NO_DUE_DATE) {
+                                                       DBG("no due date is set");
+                                                       break;
+                                               }
+                                               ret = cals_alarm_add(index, alarm_info, &et);
+                                               warn_if(CAL_SUCCESS != ret, "cals_alarm_add() Failed(%d)", ret);
+                                               break;
                                        }
                                }
                        }
                        list = list->next;
                }
+       } else {
+               DBG("No alarm exists");
        }
 
        cals_end_trans(true);
@@ -622,6 +651,7 @@ static inline int _cals_update_rrule(const int index, cal_sch_full_t *record)
        retv_if(record == NULL, CAL_ERR_ARG_NULL);
 
        snprintf(query, sizeof(query), "UPDATE %s set "
+                       "freq = %d, "
                        "range_type = %d, "
                        "until_type = %d, "
                        "until_utime = %lld, "
@@ -640,6 +670,7 @@ static inline int _cals_update_rrule(const int index, cal_sch_full_t *record)
                        "wkst = %d "
                        "WHERE event_id = %d",
                        CALS_TABLE_RRULE,
+                       record->freq,
                        record->range_type,
                        record->until_type,
                        record->until_utime,
@@ -998,12 +1029,6 @@ int cals_delete_schedule(int id)
                return r;
        }
 
-       r = _cals_delete_rrule(id);
-       if (r) {
-               ERR("_cals_delete_rrule (%d)", r);
-               return r;
-       }
-
        r = cals_alarm_remove(CALS_ALARM_REMOVE_BY_EVENT_ID, id);
        if (r) {
                ERR("cals_alarm_remove() failed(%d)", r);
@@ -1660,7 +1685,8 @@ API int calendar_svc_smartsearch_excl(const char *keyword, int offset, int limit
 
        snprintf(query, sizeof(query), "SELECT A.* "
                        "FROM %s A LEFT JOIN %s B ON A.calendar_id = B.ROWID "
-                       "WHERE A.summary LIKE ('%%' || :key || '%%') AND B.visibility = 1 LIMIT %d OFFSET %d",
+                       "WHERE A.summary LIKE ('%%' || :key || '%%') "
+                       "AND B.visibility = 1 LIMIT %d OFFSET %d",
                        CALS_TABLE_SCHEDULE, CALS_TABLE_CALENDAR, limit, offset);
 
        stmt = cals_query_prepare(query);
index c70cc99fbd9fa4b39c3277583340fbf97d9fe69d..0936c07abd0cac376e31b6c8856e3fff905ce1ca 100755 (executable)
 #include "cals-db-info.h"
 #include "cals-sqlite.h"
 
+#ifdef CALS_IPC_SERVER
+__thread sqlite3 *calendar_db_handle;
+#else
 sqlite3 *calendar_db_handle;
+#endif
 
 int cals_db_open(void)
 {
@@ -168,8 +172,9 @@ int cals_escape_like_pattern(const char *src, char * const dest, int dest_size)
        }
 
        while (src[s_pos] != 0) {
-               if (dest_size == d_pos - 1)
+               if (dest_size -1 == d_pos) {
                        break;
+               }
                if ('%' == src[s_pos] || '_' == src[s_pos]) {
                        dest[d_pos++] = '\\';
                }
@@ -177,7 +182,6 @@ int cals_escape_like_pattern(const char *src, char * const dest, int dest_size)
        }
 
        dest[d_pos] = '\0';
-
        return d_pos;
 }
 
index 57c5250eaaa3f67eb139026d1f6555f4173a1cd5..c57ddd1727c12927c86df6dafc6f9bf550562e34 100755 (executable)
 #include "calendar-svc-provider.h"
 #include "cals-internal.h"
 #include "cals-typedef.h"
+#ifdef CALS_IPC_CLIENT
+#else
 #include "cals-db.h"
 #include "cals-utils.h"
+#endif
+
+#ifdef CALS_IPC_CLIENT
+static bool __cal_free_participant(cal_participant_info_t* paritcipant_info, int *error_code)
+{
+    if(NULL == paritcipant_info)
+    {
+        return true;
+    }
+
+    CAL_FREE(paritcipant_info->attendee_email);
+    CAL_FREE(paritcipant_info->attendee_number);
+    CAL_FREE(paritcipant_info->attendee_name);
+
+    return true;
+}
+
+static bool __cal_free_full_record(cal_sch_full_t *sch_full_record, int *error_code)
+{
+    retex_if(error_code == NULL, ,"error_code is NULL.");
+    retex_if(sch_full_record == NULL, *error_code = CAL_ERR_ARG_INVALID,"sch_full_record is NULL.");
+    cal_value *value = NULL;
+    GList *head;
+
+    CAL_FREE(sch_full_record->summary);
+    CAL_FREE(sch_full_record->description);
+    CAL_FREE(sch_full_record->location);
+    CAL_FREE(sch_full_record->categories);
+    CAL_FREE(sch_full_record->uid);
+    CAL_FREE(sch_full_record->organizer_name);
+    CAL_FREE(sch_full_record->organizer_email);
+    CAL_FREE(sch_full_record->gcal_id);
+    CAL_FREE(sch_full_record->updated);
+    CAL_FREE(sch_full_record->location_summary);
+    CAL_FREE(sch_full_record->etag);
+    CAL_FREE(sch_full_record->edit_uri);
+    CAL_FREE(sch_full_record->gevent_id);
+
+    if (sch_full_record->attendee_list)
+    {
+        head = sch_full_record->attendee_list;
+        while (sch_full_record->attendee_list)
+        {
+            value = sch_full_record->attendee_list->data;
+            if(NULL != value)
+            {
+                if(NULL != value->user_data)
+                {
+                    __cal_free_participant((cal_participant_info_t*)value->user_data,error_code);
+                    CAL_FREE(value->user_data);
+
+                }
+                CAL_FREE(value);
+            }
+            sch_full_record->attendee_list = sch_full_record->attendee_list->next;
+        }
+        g_list_free(head);
+        sch_full_record->attendee_list = NULL;
+    }
+    return true;
+
+CATCH:
+
+    return false;
+}
+#endif
+
+int cals_event_init(cal_sch_full_t *sch_full_record)
+{
+       retvm_if(NULL == sch_full_record, CAL_ERR_ARG_INVALID , "sch_full_record is NULL");
+
+       memset(sch_full_record,0,sizeof(cal_sch_full_t));
+
+       sch_full_record->cal_type = CALS_SCH_TYPE_EVENT;
+       sch_full_record->meeting_status = CALS_EVENT_STATUS_NONE;
+       sch_full_record->calendar_id = DEFAULT_EVENT_CALENDAR_ID;
+
+       sch_full_record->index = CALS_INVALID_ID;
+       sch_full_record->timezone = -1;
+       sch_full_record->contact_id = CALS_INVALID_ID;
+       sch_full_record->calendar_type = CAL_PHONE_CALENDAR;
+       sch_full_record->attendee_list = NULL;
+       sch_full_record->busy_status = 2;
+       sch_full_record->summary = NULL;
+       sch_full_record->description = NULL;
+       sch_full_record->location= NULL;
+       sch_full_record->categories = NULL;
+       sch_full_record->exdate = NULL;
+       sch_full_record->organizer_email = NULL;
+       sch_full_record->organizer_name = NULL;
+       sch_full_record->uid= NULL;
+       sch_full_record->gcal_id = NULL;
+       sch_full_record->location_summary = NULL;
+       sch_full_record->etag = NULL;
+       sch_full_record->edit_uri = NULL;
+       sch_full_record->gevent_id = NULL;
+       sch_full_record->original_event_id = CALS_INVALID_ID;
+
+       sch_full_record->sync_status = CAL_SYNC_STATUS_NEW;
+       sch_full_record->account_id = -1;
+       sch_full_record->is_deleted = 0;
+       sch_full_record->latitude = 1000; // set default 1000 out of range(-180 ~ 180)
+       sch_full_record->longitude = 1000; // set default 1000 out of range(-180 ~ 180)
+       sch_full_record->freq = CALS_FREQ_ONCE;
+       sch_full_record->until_utime = CALS_TODO_NO_DUE_DATE;
+
+       return CAL_SUCCESS;
+}
+
+int cals_todo_init(cal_sch_full_t *sch_full_record)
+{
+       retvm_if(NULL == sch_full_record, CAL_ERR_ARG_INVALID , "sch_full_record is NULL");
+
+       memset(sch_full_record,0,sizeof(cal_sch_full_t));
+
+       sch_full_record->cal_type = CALS_SCH_TYPE_TODO;
+       sch_full_record->task_status = CALS_TODO_STATUS_NONE;
+       sch_full_record->calendar_id = DEFAULT_TODO_CALENDAR_ID;
+
+       sch_full_record->index = CALS_INVALID_ID;
+       sch_full_record->timezone = -1;
+       sch_full_record->contact_id = CALS_INVALID_ID;
+       sch_full_record->calendar_type = CAL_PHONE_CALENDAR;
+       sch_full_record->attendee_list = NULL;
+       sch_full_record->busy_status = 2;
+       sch_full_record->summary = NULL;
+       sch_full_record->description = NULL;
+       sch_full_record->location= NULL;
+       sch_full_record->categories = NULL;
+       sch_full_record->exdate = NULL;
+       sch_full_record->organizer_email = NULL;
+       sch_full_record->organizer_name = NULL;
+       sch_full_record->uid= NULL;
+       sch_full_record->gcal_id = NULL;
+       sch_full_record->location_summary = NULL;
+       sch_full_record->etag = NULL;
+       sch_full_record->edit_uri = NULL;
+       sch_full_record->gevent_id = NULL;
+       sch_full_record->original_event_id = CALS_INVALID_ID;
+
+       sch_full_record->sync_status = CAL_SYNC_STATUS_NEW;
+       sch_full_record->account_id = -1;
+       sch_full_record->is_deleted = 0;
+       sch_full_record->latitude = 1000; // set default 1000 out of range(-180 ~ 180)
+       sch_full_record->longitude = 1000; // set default 1000 out of range(-180 ~ 180)
+       sch_full_record->freq = CALS_FREQ_ONCE;
+       sch_full_record->until_utime = CALS_TODO_NO_DUE_DATE;
+
+       return CAL_SUCCESS;
+}
 
 static inline void cals_init_calendar_record(calendar_t *calendar)
 {
@@ -204,7 +356,11 @@ API int calendar_svc_struct_free (cal_struct** event)
        {
        case CAL_STRUCT_TYPE_SCHEDULE:
        case CAL_STRUCT_TYPE_TODO:
-               cal_db_service_free_full_record((cal_sch_full_t*)(*event)->user_data,&ret);
+#ifdef CALS_IPC_CLIENT
+           __cal_free_full_record((cal_sch_full_t*)(*event)->user_data,&ret);
+#else
+               cal_db_service_free_full_record((cal_sch_full_t*)(*event)->user_data);
+#endif
                CAL_FREE((*event)->user_data);
                CAL_FREE(*event);
                break;
@@ -847,6 +1003,10 @@ API int calendar_svc_struct_get_int(cal_struct *event, const char *field)
                {
                        return update->ver;
                }
+               else if(0 == strcmp(field, CALS_STRUCT_UPDATED_INT_CALENDAR_ID))
+               {
+                       return update->calendar_id;
+               }
                else
                {
                        ERR("Can not find the field(%s)",field);
index e9fb2a75a0fcdc142ab04670381ba77828f801fd..c295df9b8a42dd8171ac92e37302e22217d2e679 100755 (executable)
@@ -19,4 +19,7 @@
 #ifndef _CALENDAR_SVC_STRUCT_INTERNAL_H_
 #define _CALENDAR_SVC_STRUCT_INTERNAL_H_
 
+int cals_event_init(cal_sch_full_t *sch_full_record);
+int cals_todo_init(cal_sch_full_t *sch_full_record);
+
 #endif // _CALENDAR_SVC_STRUCT_INTERNAL_H_
index 44162f44087878f14aab48713e4877d09559058a..e7ca93467160f9c39ae58552a2986dbf003f25da 100644 (file)
@@ -117,6 +117,7 @@ char *cals_time_get_str_datetime(char *tzid, long long int t)
                tzid = CALS_TZID_0;
        }
        cal = _ucal_get_cal(tzid);
+       ucal_setMillis(cal, sec2ms(t), &status);
 
        y = ucal_get(cal, UCAL_YEAR, &status);
        mon = ucal_get(cal, UCAL_MONTH, &status) + 1;
@@ -131,6 +132,27 @@ char *cals_time_get_str_datetime(char *tzid, long long int t)
        return strdup(buf);
 }
 
+int cals_time_get_val_datetime(char *tzid, long long int t, const char *field, int *val)
+{
+       UErrorCode status = U_ZERO_ERROR;
+       UCalendar *cal;
+
+       if (tzid == NULL) {
+               tzid = CALS_TZID_0;
+       }
+       cal = _ucal_get_cal(tzid);
+       if (!strncmp(field, "year", strlen("year"))) {
+               *val = ucal_get(cal, UCAL_YEAR, &status);
+       } else if (!strncmp(field, "month", strlen("month"))) {
+               *val = ucal_get(cal, UCAL_MONTH, &status);
+       } else if (!strncmp(field, "mday", strlen("mday"))) {
+               *val = ucal_get(cal, UCAL_DATE, &status);
+       }
+       ucal_close(cal);
+
+       return 0;
+}
+
 long long int cals_time_convert_to_lli(struct cals_time *ct)
 {
        long long int lli;
@@ -178,7 +200,7 @@ long long int cals_time_date_to_utime(const char *tzid,
 {
        UCalendar *cal;
        UErrorCode status = U_ZERO_ERROR;
-       UChar *_tzid;
+       //UChar *_tzid;
        long long int lli;
 
        cal = _ucal_get_cal(tzid);
@@ -204,3 +226,66 @@ long long int cals_get_lli_now(void)
 {
        return ms2sec(ucal_getNow());
 }
+
+#ifdef CALS_IPC_CLIENT
+char cal_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+/* sec to 1970 1 1 0:0:0 */
+#define D19700101 62167219200
+
+long long int _date_to_utime(int y, int mon, int d, int h, int min, int s)
+{
+    int i;
+    long long int t;
+
+    t = y * 365;
+    t += ((int)y/4 - (int)y/100 + (int)y/400);
+    for (i = 0; i < mon-1; i++) {
+        t += cal_month[i];
+    }
+    if (i > 2 && (y % 4 == 0)) {
+        t += 1;
+        if ((y % 100 == 0) && (y % 400 != 0)) {
+            t -= 1;
+        }
+    }
+    t += d;
+    t *= (24 * 60 * 60);
+    t += (((h * 60) + min ) * 60 + s);
+    t -= D19700101;
+    return t;
+}
+
+long long int _datetime_to_utime(char *datetime)
+{
+    int y, mon, d, h, min, s;
+    char tmp[8] = {0};
+    char *p;
+
+    if (datetime == NULL || strlen(datetime) == 0) {
+        ERR("Invalid argument");
+        return -1;
+    }
+
+    p = datetime;
+    snprintf(tmp, 5, "%s", p);
+    y = atoi(tmp);
+    snprintf(tmp, 3, "%s", p + 4);
+    mon = atoi(tmp);
+    snprintf(tmp, 3, "%s", p + 6);
+    d = atoi(tmp);
+
+    if (strlen(datetime) > 14) {
+        snprintf(tmp, 3, "%s", p + 9);
+        h = atoi(tmp);
+        snprintf(tmp, 3, "%s", p + 11);
+        min = atoi(tmp);
+        snprintf(tmp, 3, "%s", p + 13);
+        s = atoi(tmp);
+
+    } else {
+        h = min = s = 0;
+    }
+
+    return _date_to_utime(y, mon, d, h, min, s);
+}
+#endif
index 4487f6da9bbc9cc1816fd2b545b2ba71fc1b4c49..7850250003ea7914ef03fdd025007deca4d474ec 100644 (file)
@@ -14,7 +14,14 @@ long long int cals_time_diff(struct cals_time *st, struct cals_time *et);
 long long int cals_time_diff_with_now(struct cals_time *t);
 char *cals_time_get_str_datetime(char *tzid, long long int t);
 long long int cals_get_lli_now(void);
+long long int cals_time_date_to_utime(const char *tzid,
+               int year, int month, int mday, int hour, int minute, int second);
 
-#define CALS_TZID_0 "Europe/London"
+#ifdef CALS_IPC_CLIENT
+long long int _date_to_utime(int y, int mon, int d, int h, int min, int s);
+long long int _datetime_to_utime(char *datetime);
+#endif
+
+#define CALS_TZID_0 "Etc/Unknown"
 
 #endif
index db6c67a4520cd23f798ff8770de4b911b9ab9ce0..c860f947612b85d1004784c3ce5dfa952d5f78ba 100755 (executable)
@@ -37,48 +37,6 @@ static inline const char *cals_todo_get_order(cals_todo_list_order_t order)
        return _todo_list_order[order];
 }
 
-int cals_todo_init(cal_sch_full_t *sch_full_record)
-{
-       retvm_if(NULL == sch_full_record, CAL_ERR_ARG_INVALID , "sch_full_record is NULL");
-
-       memset(sch_full_record,0,sizeof(cal_sch_full_t));
-
-       sch_full_record->cal_type = CALS_SCH_TYPE_TODO;
-       sch_full_record->task_status = CALS_TODO_STATUS_NONE;
-       sch_full_record->calendar_id = DEFAULT_TODO_CALENDAR_ID;
-
-       sch_full_record->index = CALS_INVALID_ID;
-       sch_full_record->timezone = -1;
-       sch_full_record->contact_id = CALS_INVALID_ID;
-       sch_full_record->calendar_type = CAL_PHONE_CALENDAR;
-       sch_full_record->attendee_list = NULL;
-       sch_full_record->busy_status = 2;
-       sch_full_record->summary = NULL;
-       sch_full_record->description = NULL;
-       sch_full_record->location= NULL;
-       sch_full_record->categories = NULL;
-       sch_full_record->exdate = NULL;
-       sch_full_record->organizer_email = NULL;
-       sch_full_record->organizer_name = NULL;
-       sch_full_record->uid= NULL;
-       sch_full_record->gcal_id = NULL;
-       sch_full_record->location_summary = NULL;
-       sch_full_record->etag = NULL;
-       sch_full_record->edit_uri = NULL;
-       sch_full_record->gevent_id = NULL;
-       sch_full_record->original_event_id = CALS_INVALID_ID;
-
-       sch_full_record->sync_status = CAL_SYNC_STATUS_NEW;
-       sch_full_record->account_id = -1;
-       sch_full_record->is_deleted = 0;
-       sch_full_record->latitude = 1000; // set default 1000 out of range(-180 ~ 180)
-       sch_full_record->longitude = 1000; // set default 1000 out of range(-180 ~ 180)
-       sch_full_record->freq = CALS_FREQ_ONCE;
-
-       return CAL_SUCCESS;
-}
-
-
 static int __todo_get_query_priority(int priority, char *query, int len)
 {
        switch (priority) {
@@ -212,7 +170,7 @@ API int calendar_svc_todo_get_list(int calendar_id, long long int dtend_from, lo
 {
        cal_iter *it;
        sqlite3_stmt *stmt = NULL;
-       char buf_calendar_id[256] = {0};
+       char buf_id[256] = {0};
        char buf_dtend_from[256] = {0};
        char buf_dtend_to[256] = {0};
        char buf_priority[256] = {0};
@@ -223,18 +181,18 @@ API int calendar_svc_todo_get_list(int calendar_id, long long int dtend_from, lo
        retv_if(order < CALS_TODO_LIST_ORDER_END_DATE || order > CALS_TODO_LIST_ORDER_STATUS, CAL_ERR_ARG_INVALID);
 
        if (calendar_id > 0) {
-               snprintf(buf_calendar_id, sizeof(buf_calendar_id), "AND calendar_id = %d ", calendar_id);
+               snprintf(buf_id, sizeof(buf_id), "AND calendar_id = %d ", calendar_id);
        } else {
-               memset(buf_calendar_id, 0x0, sizeof(buf_calendar_id));
+               memset(buf_id, 0x0, sizeof(buf_id));
        }
 
-       if (dtend_from >= 0) {
+       if (dtend_from != CALS_TODO_NO_DUE_DATE) {
                snprintf(buf_dtend_from, sizeof(buf_dtend_from), "AND dtend_utime >= %lld ", dtend_from);
        } else {
                memset(buf_dtend_from, 0x0, sizeof(buf_dtend_from));
        }
 
-       if (dtend_to >= 0) {
+       if (dtend_to != CALS_TODO_NO_DUE_DATE) {
                snprintf(buf_dtend_to, sizeof(buf_dtend_to), "AND dtend_utime <= %lld ", dtend_to);
        } else {
                memset(buf_dtend_to, 0x0, sizeof(buf_dtend_to));
@@ -250,7 +208,7 @@ API int calendar_svc_todo_get_list(int calendar_id, long long int dtend_from, lo
                        "ORDER BY %s",
                        CALS_TABLE_SCHEDULE,
                        CAL_STRUCT_TYPE_TODO,
-                       buf_calendar_id, buf_dtend_from, buf_dtend_to, buf_priority, buf_status,
+                       buf_id, buf_dtend_from, buf_dtend_to, buf_priority, buf_status,
                        cals_todo_get_order(order));
 
        stmt = cals_query_prepare(query);
@@ -294,10 +252,10 @@ static inline int cals_todo_get_changes(int calendar_id, int version, cal_iter *
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT id, changed_ver, created_ver, is_deleted FROM %s "
+                       "SELECT id, changed_ver, created_ver, is_deleted, calendar_id FROM %s "
                        "WHERE changed_ver > %d AND original_event_id = %d AND type = %d %s "
                        "UNION "
-                       "SELECT schedule_id, deleted_ver, -1, 1 FROM %s "
+                       "SELECT schedule_id, deleted_ver, -1, 1, calendar_id FROM %s "
                        "WHERE deleted_ver > %d AND schedule_type = %d %s",
                        CALS_TABLE_SCHEDULE,
                        version, CALS_INVALID_ID, CALS_SCH_TYPE_TODO, buf,
@@ -313,12 +271,14 @@ static inline int cals_todo_get_changes(int calendar_id, int version, cal_iter *
 
                result->id = sqlite3_column_int(stmt, 0);
                result->ver = sqlite3_column_int(stmt, 1);
-               if (sqlite3_column_int(stmt, 3) == 1)
+               if (sqlite3_column_int(stmt, 3) == 1) {
                        result->type = CALS_UPDATED_TYPE_DELETED;
-               else if (sqlite3_column_int(stmt, 2) == result->ver || version < sqlite3_column_int(stmt, 2))
+               } else if (sqlite3_column_int(stmt, 2) == result->ver || version < sqlite3_column_int(stmt, 2)) {
                        result->type = CALS_UPDATED_TYPE_INSERTED;
-               else
+               } else {
                        result->type = CALS_UPDATED_TYPE_MODIFIED;
+               }
+               result->calendar_id = sqlite3_column_int(stmt, 4);
 
                if (iter->info->head == NULL) {
                        iter->info->head = result;
@@ -439,10 +399,10 @@ API int calendar_svc_todo_get_list_by_period(int calendar_id,
        snprintf(query, sizeof(query),
                        "SELECT * FROM %s "
                        "WHERE dtend_utime >= %lld AND dtend_utime <= %lld "
-                       "AND type = %d %s %s ",
+                       "AND type = %d %s %s %s ",
                        CALS_TABLE_SCHEDULE,
                        due_from, dueto,
-                       CALS_SCH_TYPE_TODO, buf_prio, buf_stat);
+                       CALS_SCH_TYPE_TODO, buf_prio, buf_stat, buf_id);
 DBG("%s\n", query);
        stmt = cals_query_prepare(query);
        retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "Failed to query prepare");
@@ -457,6 +417,7 @@ API int calendar_svc_todo_get_count_by_period(int calendar_id,
 {
        int ret, cnt = 0;
        char query[CALS_SQL_MIN_LEN] = {0};
+       char buf_id[64] = {0};
        char buf_prio[64] = {0};
        char buf_stat[256] = {0};
 
@@ -466,6 +427,12 @@ API int calendar_svc_todo_get_count_by_period(int calendar_id,
        DBG("priority(%d) status(%d)", priority, status);
        sqlite3_stmt *stmt = NULL;
 
+       if (calendar_id > 0) {
+               snprintf(buf_id, sizeof(buf_id), "AND calendar_id = %d ", calendar_id);
+       } else {
+               memset(query, 0x0, sizeof(buf_id));
+       }
+
        /* priority */
        __todo_get_query_priority(priority, buf_prio, sizeof(buf_prio));
 
@@ -475,10 +442,10 @@ API int calendar_svc_todo_get_count_by_period(int calendar_id,
        snprintf(query, sizeof(query),
                        "SELECT count(*) FROM %s "
                        "WHERE dtend_utime >= %lld AND dtend_utime <= %lld "
-                       "AND type = %d %s %s ",
+                       "AND type = %d %s %s %s ",
                        CALS_TABLE_SCHEDULE,
                        due_from, dueto,
-                       CALS_SCH_TYPE_TODO, buf_prio, buf_stat);
+                       CALS_SCH_TYPE_TODO, buf_prio, buf_stat, buf_id);
 
 DBG("%s\n", query);
        stmt = cals_query_prepare(query);
index 32b3a4bbedb3750180ec8dd23ebfbfd84b9df228..0344abec07dc6e339a045ff903d8d3bcffa48b0f 100755 (executable)
@@ -98,6 +98,7 @@ typedef struct _updated {
        int type;
        int id;
        int ver;
+       int calendar_id;
        struct _updated *next;
 } cals_updated;
 
index 0556a19ce7ca03e177c79ff4295b3ef9523b34d6..6239faf10da8163301ed14132a21450c085c3cb7 100755 (executable)
 
 #define CALS_MALLOC_DEFAULT_NUM 256 //4Kbytes
 
+#ifdef CALS_IPC_SERVER
+extern __thread sqlite3 *calendar_db_handle;
+#else
 extern sqlite3* calendar_db_handle;
+#endif
 
 typedef        enum
 {
@@ -45,6 +49,15 @@ static const char *CALS_NOTI_EVENT_CHANGED="/opt/data/calendar-svc/.CALENDAR_SVC
 static const char *CALS_NOTI_TODO_CHANGED="/opt/data/calendar-svc/.CALENDAR_SVC_TODO_CHANGED";
 static const char *CALS_NOTI_CALENDAR_CHANGED="/opt/data/calendar-svc/.CALENDAR_SVC_CALENDAR_CHANGED";
 
+#ifdef CALS_IPC_SERVER
+static __thread int transaction_cnt = 0;
+static __thread int transaction_ver = 0;
+static __thread bool version_up = false;
+
+static __thread bool event_change=false;
+static __thread bool todo_change=false;
+static __thread bool calendar_change=false;
+#else
 static int transaction_cnt = 0;
 static int transaction_ver = 0;
 static bool version_up = false;
@@ -52,6 +65,7 @@ static bool version_up = false;
 static bool event_change=false;
 static bool todo_change=false;
 static bool calendar_change=false;
+#endif
 
 static inline void _cals_notify_event_change(void)
 {
@@ -330,9 +344,10 @@ inline cals_updated* cals_updated_schedule_add_mempool(void)
        int i;
        cals_updated *mempool;
 
-       mempool = calloc(CALS_MALLOC_DEFAULT_NUM, sizeof(cals_updated));
-       for (i=0;i<CALS_MALLOC_DEFAULT_NUM-1;i++)
-               mempool[i].next = &mempool[i+1];
+       mempool = calloc(1, sizeof(cals_updated));
+//     for (i = 0; i < CALS_MALLOC_DEFAULT_NUM-1; i++) {
+//             mempool[i].next = &mempool[i+1];
+//     }
        return mempool;
 }
 
@@ -344,7 +359,8 @@ inline int cals_updated_schedule_free_mempool(cals_updated *mempool)
 
        memseg = mempool;
        while (memseg) {
-               tmp = memseg[CALS_MALLOC_DEFAULT_NUM-1].next;
+               tmp = memseg->next;
+//             tmp = memseg[CALS_MALLOC_DEFAULT_NUM-1].next;
                free(memseg);
                memseg = tmp;
        }