tizen 2.3.1 release tizen_2.3.1 submit/tizen_2.3.1/20150915.081705 tizen_2.3.1_release
authorjk7744.park <jk7744.park@samsung.com>
Tue, 8 Sep 2015 13:32:51 +0000 (22:32 +0900)
committerjk7744.park <jk7744.park@samsung.com>
Tue, 8 Sep 2015 13:32:51 +0000 (22:32 +0900)
212 files changed:
.CALENDAR_SVC_IPC_READY [new file with mode: 0644]
CMakeLists.txt
LICENSE.APLv2 [moved from LICENSE with 97% similarity]
NOTICE
calendar-service.manifest [new file with mode: 0644]
calendar-service.pc.in [deleted file]
calendar.pc [deleted file]
client/CMakeLists.txt [new file with mode: 0755]
client/cal_client_db.c [new file with mode: 0644]
client/cal_client_ipc.c [new file with mode: 0644]
client/cal_client_ipc.h [new file with mode: 0644]
client/cal_client_reminder.c [new file with mode: 0644]
client/cal_client_reminder.h [moved from src/cals-inotify.h with 56% similarity, mode: 0644]
client/calendar-service2.pc.in [new file with mode: 0644]
common/cal_filter.c [new file with mode: 0644]
common/cal_filter.h [moved from src/cals-struct.h with 67% similarity, mode: 0644]
common/cal_inotify.c [new file with mode: 0644]
common/cal_inotify.h [new file with mode: 0644]
common/cal_internal.h [moved from include/cals-internal.h with 52% similarity, mode: 0644]
common/cal_list.c [new file with mode: 0644]
common/cal_list.h [new file with mode: 0644]
common/cal_mutex.c [new file with mode: 0644]
common/cal_mutex.h [moved from test/timetest.h with 59% similarity]
common/cal_query.c [new file with mode: 0644]
common/cal_query.h [moved from test/test-log.h with 51% similarity]
common/cal_record.c [new file with mode: 0644]
common/cal_record.h [new file with mode: 0644]
common/cal_record_alarm.c [new file with mode: 0644]
common/cal_record_attendee.c [new file with mode: 0644]
common/cal_record_calendar.c [new file with mode: 0644]
common/cal_record_event.c [new file with mode: 0644]
common/cal_record_extended.c [new file with mode: 0644]
common/cal_record_instance_allday.c [new file with mode: 0644]
common/cal_record_instance_allday_extended.c [new file with mode: 0644]
common/cal_record_instance_normal.c [new file with mode: 0644]
common/cal_record_instance_normal_extended.c [new file with mode: 0644]
common/cal_record_search.c [new file with mode: 0644]
common/cal_record_timezone.c [new file with mode: 0644]
common/cal_record_todo.c [new file with mode: 0644]
common/cal_record_updated_info.c [new file with mode: 0644]
common/cal_time.cpp [new file with mode: 0644]
common/cal_time.h [new file with mode: 0644]
common/cal_typedef.h [new file with mode: 0755]
common/cal_vcalendar.c [new file with mode: 0644]
common/cal_vcalendar.h [moved from src/cals-alarm.h with 52% similarity, mode: 0644]
common/cal_vcalendar_make.c [new file with mode: 0644]
common/cal_vcalendar_make.h [new file with mode: 0644]
common/cal_vcalendar_parse.c [new file with mode: 0644]
common/cal_vcalendar_parse.h [new file with mode: 0644]
common/cal_view.c [new file with mode: 0644]
common/cal_view.h [new file with mode: 0644]
common/ipc/cal_ipc.h [new file with mode: 0644]
common/ipc/cal_ipc_marshal.c [new file with mode: 0644]
common/ipc/cal_ipc_marshal.h [new file with mode: 0644]
common/ipc/cal_ipc_marshal_alarm.c [new file with mode: 0644]
common/ipc/cal_ipc_marshal_attendee.c [new file with mode: 0644]
common/ipc/cal_ipc_marshal_calendar.c [new file with mode: 0644]
common/ipc/cal_ipc_marshal_event.c [new file with mode: 0644]
common/ipc/cal_ipc_marshal_extended.c [new file with mode: 0644]
common/ipc/cal_ipc_marshal_instance_allday.c [new file with mode: 0644]
common/ipc/cal_ipc_marshal_instance_allday_extended.c [new file with mode: 0755]
common/ipc/cal_ipc_marshal_instance_normal.c [new file with mode: 0644]
common/ipc/cal_ipc_marshal_instance_normal_extended.c [new file with mode: 0755]
common/ipc/cal_ipc_marshal_search.c [new file with mode: 0644]
common/ipc/cal_ipc_marshal_timezone.c [new file with mode: 0644]
common/ipc/cal_ipc_marshal_todo.c [new file with mode: 0644]
common/ipc/cal_ipc_marshal_updated_info.c [new file with mode: 0644]
debian/changelog [deleted file]
debian/compat [deleted file]
debian/control [deleted file]
debian/copyright [deleted file]
debian/dirs [deleted file]
debian/docs [deleted file]
debian/libslp-calendar-0.install.in [deleted file]
debian/libslp-calendar-0.postinst [deleted file]
debian/libslp-calendar-dev.install.in [deleted file]
debian/rules [deleted file]
doc/calendar_doc.h [new file with mode: 0644]
doc/images/alarm_process.png [new file with mode: 0755]
doc/images/calendar_model.png [new file with mode: 0755]
doc/images/entities.png [new file with mode: 0755]
doc/images/properties.png [new file with mode: 0755]
doc/images/view_db.png [new file with mode: 0755]
doc/images/view_property.png [new file with mode: 0755]
include/calendar-svc-errors.h [deleted file]
include/calendar-svc-provider.h [deleted file]
include/calendar-svc-struct.h [deleted file]
include/calendar.h [new file with mode: 0644]
include/calendar_db.h [new file with mode: 0644]
include/calendar_errors.h [new file with mode: 0644]
include/calendar_filter.h [new file with mode: 0644]
include/calendar_internal.h [new file with mode: 0644]
include/calendar_list.h [new file with mode: 0644]
include/calendar_query.h [new file with mode: 0644]
include/calendar_record.h [new file with mode: 0644]
include/calendar_reminder.h [new file with mode: 0644]
include/calendar_service.h [new file with mode: 0644]
include/calendar_types.h [new file with mode: 0644]
include/calendar_vcalendar.h [new file with mode: 0644]
include/calendar_view.h [new file with mode: 0644]
include/cals-db-info.h [deleted file]
native/CMakeLists.txt [new file with mode: 0755]
native/cal_access_control.c [new file with mode: 0644]
native/cal_access_control.h [new file with mode: 0644]
native/cal_calendar.c [new file with mode: 0644]
native/cal_db.c [new file with mode: 0755]
native/cal_db.h [new file with mode: 0644]
native/cal_db_alarm.c [new file with mode: 0644]
native/cal_db_alarm.h [new file with mode: 0644]
native/cal_db_attendee.c [new file with mode: 0644]
native/cal_db_attendee.h [new file with mode: 0644]
native/cal_db_calendar.c [new file with mode: 0644]
native/cal_db_calendar.h [new file with mode: 0644]
native/cal_db_event.c [new file with mode: 0644]
native/cal_db_event.h [new file with mode: 0644]
native/cal_db_extended.c [new file with mode: 0644]
native/cal_db_extended.h [new file with mode: 0644]
native/cal_db_instance.c [new file with mode: 0644]
native/cal_db_instance.h [new file with mode: 0644]
native/cal_db_instance_helper.c [new file with mode: 0755]
native/cal_db_instance_helper.h [new file with mode: 0755]
native/cal_db_plugin_alarm.c [new file with mode: 0644]
native/cal_db_plugin_attendee.c [new file with mode: 0644]
native/cal_db_plugin_calendar.c [new file with mode: 0644]
native/cal_db_plugin_event.c [new file with mode: 0644]
native/cal_db_plugin_extended.c [new file with mode: 0644]
native/cal_db_plugin_instance_allday.c [new file with mode: 0644]
native/cal_db_plugin_instance_allday_extended.c [new file with mode: 0755]
native/cal_db_plugin_instance_normal.c [new file with mode: 0644]
native/cal_db_plugin_instance_normal_extended.c [new file with mode: 0755]
native/cal_db_plugin_search.c [new file with mode: 0644]
native/cal_db_plugin_timezone.c [new file with mode: 0644]
native/cal_db_plugin_todo.c [new file with mode: 0644]
native/cal_db_query.c [new file with mode: 0644]
native/cal_db_query.h [new file with mode: 0644]
native/cal_db_rrule.c [new file with mode: 0644]
native/cal_db_rrule.h [new file with mode: 0644]
native/cal_db_util.c [new file with mode: 0644]
native/cal_db_util.h [new file with mode: 0644]
native/cal_reminder.c [new file with mode: 0644]
native/cal_service.h [new file with mode: 0644]
packaging/calendar-service.spec [new file with mode: 0644]
packaging/calendar-serviced.service [new file with mode: 0644]
packaging/calendar-serviced.socket [new file with mode: 0644]
packaging/libslp-calendar.spec [deleted file]
schema/CMakeLists.txt
schema/db-gen/Makefile [new file with mode: 0755]
schema/generator.sh
schema/header-gen/schema-header-gen.c
schema/initdb.c
schema/schema.sql
server/CMakeLists.txt [new file with mode: 0755]
server/cal_server.c [new file with mode: 0644]
server/cal_server_alarm.c [new file with mode: 0644]
server/cal_server_alarm.h [new file with mode: 0644]
server/cal_server_calendar_delete.c [new file with mode: 0644]
server/cal_server_calendar_delete.h [new file with mode: 0644]
server/cal_server_contacts.c [new file with mode: 0644]
server/cal_server_contacts.h [new file with mode: 0644]
server/cal_server_ipc.c [new file with mode: 0644]
server/cal_server_ipc.h [new file with mode: 0644]
server/cal_server_reminder.c [new file with mode: 0644]
server/cal_server_reminder.h [new file with mode: 0644]
server/cal_server_schema.c [new file with mode: 0644]
server/cal_server_schema.h [new file with mode: 0644]
server/cal_server_update.c [new file with mode: 0644]
server/cal_server_update.h [new file with mode: 0644]
src/cals-alarm.c [deleted file]
src/cals-calendar.c [deleted file]
src/cals-calendar.h [deleted file]
src/cals-db.c [deleted file]
src/cals-db.h [deleted file]
src/cals-event.c [deleted file]
src/cals-ical.c [deleted file]
src/cals-ical.h [deleted file]
src/cals-inotify.c [deleted file]
src/cals-instance.c [deleted file]
src/cals-instance.h [deleted file]
src/cals-provider.c [deleted file]
src/cals-schedule.c [deleted file]
src/cals-schedule.h [deleted file]
src/cals-sqlite.c [deleted file]
src/cals-sqlite.h [deleted file]
src/cals-struct.c [deleted file]
src/cals-time.c [deleted file]
src/cals-time.h [deleted file]
src/cals-todo.c [deleted file]
src/cals-typedef.h [deleted file]
src/cals-utils.c [deleted file]
src/cals-utils.h [deleted file]
test/Makefile [deleted file]
test/allday.c [deleted file]
test/calendar-test.c [deleted file]
test/eve-add.c [deleted file]
test/eve-del.c [deleted file]
test/eve-period.c [deleted file]
test/eve-see.c [deleted file]
test/ical-export.c [deleted file]
test/ical-import.c [deleted file]
test/ical-read.c [deleted file]
test/ical-write.c [deleted file]
test/instance-del.c [deleted file]
test/list.c [deleted file]
test/period.c [deleted file]
test/recur-add.c [deleted file]
test/schedule-test.c [deleted file]
test/test-alarm.c [deleted file]
test/timetest.c [deleted file]
test/todo-add.c [deleted file]
test/todo-period.c [deleted file]
test/utime.h [deleted file]
test/versiontest.c [deleted file]

diff --git a/.CALENDAR_SVC_IPC_READY b/.CALENDAR_SVC_IPC_READY
new file mode 100644 (file)
index 0000000..e69de29
index 041d291..8e3906e 100755 (executable)
@@ -1,12 +1,7 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(calendar-service C)
+PROJECT(calendar-service C CXX)
 
-#IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-#      SET(CMAKE_BUILD_TYPE "Release")
-#ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-#MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
-
-SET(DEST_INCLUDE_DIR "include/calendar-svc")
+SET(DEST_INCLUDE_DIR "include/calendar-service")
 SET(SRC_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include")
 
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
@@ -14,51 +9,42 @@ SET(EXEC_PREFIX "\${prefix}")
 SET(LIBDIR "\${prefix}/lib")
 SET(INCLUDEDIR "\${prefix}/${DEST_INCLUDE_DIR}")
 SET(VERSION_MAJOR 0)
-SET(VERSION "${VERSION_MAJOR}.1.12")
+SET(VERSION "${VERSION_MAJOR}.1.126")
 
 #INCLUDE_DIRECTORIES(${SRC_INCLUDE_DIR})
 SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -I${CMAKE_SOURCE_DIR}/include")
 
-FILE(GLOB SRCS src/*.c)
-
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED glib-2.0 sqlite3 vconf dlog db-util alarm-service icu-i18n appsvc)
+pkg_check_modules(pkgs REQUIRED
+       glib-2.0
+       sqlite3
+       vconf
+       alarm-service
+       icu-i18n
+       contacts-service2
+       security-server
+       capi-appfw-package-manager
+       )
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fdata-sections -ffunction-sections -Wl,--gc-sections")
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
 #SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-#SET(CMAKE_C_FLAGS_RELEASE "-mabi=aapcs-linux -march=armv7-a -msoft-float -O2")
 
 ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
 
-ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
-SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
-SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS})
-
-CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
-SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc;schema/schema.h")
-
-INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib)
-INSTALL(FILES ${PROJECT_NAME}.pc DESTINATION lib/pkgconfig)
-
-FILE(GLOB HEADER_FILES ${SRC_INCLUDE_DIR}/calendar-svc*.h)
-INSTALL(FILES ${HEADER_FILES} DESTINATION ${DEST_INCLUDE_DIR})
+#header
+FILE(GLOB HEADER_FILES ${SRC_INCLUDE_DIR}/calendar*.h)
+INSTALL(FILES ${HEADER_FILES} DESTINATION ${INCLUDEDIR}2)
 
 FILE(GLOB NOTI_FILES ${CMAKE_SOURCE_DIR}/.CALENDAR_SVC_*_CHANGED)
-INSTALL(FILES ${NOTI_FILES} DESTINATION /opt/data/calendar-svc)
-
-# for immigration
-SET(IMMIGRATION "calendar")
-SET(OLD_DEST_INCLUDE_DIR "include/calendar")
-INSTALL(FILES ${IMMIGRATION}.pc DESTINATION lib/pkgconfig)
-INSTALL(FILES ${SRC_INCLUDE_DIR}/calendar-svc-provider.h DESTINATION ${OLD_DEST_INCLUDE_DIR})
-INSTALL(FILES ${SRC_INCLUDE_DIR}/calendar-svc-struct.h DESTINATION ${OLD_DEST_INCLUDE_DIR})
-INSTALL(FILES ${SRC_INCLUDE_DIR}/calendar-svc-errors.h DESTINATION ${OLD_DEST_INCLUDE_DIR})
+INSTALL(FILES ${NOTI_FILES} DESTINATION /opt/usr/data/calendar-svc)
 
 ADD_SUBDIRECTORY(schema)
+ADD_SUBDIRECTORY(client)
+ADD_SUBDIRECTORY(server)
similarity index 97%
rename from LICENSE
rename to LICENSE.APLv2
index bae7f54..311e5ba 100644 (file)
--- a/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
+Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.\r
 \r
                                  Apache License\r
                            Version 2.0, January 2004\r
diff --git a/NOTICE b/NOTICE
index 4c49449..d34af37 100644 (file)
--- a/NOTICE
+++ b/NOTICE
@@ -1 +1 @@
-Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
diff --git a/calendar-service.manifest b/calendar-service.manifest
new file mode 100644 (file)
index 0000000..979dc01
--- /dev/null
@@ -0,0 +1,36 @@
+<manifest>
+       <define>
+               <domain name="calendar-service"/>
+               <provide>
+                       <label name="calendar-service::initdb" />
+                       <label name="calendar-service::db" />
+                       <label name="calendar-service::svc" />
+               </provide>
+               <request>
+                       <smack request="calendar-service::initdb" type="rwxatl"/>
+                       <smack request="calendar-service::db" type="rwxatl"/>
+                       <smack request="calendar-service::svc" type="rwxatl"/>
+                       <smack request="sys-assert::core" type="rwxat"/>
+                       <smack request="contacts-service::svc" type="rw"/>
+                       <smack request="pkgmgr" type="r"/>
+                       <smack request="pkgmgr::db" type="rw"/>
+                       <smack request="libaccounts-svc" type="r"/>
+                       <smack request="libaccounts-svc::db" type="rl"/>
+                       <smack request="libaccounts-svc::check_read" type="r"/>
+                       <smack request="alarm-server::alarm" type="rw"/>
+                       <smack request="security-server::api-cookie-check" type="w"/>
+               </request>
+       </define>
+       <assign>
+               <filesystem path="/usr/lib/*" label="_" exec_label="none"/>
+               <filesystem path="/opt/usr/dbspace/.calendar-svc.db" label="calendar-service::db" />
+               <filesystem path="/opt/usr/dbspace/.calendar-svc.db-journal" label="calendar-service::db" />
+               <filesystem path="/opt/usr/data/calendar-svc/.CALENDAR_SVC_CALENDAR_CHANGED" label="calendar-service::svc" />
+               <filesystem path="/opt/usr/data/calendar-svc/.CALENDAR_SVC_EVENT_CHANGED" label="calendar-service::svc" />
+               <filesystem path="/opt/usr/data/calendar-svc/.CALENDAR_SVC_TODO_CHANGED" label="calendar-service::svc" />
+               <filesystem path="/opt/usr/data/calendar-svc/.CALENDAR_SVC_IPC_READY" label="calendar-service::svc" />
+       </assign>
+       <request>
+               <domain name="calendar-service" />
+       </request>
+</manifest>
diff --git a/calendar-service.pc.in b/calendar-service.pc.in
deleted file mode 100755 (executable)
index afff9e8..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-# Package Information for pkg-config
-
-prefix=@PREFIX@
-exec_prefix=@EXEC_PREFIX@
-libdir=@LIBDIR@
-includedir=@INCLUDEDIR@
-
-Name: @PROJECT_NAME@
-Description: @PROJECT_NAME@ library
-Version: @VERSION@
-Requires: glib-2.0 alarm-service
-Libs: -L${libdir} -l@PROJECT_NAME@
-Cflags: -I${includedir}
diff --git a/calendar.pc b/calendar.pc
deleted file mode 100755 (executable)
index 2b4d600..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-# Package Information for pkg-config
-
-prefix=/usr
-exec_prefix=${prefix}
-libdir=${prefix}/lib
-includedir=${prefix}/include/calendar-svc
-
-Name: calendar-service
-Description: calendar-service library
-Version: 0.1.8
-Requires: glib-2.0 alarm-service
-Libs: -L${libdir} -lcalendar-service
-Cflags: -I${includedir}
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..2ae9874
--- /dev/null
@@ -0,0 +1,86 @@
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/client)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common/ipc)
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+
+SET(INC_DIR ${CMAKE_SOURCE_DIR}/include)
+
+SET(CALSVC2 calendar-service2)
+
+SET(SRCS
+       cal_client_ipc.c
+       cal_client_db.c
+    cal_client_reminder.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_alarm.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_attendee.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_calendar.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_event.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_instance_allday.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_instance_allday_extended.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_instance_normal.c
+        ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_instance_normal_extended.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_search.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_timezone.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_todo.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_updated_info.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_extended.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record.c
+    ${CMAKE_SOURCE_DIR}/common/cal_record_calendar.c
+    ${CMAKE_SOURCE_DIR}/common/cal_record_event.c
+    ${CMAKE_SOURCE_DIR}/common/cal_record_todo.c
+    ${CMAKE_SOURCE_DIR}/common/cal_record_attendee.c
+    ${CMAKE_SOURCE_DIR}/common/cal_record_alarm.c
+    ${CMAKE_SOURCE_DIR}/common/cal_record_search.c
+    ${CMAKE_SOURCE_DIR}/common/cal_record_timezone.c
+    ${CMAKE_SOURCE_DIR}/common/cal_record_updated_info.c
+    ${CMAKE_SOURCE_DIR}/common/cal_record_instance_normal.c
+    ${CMAKE_SOURCE_DIR}/common/cal_record_instance_allday.c
+    ${CMAKE_SOURCE_DIR}/common/cal_record_instance_normal_extended.c
+    ${CMAKE_SOURCE_DIR}/common/cal_record_instance_allday_extended.c
+    ${CMAKE_SOURCE_DIR}/common/cal_record_extended.c
+    ${CMAKE_SOURCE_DIR}/common/cal_view.c
+    ${CMAKE_SOURCE_DIR}/common/cal_filter.c
+    ${CMAKE_SOURCE_DIR}/common/cal_query.c
+    ${CMAKE_SOURCE_DIR}/common/cal_inotify.c
+    ${CMAKE_SOURCE_DIR}/common/cal_list.c
+    ${CMAKE_SOURCE_DIR}/common/cal_time.cpp
+    ${CMAKE_SOURCE_DIR}/common/cal_vcalendar.c
+    ${CMAKE_SOURCE_DIR}/common/cal_vcalendar_make.c
+    ${CMAKE_SOURCE_DIR}/common/cal_vcalendar_parse.c
+    ${CMAKE_SOURCE_DIR}/common/cal_mutex.c
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(service2_pkgs REQUIRED
+       pims-ipc
+       dlog
+       capi-base-common
+       )
+
+FOREACH(flag ${service2_pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(service2_pkgs_LDFLAGS "${pkgs_LDFLAGS} ${service2_pkgs_LDFLAGS}")
+
+ADD_DEFINITIONS("-DCAL_IPC_CLIENT")
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+
+#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+ADD_LIBRARY(${CALSVC2} SHARED ${SRCS})
+SET_TARGET_PROPERTIES(${CALSVC2} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${CALSVC2} PROPERTIES VERSION ${VERSION})
+TARGET_LINK_LIBRARIES(${CALSVC2} ${service2_pkgs_LDFLAGS})
+
+INSTALL(TARGETS ${CALSVC2} DESTINATION lib)
+
+#pc
+CONFIGURE_FILE(${CALSVC2}.pc.in ${CALSVC2}.pc @ONLY)
+INSTALL(FILES ${CALSVC2}.pc DESTINATION lib/pkgconfig)
+
diff --git a/client/cal_client_db.c b/client/cal_client_db.c
new file mode 100644 (file)
index 0000000..92de12a
--- /dev/null
@@ -0,0 +1,2436 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>     //calloc
+#include <pims-ipc.h>
+#include <glib-object.h>    //g_type_init
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "calendar_service.h"
+#include "calendar_db.h"
+#include "calendar_types.h"
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_inotify.h"
+#include "cal_view.h"
+#include "cal_record.h"
+#include "cal_list.h"
+#include "cal_mutex.h"
+
+#include "cal_ipc.h"
+#include "cal_ipc_marshal.h"
+
+#include "cal_client_ipc.h"
+
+typedef struct {
+       calendar_db_result_cb callback;
+       void *user_data;
+}cal_client_db_async_userdata_s;
+
+typedef struct {
+       calendar_db_insert_result_cb callback;
+       void *user_data;
+}cal_client_db_async_insert_userdata_s;
+
+#define CAL_IPC_DATA_FREE(ptr) \
+       do { \
+               if (ptr) \
+               pims_ipc_data_destroy(ptr); \
+               ptr = NULL; \
+       } while(0)
+
+#define __CAL_CLIENT_ACCESS_MAX 10
+#define __CAL_CLIENT_ALLOW_USEC 25000
+
+#define CAL_LIMIT_ACCESS_FRONT(uri) \
+       int is_schedule = 0; \
+do { \
+       if (!strncmp(uri, CALENDAR_VIEW_EVENT, strlen(CALENDAR_VIEW_EVENT))) \
+       { \
+               is_schedule = 1; \
+               struct timeval hold = {0}; \
+               struct timeval diff = {0}; \
+               gettimeofday(&hold, NULL); \
+               timersub(&hold, &__g_release_time, &diff); \
+               DBG("%ld.%ld sec", diff.tv_sec, diff.tv_usec); \
+               if (diff.tv_sec / 1000 == 0 && diff.tv_usec < __CAL_CLIENT_ALLOW_USEC) \
+               { \
+                       if (__g_access_count < __CAL_CLIENT_ACCESS_MAX) \
+                       { \
+                               __g_access_count++; \
+                               DBG("--count (%d)", __g_access_count); \
+                       } \
+                       else \
+                       { \
+                               DBG("--sleep"); \
+                               usleep(200000); \
+                               __g_access_count = 0; \
+                               timerclear(&__g_release_time); \
+                       } \
+               } \
+               else \
+               { \
+                       DBG("--reset"); \
+                       __g_access_count = 0; \
+                       timerclear(&__g_release_time); \
+               } \
+       } \
+} while(0)
+
+#define CAL_LIMIT_ACCESS_BACK \
+       do { \
+               if (is_schedule) \
+               { \
+                       gettimeofday(&__g_release_time, NULL); \
+               } \
+       } while(0)
+
+
+static int __g_access_count;
+static struct timeval __g_release_time;
+
+
+void __cal_client_db_insert_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata);
+void __cal_client_db_update_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata);
+void __cal_client_db_delete_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata);
+void __cal_client_db_insert_vcalendars_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata);
+void __cal_client_db_replace_vcalendars_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata);
+void __cal_client_db_replace_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata);
+
+void __cal_client_db_insert_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata)
+{
+       cal_client_db_async_insert_userdata_s *sync_data = (cal_client_db_async_insert_userdata_s *)userdata;
+       int ret = CALENDAR_ERROR_NONE;
+
+       int count = 0;
+       int *id = 0;
+
+       if (sync_data == NULL)
+       {
+               ERR("sync_data is NULL");
+               return;
+       }
+
+       if (data_out) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(data_out,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int i=0;
+                       unsigned int size = 0;
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(data_out,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+
+                       ret_pims = pims_ipc_data_get(data_out,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               goto RETURN_PIMS;
+                       }
+                       count = *(int*)ret_pims;
+                       id = calloc(1, sizeof(int)*count);
+                       if (NULL == id) {
+                               ERR("calloc() Fail");
+                               count = 0;
+                               goto RETURN_PIMS;
+                       }
+                       for(i = 0; i < count; i++) {
+                               ret_pims = pims_ipc_data_get(data_out,&size);
+                               if (NULL == ret_pims) {
+                                       ERR("pims_ipc_data_get() Fail");
+                                       goto RETURN_PIMS;
+                               }
+                               id[i] = *(unsigned int*)ret_pims;
+                       }
+               }
+       } else {
+               ret = CALENDAR_ERROR_IPC;
+               ERR("async cb is no data");
+       }
+
+       if (sync_data->callback)
+               sync_data->callback(ret, id, count, sync_data->user_data);
+
+       _cal_inotify_call_pending_callback();
+
+RETURN_PIMS:
+       CAL_FREE(id);
+       CAL_FREE(sync_data);
+       return ;
+}
+
+void __cal_client_db_update_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata)
+{
+       cal_client_db_async_userdata_s *sync_data = (cal_client_db_async_userdata_s *)userdata;
+       int ret = CALENDAR_ERROR_NONE;
+
+       if (sync_data == NULL)
+       {
+               ERR("sync_data is NULL");
+               return;
+       }
+
+       if (data_out) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(data_out,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(data_out,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+               }
+       } else {
+               ret = CALENDAR_ERROR_IPC;
+               ERR("async cb is no data");
+       }
+
+       if (sync_data->callback)
+       {
+               sync_data->callback(ret, sync_data->user_data);
+       }
+
+       _cal_inotify_call_pending_callback();
+
+RETURN_PIMS:
+       CAL_FREE(sync_data);
+       return ;
+}
+void __cal_client_db_delete_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata)
+{
+       cal_client_db_async_userdata_s *sync_data = (cal_client_db_async_userdata_s *)userdata;
+       int ret = CALENDAR_ERROR_NONE;
+
+       if (sync_data == NULL)
+       {
+               ERR("sync_data is NULL");
+               return;
+       }
+
+       if (data_out) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(data_out,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(data_out,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+               }
+       } else {
+               ret = CALENDAR_ERROR_IPC;
+               ERR("async cb is no data");
+       }
+
+       if (sync_data->callback)
+               sync_data->callback(ret, sync_data->user_data);
+
+       _cal_inotify_call_pending_callback();
+
+RETURN_PIMS:
+       CAL_FREE(sync_data);
+       return ;
+}
+
+void __cal_client_db_insert_vcalendars_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata)
+{
+       cal_client_db_async_insert_userdata_s *sync_data = (cal_client_db_async_insert_userdata_s *)userdata;
+       int ret = CALENDAR_ERROR_NONE;
+
+       int count = 0;
+       int *id = 0;
+
+       if (sync_data == NULL)
+       {
+               ERR("sync_data is NULL");
+               return;
+       }
+
+       if (data_out) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(data_out,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int i=0;
+                       unsigned int size = 0;
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(data_out,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+
+                       ret_pims = pims_ipc_data_get(data_out,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               goto RETURN_PIMS;
+                       }
+                       count = *(int*)ret_pims;
+                       id = calloc(1, sizeof(int)*count);
+                       if (id) {
+                               for(i = 0; i < count; i++) {
+                                       ret_pims = pims_ipc_data_get(data_out,&size);
+                                       if (NULL == ret_pims) {
+                                               ERR("pims_ipc_data_get() Fail");
+                                               goto RETURN_PIMS;
+                                       }
+                                       id[i] = *(unsigned int*)ret_pims;
+                               }
+                       } else {
+                               count = 0;
+                       }
+               }
+       } else {
+               ret = CALENDAR_ERROR_IPC;
+               ERR("async cb is no data");
+       }
+
+       if (sync_data->callback)
+               sync_data->callback(ret, id, count, sync_data->user_data);
+
+       _cal_inotify_call_pending_callback();
+
+RETURN_PIMS:
+       CAL_FREE(id);
+       CAL_FREE(sync_data);
+       return ;
+}
+
+void __cal_client_db_replace_vcalendars_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata)
+{
+       cal_client_db_async_userdata_s *sync_data = (cal_client_db_async_userdata_s *)userdata;
+       int ret = CALENDAR_ERROR_NONE;
+
+       if (sync_data == NULL)
+       {
+               ERR("sync_data is NULL");
+               return;
+       }
+
+       if (data_out) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(data_out,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(data_out,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+               }
+       } else {
+               ret = CALENDAR_ERROR_IPC;
+               ERR("async cb is no data");
+       }
+
+       if (sync_data->callback)
+               sync_data->callback(ret, sync_data->user_data);
+
+       _cal_inotify_call_pending_callback();
+
+RETURN_PIMS:
+       CAL_FREE(sync_data);
+       return ;
+}
+
+void __cal_client_db_replace_records_cb(pims_ipc_h ipc, pims_ipc_data_h data_out, void *userdata)
+{
+       cal_client_db_async_userdata_s *sync_data = (cal_client_db_async_userdata_s *)userdata;
+       int ret = CALENDAR_ERROR_NONE;
+
+       if (sync_data == NULL)
+       {
+               ERR("sync_data is NULL");
+               return;
+       }
+
+       if (data_out) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(data_out,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(data_out,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+               }
+       } else {
+               ret = CALENDAR_ERROR_IPC;
+               ERR("async cb is no data");
+       }
+
+       if (sync_data->callback)
+               sync_data->callback(ret, sync_data->user_data);
+
+       _cal_inotify_call_pending_callback();
+
+RETURN_PIMS:
+       CAL_FREE(sync_data);
+       return ;
+}
+
+API int calendar_db_insert_record( calendar_record_h record, int* id )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(record==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"record is NULL");
+
+       CAL_RECORD_RESET_COMMON((cal_record_s*)record);
+
+       cal_record_s *rec = (cal_record_s *)record;
+       CAL_LIMIT_ACCESS_FRONT(rec->view_uri);
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       ret = _cal_ipc_marshal_record(record,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_INSERT_RECORD, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               //int id = 0;
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(outdata,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               pims_ipc_data_destroy(outdata);
+                               ret = CALENDAR_ERROR_IPC;
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+                       int out_id = 0;
+                       ret_pims = pims_ipc_data_get(outdata,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               pims_ipc_data_destroy(outdata);
+                               ret = CALENDAR_ERROR_IPC;
+                               goto RETURN_PIMS;
+                       }
+                       out_id = *(int*)ret_pims;
+                       if (id)
+                               *id = out_id;
+               }
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       CAL_LIMIT_ACCESS_BACK;
+       return ret;
+}
+
+API int calendar_db_get_record( const char* view_uri, int id, calendar_record_h* out_record )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(view_uri==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"view_uri is NULL");
+       retvm_if(id<=0,CALENDAR_ERROR_INVALID_PARAMETER,"id <= 0");
+       retvm_if(out_record==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"record is NULL");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_char(view_uri,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(id,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_GET_RECORD, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       ret = _cal_ipc_unmarshal_record(outdata,out_record);
+               }
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+RETURN_PIMS:
+       return ret;
+}
+
+API int calendar_db_update_record( calendar_record_h record )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(record==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"record is NULL");
+
+       cal_record_s *rec = (cal_record_s *)record;
+       CAL_LIMIT_ACCESS_FRONT(rec->view_uri);
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_record(record,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_UPDATE_RECORD, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(outdata,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               pims_ipc_data_destroy(outdata);
+                               ret = CALENDAR_ERROR_IPC;
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+               }
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       CAL_LIMIT_ACCESS_BACK;
+       return ret;
+}
+
+API int calendar_db_delete_record( const char* view_uri, int id )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(view_uri==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"view_uri is NULL");
+       retvm_if(id<=0,CALENDAR_ERROR_INVALID_PARAMETER,"id <= 0");
+
+       CAL_LIMIT_ACCESS_FRONT(view_uri);
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_char(view_uri,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(id,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_DELETE_RECORD, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(outdata,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               pims_ipc_data_destroy(outdata);
+                               ret = CALENDAR_ERROR_IPC;
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+               }
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       CAL_LIMIT_ACCESS_BACK;
+       return ret;
+}
+
+API int calendar_db_get_all_records( const char* view_uri, int offset, int limit, calendar_list_h* out_list )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(out_list==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"list is NULL");
+       retvm_if(view_uri==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"view_uri is NULL");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+
+       ret = _cal_ipc_marshal_char(view_uri,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(offset,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(limit,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_GET_ALL_RECORDS, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE)
+                       ret = _cal_ipc_unmarshal_list(outdata,out_list);
+
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+}
+
+API int calendar_db_get_records_with_query( calendar_query_h query, int offset, int limit, calendar_list_h* out_list )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(query==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"query is NULL");
+       retvm_if(out_list==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"list is NULL");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_query(query,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(offset,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(limit,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_GET_RECORDS_WITH_QUERY, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE)
+                       ret = _cal_ipc_unmarshal_list(outdata,out_list);
+
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+}
+
+API int calendar_db_clean_after_sync( int calendar_book_id, int calendar_db_version)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(calendar_book_id <= 0,CALENDAR_ERROR_INVALID_PARAMETER,"calendar_book_id < 0");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(calendar_book_id,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(calendar_db_version,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_CLEAN_AFTER_SYNC, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+}
+
+API int calendar_db_get_count( const char* view_uri, int *out_count )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(view_uri==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"view_uri is NULL");
+       retvm_if(out_count==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"count pointer is NULL");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_char(view_uri,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_GET_COUNT, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE)
+                       ret = _cal_ipc_unmarshal_int(outdata,out_count);
+
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+}
+
+API int calendar_db_get_count_with_query( calendar_query_h query, int *out_count )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(query==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"record is NULL");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_query(query,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_GET_COUNT_WITH_QUERY, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE)
+                       ret = _cal_ipc_unmarshal_int(outdata,out_count);
+
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+}
+
+API int calendar_db_insert_records( calendar_list_h record_list, int** record_id_array, int* count)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(record_list==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"list is NULL");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_list(record_list,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       if (_cal_client_ipc_call(CAL_IPC_MODULE,CAL_IPC_SERVER_DB_INSERT_RECORDS,
+                               indata,&outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(outdata,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               pims_ipc_data_destroy(outdata);
+                               ret = CALENDAR_ERROR_IPC;
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+                       goto SET_DATA;
+               }
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+       return ret;
+
+SET_DATA:
+       if (outdata)
+       {
+               int i=0;
+               unsigned int size = 0;
+               int *ids = NULL;
+
+               if (count && record_id_array) {
+                       void *ret_pims = NULL;
+                       ret_pims = pims_ipc_data_get(outdata,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               pims_ipc_data_destroy(outdata);
+                               ret = CALENDAR_ERROR_IPC;
+                               goto RETURN_PIMS;
+                       }
+                       *count = *(int*)ret_pims;
+
+                       if (*count <=0)
+                       {
+                               ERR("count is %d",*count);
+                               count = 0;
+                               pims_ipc_data_destroy(outdata);
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+                       ids = calloc(1, sizeof(int)*(*count));
+                       if(ids == NULL) {
+                               count = 0;
+                               ERR("calloc fail");
+                               pims_ipc_data_destroy(outdata);
+                               return CALENDAR_ERROR_OUT_OF_MEMORY;
+                       }
+                       for(i = 0; i < (*count) ;i++) {
+                               ret_pims = pims_ipc_data_get(outdata,&size);
+                               if (NULL == ret_pims) {
+                                       ERR("pims_ipc_data_get() Fail");
+                                       pims_ipc_data_destroy(outdata);
+                                       free(ids);
+                                       ret = CALENDAR_ERROR_IPC;
+                                       goto RETURN_PIMS;
+                               }
+                               ids[i] = *(int*)ret_pims;
+                       }
+                       *record_id_array = ids;
+               }
+               pims_ipc_data_destroy(outdata);
+       }
+
+RETURN_PIMS:
+       return ret;
+}
+
+API int calendar_db_insert_records_async(calendar_list_h list, calendar_db_insert_result_cb callback, void *user_data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       cal_client_db_async_insert_userdata_s *async_data = NULL;
+       calendar_list_h clone_list = NULL;
+       bool result = false;
+
+       retvm_if(list==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"list is NULL");
+
+       ret = cal_client_ipc_client_check_permission(CAL_PERMISSION_WRITE, &result);
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
+       retvm_if(result == false, CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied (calendar read)");
+
+       ret = _cal_list_clone(list, &clone_list);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_list_clone() failed");
+               return ret;
+       }
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               calendar_list_destroy(clone_list, true);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_list(clone_list,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               calendar_list_destroy(clone_list, true);
+               return ret;
+       }
+
+       async_data = (cal_client_db_async_insert_userdata_s*)malloc(sizeof(cal_client_db_async_insert_userdata_s));
+       if (async_data == NULL)
+       {
+               ERR("malloc fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               calendar_list_destroy(clone_list, true);
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       async_data->callback = callback;
+       async_data->user_data = user_data;
+
+       if (_cal_client_ipc_call_async(CAL_IPC_MODULE,CAL_IPC_SERVER_DB_INSERT_RECORDS,
+                               indata,__cal_client_db_insert_records_cb,async_data) != 0)
+       {
+               ERR("pims_ipc_call_async failed");
+               calendar_list_destroy(clone_list, true);
+               CAL_IPC_DATA_FREE(indata);
+               CAL_FREE(async_data);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       calendar_list_destroy(clone_list, true);
+
+       return ret;
+}
+
+API int calendar_db_update_records( calendar_list_h record_list)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(record_list==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"record is NULL");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_list(record_list,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_UPDATE_RECORDS, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(outdata,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               pims_ipc_data_destroy(outdata);
+                               ret = CALENDAR_ERROR_IPC;
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+               }
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+
+}
+
+API int calendar_db_update_records_async( calendar_list_h list, calendar_db_result_cb callback, void *user_data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       cal_client_db_async_userdata_s *async_data = NULL;
+       calendar_list_h clone_list = NULL;
+       bool result = false;
+
+       retvm_if(list==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"record is NULL");
+
+       ret = cal_client_ipc_client_check_permission(CAL_PERMISSION_WRITE, &result);
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
+       retvm_if(result == false, CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied (calendar read)");
+
+       ret = _cal_list_clone(list, &clone_list);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_list_clone() failed");
+               return ret;
+       }
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               calendar_list_destroy(clone_list, true);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_list(clone_list,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               calendar_list_destroy(clone_list, true);
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       async_data = (cal_client_db_async_userdata_s*)malloc(sizeof(cal_client_db_async_userdata_s));
+       if (async_data == NULL)
+       {
+               ERR("malloc fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               calendar_list_destroy(clone_list, true);
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       async_data->callback = callback;
+       async_data->user_data = user_data;
+
+       if (_cal_client_ipc_call_async(CAL_IPC_MODULE,CAL_IPC_SERVER_DB_UPDATE_RECORDS,
+                               indata,__cal_client_db_update_records_cb,async_data) != 0)
+       {
+               ERR("pims_ipc_call_async failed");
+               calendar_list_destroy(clone_list, true);
+               CAL_IPC_DATA_FREE(indata);
+               CAL_FREE(async_data);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       calendar_list_destroy(clone_list, true);
+       return ret;
+}
+
+API int calendar_db_delete_records(const char* view_uri, int record_id_array[], int count)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+       int i = 0;
+
+       retvm_if(view_uri==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"view_uri is NULL");
+       retvm_if(record_id_array==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"record_id_array is NULL");
+       retvm_if(count<=0,CALENDAR_ERROR_INVALID_PARAMETER,"count <= 0 ");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_char(view_uri,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(count,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       for (i=0;i<count;i++)
+       {
+               ret = _cal_ipc_marshal_int(record_id_array[i],indata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("marshal fail");
+                       CAL_IPC_DATA_FREE(indata);
+                       return ret;
+               }
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_DELETE_RECORDS, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(outdata,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               pims_ipc_data_destroy(outdata);
+                               ret = CALENDAR_ERROR_IPC;
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+               }
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+
+}
+
+API int calendar_db_delete_records_async(const char* view_uri, int ids[], int count, calendar_db_result_cb callback, void *user_data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       int i = 0;
+       cal_client_db_async_userdata_s *async_data = NULL;
+       bool result = false;
+
+       retvm_if(view_uri==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"view_uri is NULL");
+       retvm_if(ids==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"ids is NULL");
+       retvm_if(count <= 0,CALENDAR_ERROR_INVALID_PARAMETER,"count is 0");
+
+       ret = cal_client_ipc_client_check_permission(CAL_PERMISSION_WRITE, &result);
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
+       retvm_if(result == false, CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied (calendar read)");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_char(view_uri,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(count,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       for (i=0;i<count;i++)
+       {
+               ret = _cal_ipc_marshal_int(ids[i],indata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("marshal fail");
+                       CAL_IPC_DATA_FREE(indata);
+                       return ret;
+               }
+       }
+
+       async_data = (cal_client_db_async_userdata_s*)malloc(sizeof(cal_client_db_async_userdata_s));
+       if (async_data == NULL)
+       {
+               ERR("malloc fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       async_data->callback = callback;
+       async_data->user_data = user_data;
+       if (_cal_client_ipc_call_async(CAL_IPC_MODULE,CAL_IPC_SERVER_DB_DELETE_RECORDS,
+                               indata,__cal_client_db_delete_records_cb,async_data) != 0)
+       {
+               ERR("pims_ipc_call_async failed");
+               CAL_IPC_DATA_FREE(indata);
+               CAL_FREE(async_data);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       return ret;
+}
+
+API int calendar_db_get_changes_by_version(const char* view_uri, int calendar_book_id, int calendar_db_version, calendar_list_h* record_list, int* current_calendar_db_version )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(view_uri==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"view_uri is NULL");
+       retvm_if(record_list==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"record_list is NULL");
+       retvm_if(current_calendar_db_version==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"current_calendar_db_version is NULL");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_char(view_uri,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(calendar_book_id,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(calendar_db_version,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_CHANGES_BY_VERSION, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       ret = _cal_ipc_unmarshal_list(outdata,record_list);
+                       if (ret == CALENDAR_ERROR_NONE)
+                               ret = _cal_ipc_unmarshal_int(outdata,current_calendar_db_version);
+               }
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+}
+
+API int calendar_db_get_current_version(int* calendar_db_version)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(calendar_db_version==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"calendar_db_version is null");
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_GET_CURRENT_VERSION, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               return CALENDAR_ERROR_IPC;
+       }
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE)
+                       ret = _cal_ipc_unmarshal_int(outdata,calendar_db_version);
+
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+}
+
+API int calendar_db_add_changed_cb(const char* view_uri, calendar_db_changed_cb callback, void* user_data )
+{
+       CAL_FN_CALL;
+       int ret;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+
+       retv_if(NULL == view_uri || NULL == callback , CALENDAR_ERROR_INVALID_PARAMETER);
+
+       type = _cal_view_get_type(view_uri);
+
+       switch(type)
+       {
+       case CAL_RECORD_TYPE_CALENDAR:
+               ret = _cal_inotify_subscribe(CAL_NOTI_TYPE_CALENDAR, CAL_NOTI_CALENDAR_CHANGED, callback, user_data);
+               break;
+       case CAL_RECORD_TYPE_EVENT:
+               ret = _cal_inotify_subscribe(CAL_NOTI_TYPE_EVENT, CAL_NOTI_EVENT_CHANGED, callback, user_data);
+               break;
+       case CAL_RECORD_TYPE_TODO:
+               ret = _cal_inotify_subscribe(CAL_NOTI_TYPE_TODO, CAL_NOTI_TODO_CHANGED, callback, user_data);
+               break;
+       default:
+               ERR("Invalid view_uri(%s)", view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "_cal_inotify_subscribe() Failed(%d)", ret);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_db_remove_changed_cb( const char* view_uri, calendar_db_changed_cb callback, void* user_data )
+{
+       CAL_FN_CALL;
+       int ret;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+
+       retv_if(NULL == view_uri || NULL == callback , CALENDAR_ERROR_INVALID_PARAMETER);
+
+       type = _cal_view_get_type(view_uri);
+
+       switch(type)
+       {
+       case CAL_RECORD_TYPE_CALENDAR:
+               ret = _cal_inotify_unsubscribe_with_data(CAL_NOTI_CALENDAR_CHANGED, callback, user_data);
+               break;
+       case CAL_RECORD_TYPE_EVENT:
+               ret = _cal_inotify_unsubscribe_with_data(CAL_NOTI_EVENT_CHANGED, callback, user_data);
+               break;
+       case CAL_RECORD_TYPE_TODO:
+               ret = _cal_inotify_unsubscribe_with_data(CAL_NOTI_TODO_CHANGED, callback, user_data);
+               break;
+       default:
+               ERR("Invalid view_uri(%s)", view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "_cal_inotify_unsubscribe_with_data() Failed(%d)", ret);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_db_insert_vcalendars(const char* vcalendar_stream, int **record_id_array, int *count)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+       int i = 0;
+
+       retvm_if(NULL == vcalendar_stream, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_char(vcalendar_stream,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_INSERT_VCALENDARS, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+       CAL_IPC_DATA_FREE(indata);
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(outdata,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               pims_ipc_data_destroy(outdata);
+                               ret = CALENDAR_ERROR_IPC;
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+               }
+
+               if (ret == CALENDAR_ERROR_NONE && count != NULL && record_id_array != NULL) {
+                       int *ids = NULL;
+
+                       ret_pims = pims_ipc_data_get(outdata,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               pims_ipc_data_destroy(outdata);
+                               ret = CALENDAR_ERROR_IPC;
+                               goto RETURN_PIMS;
+                       }
+                       *count = *(int*)ret_pims;
+
+                       ids = (int*)malloc(sizeof(int)*(*count));
+                       if(ids == NULL) {
+                               pims_ipc_data_destroy(outdata);
+                               ERR("malloc fail");
+                               return CALENDAR_ERROR_OUT_OF_MEMORY;
+                       }
+                       for(i = 0; i < (*count); i++) {
+                               ret_pims = pims_ipc_data_get(outdata,&size);
+                               if (NULL == ret_pims) {
+                                       ERR("pims_ipc_data_get() Fail");
+                                       pims_ipc_data_destroy(outdata);
+                                       free(ids);
+                                       ret = CALENDAR_ERROR_IPC;
+                                       goto RETURN_PIMS;
+                               }
+                               ids[i] = *(int*)ret_pims;
+                       }
+                       *record_id_array = ids;
+               }
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+}
+
+API int calendar_db_insert_vcalendars_async(const char* vcalendar_stream, calendar_db_insert_result_cb callback, void *user_data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       cal_client_db_async_insert_userdata_s *async_data = NULL;
+       bool result = false;
+
+       retvm_if(vcalendar_stream==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"list is NULL");
+
+       ret = cal_client_ipc_client_check_permission(CAL_PERMISSION_WRITE, &result);
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
+       retvm_if(result == false, CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied (calendar read)");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_char(vcalendar_stream,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+
+               return ret;
+       }
+
+       async_data = (cal_client_db_async_insert_userdata_s*)malloc(sizeof(cal_client_db_async_insert_userdata_s));
+       if (async_data == NULL)
+       {
+               ERR("malloc fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       async_data->callback = callback;
+       async_data->user_data = user_data;
+
+       if (_cal_client_ipc_call_async(CAL_IPC_MODULE,CAL_IPC_SERVER_DB_INSERT_VCALENDARS,
+                               indata,__cal_client_db_insert_vcalendars_cb,async_data) != 0)
+       {
+               ERR("pims_ipc_call_async failed");
+               CAL_IPC_DATA_FREE(indata);
+               CAL_FREE(async_data);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       return ret;
+}
+
+API int calendar_db_replace_vcalendars(const char* vcalendar_stream, int *record_id_array, int count)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+       int i = 0;
+
+       retvm_if(NULL == vcalendar_stream, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == record_id_array, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(count <= 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_char(vcalendar_stream,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(count,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       for(i=0;i<count;i++)
+       {
+               ret = _cal_ipc_marshal_int(record_id_array[i],indata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("marshal fail");
+                       CAL_IPC_DATA_FREE(indata);
+                       return ret;
+               }
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_REPLACE_VCALENDARS, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+       CAL_IPC_DATA_FREE(indata);
+       if (outdata){
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(outdata,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               pims_ipc_data_destroy(outdata);
+                               ret = CALENDAR_ERROR_IPC;
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+               }
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+}
+
+API int calendar_db_replace_vcalendars_async(const char* vcalendar_stream, int *record_id_array, int count, calendar_db_result_cb callback, void *user_data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       cal_client_db_async_userdata_s *async_data = NULL;
+       int i = 0;
+       bool result = false;
+
+       retvm_if(NULL == vcalendar_stream, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == record_id_array, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(count <= 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = cal_client_ipc_client_check_permission(CAL_PERMISSION_WRITE, &result);
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
+       retvm_if(result == false, CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied (calendar read)");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_char(vcalendar_stream,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(count,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       for(i=0;i<count;i++)
+       {
+               ret = _cal_ipc_marshal_int(record_id_array[i],indata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("marshal fail");
+                       CAL_IPC_DATA_FREE(indata);
+                       return ret;
+               }
+       }
+
+       async_data = (cal_client_db_async_userdata_s*)malloc(sizeof(cal_client_db_async_userdata_s));
+       if (async_data == NULL)
+       {
+               ERR("malloc fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       async_data->callback = callback;
+       async_data->user_data = user_data;
+
+       if (_cal_client_ipc_call_async(CAL_IPC_MODULE,CAL_IPC_SERVER_DB_REPLACE_VCALENDARS,
+                               indata,__cal_client_db_replace_vcalendars_cb,async_data) != 0)
+       {
+               ERR("pims_ipc_call_async failed");
+               CAL_IPC_DATA_FREE(indata);
+               CAL_FREE(async_data);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       return ret;
+}
+
+API int calendar_db_replace_record(calendar_record_h record, int record_id)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(record==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"record is NULL");
+       retvm_if(record_id < 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       cal_record_s *rec = (cal_record_s *)record;
+       CAL_LIMIT_ACCESS_FRONT(rec->view_uri);
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_record(record,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(record_id,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_REPLACE_RECORD, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(outdata,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               pims_ipc_data_destroy(outdata);
+                               ret = CALENDAR_ERROR_IPC;
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+               }
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       CAL_LIMIT_ACCESS_BACK;
+       return ret;
+}
+
+API int calendar_db_replace_records(calendar_list_h record_list, int *record_id_array, int count)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+       int i = 0;
+
+       retvm_if(record_list==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"record is NULL");
+       retvm_if(record_id_array==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"record_id_array is NULL");
+       retvm_if(count <= 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_list(record_list,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(count,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       for(i=0;i<count;i++)
+       {
+               ret = _cal_ipc_marshal_int(record_id_array[i],indata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("marshal fail");
+                       CAL_IPC_DATA_FREE(indata);
+                       return ret;
+               }
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call( CAL_IPC_MODULE, CAL_IPC_SERVER_DB_REPLACE_RECORDS, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE) {
+                       int transaction_ver = 0;
+                       ret_pims = pims_ipc_data_get(outdata,&size);
+                       if (NULL == ret_pims) {
+                               ERR("pims_ipc_data_get() Fail");
+                               pims_ipc_data_destroy(outdata);
+                               ret = CALENDAR_ERROR_IPC;
+                               goto RETURN_PIMS;
+                       }
+                       transaction_ver = *(int*)ret_pims;
+                       _cal_client_ipc_set_change_version(transaction_ver);
+               }
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+}
+
+API int calendar_db_replace_records_async(calendar_list_h record_list, int *record_id_array, int count, calendar_db_result_cb callback, void *user_data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       cal_client_db_async_userdata_s *async_data = NULL;
+       int i = 0;
+       bool result = false;
+
+       retvm_if(NULL == record_list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: list is NULL");
+       retvm_if(NULL == record_id_array, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: id is NULL");
+       retvm_if(count <= 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: count <= 0");
+
+       ret = cal_client_ipc_client_check_permission(CAL_PERMISSION_WRITE, &result);
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
+       retvm_if(result == false, CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied (calendar read)");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_list(record_list,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(count,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       for(i=0;i<count;i++)
+       {
+               ret = _cal_ipc_marshal_int(record_id_array[i],indata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("marshal fail");
+                       CAL_IPC_DATA_FREE(indata);
+                       return ret;
+               }
+       }
+
+       async_data = (cal_client_db_async_userdata_s*)malloc(sizeof(cal_client_db_async_userdata_s));
+       if (async_data == NULL)
+       {
+               ERR("malloc fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       async_data->callback = callback;
+       async_data->user_data = user_data;
+
+       if (_cal_client_ipc_call_async(CAL_IPC_MODULE,CAL_IPC_SERVER_DB_REPLACE_RECORDS,
+                               indata,__cal_client_db_replace_records_cb,async_data) != 0)
+       {
+               ERR("pims_ipc_call_async failed");
+               CAL_IPC_DATA_FREE(indata);
+               CAL_FREE(async_data);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       return ret;
+}
+
+API int calendar_db_get_last_change_version(int* last_version)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       bool result = false;
+       retvm_if(NULL == last_version, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       *last_version = 0;
+
+       ret = cal_client_ipc_client_check_permission(CAL_PERMISSION_READ, &result);
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "cal_client_ipc_client_check_permission() is fail (%d)", ret);
+       retvm_if(result == false, CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied (calendar read)");
+
+       *last_version = _cal_client_ipc_get_change_version();
+       return ret;
+}
+
+API int calendar_db_get_changes_exception_by_version(const char* view_uri, int original_event_id, int calendar_db_version, calendar_list_h* record_list)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retvm_if(view_uri==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"view_uri is NULL");
+       retvm_if(record_list==NULL,CALENDAR_ERROR_INVALID_PARAMETER,"record_list is NULL");
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+       ret = _cal_ipc_marshal_char(view_uri,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(original_event_id,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+       ret = _cal_ipc_marshal_int(calendar_db_version,indata);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("marshal fail");
+               CAL_IPC_DATA_FREE(indata);
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_CHANGES_EXCEPTION, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               if (ret == CALENDAR_ERROR_NONE)
+                       ret = _cal_ipc_unmarshal_list(outdata,record_list);
+
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+}
+
+#ifdef CAL_MEMORY_TEST
+API int calendar_destroy(void)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+
+       // make indata
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL)
+       {
+               ERR("ipc data created fail !");
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+
+       // ipc call
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_DESTROY, indata, &outdata) != 0)
+       {
+               ERR("pims_ipc_call failed");
+               CAL_IPC_DATA_FREE(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       CAL_IPC_DATA_FREE(indata);
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               void *ret_pims = NULL;
+               ret_pims = pims_ipc_data_get(outdata,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       pims_ipc_data_destroy(outdata);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto RETURN_PIMS;
+               }
+               ret = *(int*)ret_pims;
+               pims_ipc_data_destroy(outdata);
+       } else {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+RETURN_PIMS:
+       return ret;
+}
+#endif //#ifdef CAL_MEMORY_TEST
diff --git a/client/cal_client_ipc.c b/client/cal_client_ipc.c
new file mode 100644 (file)
index 0000000..9cddb62
--- /dev/null
@@ -0,0 +1,606 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <unistd.h>
+#include <stdlib.h>     //calloc
+#include <pims-ipc.h>
+#include <glib-object.h> //g_type_init
+#include <security-server.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "calendar_service.h"
+#include "calendar_db.h"
+#include "calendar_types.h"
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_inotify.h"
+#include "cal_view.h"
+#include "cal_record.h"
+#include "cal_list.h"
+#include "cal_mutex.h"
+#include "cal_ipc.h"
+#include "cal_ipc_marshal.h"
+#include "cal_client_ipc.h"
+#include "cal_client_reminder.h"
+
+typedef struct {
+       pims_ipc_h ipc;
+       int change_version;
+} cal_ipc_s;
+
+static int cal_connection_count = 0;
+static TLS int cal_connection_count_thread = 0;
+
+static GHashTable *_cal_ipc_table = NULL;
+static bool _cal_ipc_disconnected = false;
+static int _cal_ipc_disconnected_count = 0;
+
+static inline void _cal_client_ipc_get_pid_str(char *buf, int buf_size)
+{
+       snprintf(buf, buf_size, "%d", getpid());
+}
+
+static inline void _cal_client_ipc_get_tid_str(char *buf, int buf_size)
+{
+       snprintf(buf, buf_size, "%ld", syscall(SYS_gettid));
+}
+
+static void _cal_client_ipc_free(gpointer p)
+{
+       cal_ipc_s *ci = (cal_ipc_s *)p;
+       ret_if(NULL == ci);
+       if (ci->ipc)
+               pims_ipc_destroy(ci->ipc);
+       free(ci);
+}
+
+static int __cal_client_ipc_get_cookie_for_access_control(pims_ipc_data_h *indata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       size_t cookie_size =0;
+       pims_ipc_data_h data;
+
+       cookie_size = security_server_get_cookie_size();
+       retvm_if(cookie_size<=0,CALENDAR_ERROR_NOT_PERMITTED,"get cookie_size fail");
+
+       char cookie[256] = {0,};
+       char *e_cookie = NULL;
+       ret = security_server_request_cookie(cookie, cookie_size);
+       retvm_if(ret<0,CALENDAR_ERROR_NOT_PERMITTED,"get cookie fail");
+
+       data = pims_ipc_data_create(0);
+       retvm_if(data==NULL,CALENDAR_ERROR_OUT_OF_MEMORY,"ipc data created fail!");
+
+       ret = _cal_ipc_marshal_int(cookie_size, data);
+
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("ipc marshal fail");
+               pims_ipc_data_destroy(data);
+               return ret;
+       }
+       e_cookie = g_base64_encode((const guchar *)cookie, cookie_size);
+       if (e_cookie == NULL)
+       {
+               ERR("base64 encode fail");
+               pims_ipc_data_destroy(data);
+               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               return ret;
+       }
+
+       ret = _cal_ipc_marshal_char(e_cookie, data);
+       CAL_FREE(e_cookie);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("ipc marshal fail");
+               pims_ipc_data_destroy(data);
+               return ret;
+       }
+
+       *indata = data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int _cal_client_ipc_connect_server(pims_ipc_h *out_ipc)
+{
+       int ret = 0;
+       retv_if(NULL == out_ipc, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       // ipc create
+       pims_ipc_h ipc = pims_ipc_create(CAL_IPC_SOCKET_PATH);
+       if (NULL == ipc) {
+               if (errno == EACCES) {
+                       ERR("pims_ipc_create() Failed(%d)", CALENDAR_ERROR_PERMISSION_DENIED);
+                       ret = CALENDAR_ERROR_PERMISSION_DENIED;
+                       goto ERROR_RETURN;
+               } else {
+                       ERR("pims_ipc_create() Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+                       ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                       goto ERROR_RETURN;
+               }
+       }
+
+       ret = __cal_client_ipc_get_cookie_for_access_control(&indata);
+       if( ret != CALENDAR_ERROR_NONE)
+               goto ERROR_RETURN;
+
+       // ipc call
+       if (pims_ipc_call(ipc, CAL_IPC_MODULE, CAL_IPC_SERVER_CONNECT, indata, &outdata) != 0) {
+               ERR("pims_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               ret = CALENDAR_ERROR_IPC;
+               goto ERROR_RETURN;
+       }
+
+       pims_ipc_data_destroy(indata);
+       indata = NULL;
+
+       if (outdata) {
+               // check outdata
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               pims_ipc_data_destroy(outdata);
+
+               if (ret != CALENDAR_ERROR_NONE) {
+                       ERR("calendar_connect return (%d)",ret);
+                       goto ERROR_RETURN;
+               }
+       } else {
+               ERR("ipc outdata is NULL");
+               ret = CALENDAR_ERROR_IPC;
+               goto ERROR_RETURN;
+       }
+       *out_ipc = ipc;
+       return ret;
+
+ERROR_RETURN:
+       pims_ipc_destroy(ipc);
+       return ret;
+}
+
+static int _cal_client_ipc_connect(void)
+{
+       int ret = 0;
+       cal_ipc_s *ci = NULL;
+       char ipc_key[1024] = {0};
+       retv_if(_cal_ipc_disconnected, CALENDAR_ERROR_IPC);
+
+       _cal_client_ipc_get_tid_str(ipc_key, sizeof(ipc_key));
+       if (NULL == _cal_ipc_table)
+               _cal_ipc_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, _cal_client_ipc_free);
+       else
+               ci = g_hash_table_lookup(_cal_ipc_table, ipc_key);
+
+       if (ci) {
+               DBG("calendar already connected");
+               return CALENDAR_ERROR_NONE;
+       }
+
+       ci = calloc(1, sizeof(cal_ipc_s));
+       retvm_if(NULL == ci, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
+       ret = _cal_client_ipc_connect_server(&(ci->ipc));
+       if (CALENDAR_ERROR_NONE != ret) {
+               _cal_client_ipc_free(ci);
+               return ret;
+       }
+       ci->change_version = 0;
+       g_hash_table_insert(_cal_ipc_table, g_strdup(ipc_key), ci);
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_set_disconnected_cb(void (*cb)(void *), void *user_data)
+{
+       if (0 == _cal_ipc_disconnected_count++)
+               return pims_ipc_set_server_disconnected_cb(cb, user_data);
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_unset_disconnected_cb(void)
+{
+       if (1 == _cal_ipc_disconnected_count--)
+                return pims_ipc_unset_server_disconnected_cb();
+       return CALENDAR_ERROR_NONE;
+}
+
+void _cal_ipc_set_disconnected(bool is_disconnected)
+{
+       _cal_ipc_disconnected = is_disconnected;
+}
+
+static void _cal_ipc_recovery_foreach_cb(gpointer key, gpointer value, gpointer user_data)
+{
+       int ret = 0 ;
+       cal_ipc_s *ci = (cal_ipc_s *)value;
+       ret = _cal_client_ipc_connect_server(&(ci->ipc));
+       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_client_ipc_connect_server() Fail(%d)", ret);
+}
+
+void _cal_ipc_recovery(void)
+{
+       if (true == _cal_ipc_disconnected)
+               g_hash_table_foreach(_cal_ipc_table, _cal_ipc_recovery_foreach_cb, NULL);
+}
+
+static void _cal_ipc_disconnected_cb(void *user_data)
+{
+       _cal_ipc_set_disconnected(true);
+}
+
+static void _cal_ipc_ready_cb(void *user_data)
+{
+       _cal_ipc_recovery();
+       _cal_client_reminder_recover_for_subscribe();
+       _cal_ipc_set_disconnected(false);
+}
+
+API int calendar_connect(void)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       _cal_mutex_lock(CAL_MUTEX_CONNECTION);
+
+       if (0 < cal_connection_count) {
+               DBG("calendar already connected");
+               cal_connection_count++;
+               _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+               return CALENDAR_ERROR_NONE;
+       }
+
+       ret = _cal_client_ipc_connect();
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_client_ipc_connect() Fail(%d)", ret);
+               _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+               return ret;
+       }
+
+       ret = _cal_inotify_initialize();
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_inotify_initialize() Fail(%d)", ret);
+               _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+               return ret;
+       }
+
+       g_type_init();  // added for alarmmgr
+       _cal_client_reminder_create_for_subscribe();
+       cal_inotify_subscribe_ipc_ready(_cal_ipc_ready_cb, NULL);
+       _cal_view_initialize();
+       _cal_ipc_set_disconnected_cb(_cal_ipc_disconnected_cb, NULL);
+       cal_connection_count++;
+
+       _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int _cal_client_ipc_disconnect_server(pims_ipc_h ipc)
+{
+       int ret = 0;
+       retv_if(NULL == ipc, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       // ipc call
+       if (pims_ipc_call(ipc, CAL_IPC_MODULE, CAL_IPC_SERVER_DISCONNECT, indata, &outdata) != 0) {
+               ERR("pims_ipc_call failed");
+               return CALENDAR_ERROR_IPC;
+       }
+
+       if (NULL == outdata) {
+               ERR("ipc outdata is NULL");
+               return CALENDAR_ERROR_IPC;
+       }
+
+       // check outdata
+       unsigned int size = 0;
+       void *ret_pims = NULL;
+       ret_pims = pims_ipc_data_get(outdata, &size);
+       if (NULL == ret_pims) {
+               pims_ipc_data_destroy(outdata);
+               return CALENDAR_ERROR_IPC;
+       }
+       ret = *(int*)ret_pims;
+       pims_ipc_data_destroy(outdata);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int _cal_client_ipc_disconnect(void)
+{
+       int ret = 0;
+       cal_ipc_s *ci = NULL;
+       char ipc_key[1024] = {0};
+
+       retvm_if(NULL == _cal_ipc_table, CALENDAR_ERROR_IPC, "calendar is not connected");
+
+       _cal_client_ipc_get_tid_str(ipc_key, sizeof(ipc_key));
+       ci = g_hash_table_lookup(_cal_ipc_table, ipc_key);
+       retvm_if(NULL == ci, CALENDAR_ERROR_IPC, "g_hash_table_lookup() Fail");
+
+       ret = _cal_client_ipc_disconnect_server(ci->ipc);
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "_cal_client_ipc_disconnect_server() Fail(%d)", ret);
+       g_hash_table_remove(_cal_ipc_table, ipc_key);
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_disconnect(void)
+{
+       _cal_mutex_lock(CAL_MUTEX_CONNECTION);
+
+       if (cal_connection_count < 1) {
+               DBG("Nothing to disconnect");
+               _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+               return CALENDAR_ERROR_NONE;
+       }
+       if (1 < cal_connection_count) {
+               DBG("connection count (%d)", cal_connection_count);
+               cal_connection_count--;
+               _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+               return CALENDAR_ERROR_NONE;
+       }
+
+       _cal_client_ipc_disconnect();
+
+       _cal_client_reminder_destroy_for_subscribe();
+       cal_inotify_unsubscribe_ipc_ready();
+       _cal_inotify_finalize();
+       _cal_view_finalize();
+       _cal_ipc_unset_disconnected_cb();
+
+       cal_connection_count--;
+       _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_connect_on_thread(void)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       _cal_mutex_lock(CAL_MUTEX_CONNECTION);
+
+       if (0 < cal_connection_count_thread) {
+               DBG("calendar already connected on thread");
+               cal_connection_count_thread++;
+               _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+               return CALENDAR_ERROR_NONE;
+       }
+
+       ret = _cal_client_ipc_connect();
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_client_ipc_connect() Fail(%d)", ret);
+               _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+               return ret;
+       }
+
+       ret = _cal_inotify_initialize();
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_inotify_initialize() Fail(%d)", ret);
+               _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+               return ret;
+       }
+
+       cal_inotify_subscribe_ipc_ready(_cal_ipc_ready_cb, NULL);
+       _cal_view_initialize();
+       _cal_ipc_set_disconnected_cb(_cal_ipc_disconnected_cb, NULL);
+       cal_connection_count_thread++;
+
+       _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_disconnect_on_thread(void)
+{
+       _cal_mutex_lock(CAL_MUTEX_CONNECTION);
+
+       if (cal_connection_count_thread < 1) {
+               DBG("Nothing to disconnect");
+               _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+               return CALENDAR_ERROR_NONE;
+       }
+       if (1 < cal_connection_count_thread) {
+               DBG("connection count (%d)", cal_connection_count_thread);
+               cal_connection_count_thread--;
+               _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+               return CALENDAR_ERROR_NONE;
+       }
+
+       _cal_client_ipc_disconnect();
+
+       cal_inotify_unsubscribe_ipc_ready();
+       _cal_inotify_finalize();
+       _cal_view_finalize();
+       _cal_ipc_unset_disconnected_cb();
+
+       cal_connection_count--;
+       _cal_mutex_unlock(CAL_MUTEX_CONNECTION);
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_connect_with_flags(unsigned int flags)
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       ret = calendar_connect();
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               if (flags & CALENDAR_CONNECT_FLAG_RETRY)
+               {
+                       int retry_time = 500;
+                       int i = 0;
+                       for(i=0;i<9;i++)
+                       {
+                               usleep(retry_time*1000);
+                               ret = calendar_connect();
+                               DBG("retry cnt=%d, ret=%x",(i+1), ret);
+                               if (ret == CALENDAR_ERROR_NONE)
+                                       break;
+                               if (i>6)
+                                       retry_time += 30000;
+                               else
+                                       retry_time *= 2;
+                       }
+
+               }
+       }
+
+       return ret;
+}
+
+static cal_ipc_s* _cal_get_ipc_data(void)
+{
+       cal_ipc_s *ci = NULL;
+       char ipc_key[1024] = {0};
+       retvm_if(NULL == _cal_ipc_table, NULL, "Not connected");
+
+       _cal_client_ipc_get_tid_str(ipc_key, sizeof(ipc_key));
+       ci = g_hash_table_lookup(_cal_ipc_table, ipc_key);
+       if (ci)
+               return ci;
+
+       _cal_client_ipc_get_pid_str(ipc_key, sizeof(ipc_key));
+       ci = g_hash_table_lookup(_cal_ipc_table, ipc_key);
+       if (ci)
+               return ci;
+       return NULL;
+}
+
+bool _cal_client_ipc_is_call_inprogress(void)
+{
+       cal_ipc_s *ci = _cal_get_ipc_data();
+       if (ci)
+               return pims_ipc_is_call_in_progress(ci->ipc);
+       return false;
+}
+
+pims_ipc_h __cal_client_ipc_get_handle(void)
+{
+       cal_ipc_s *ci = _cal_get_ipc_data();
+       if (ci)
+               return ci->ipc;
+       return NULL;
+}
+
+void __cal_client_ipc_lock(void)
+{
+       if (0 == cal_connection_count_thread)
+               _cal_mutex_lock(CAL_MUTEX_PIMS_IPC_CALL);
+}
+
+void __cal_client_ipc_unlock(void)
+{
+       if (0 == cal_connection_count_thread)
+               _cal_mutex_unlock(CAL_MUTEX_PIMS_IPC_CALL);
+}
+
+int _cal_client_ipc_call(char *module, char *function, pims_ipc_h data_in, pims_ipc_data_h *data_out)
+{
+       int ret = 0;
+       retv_if(_cal_ipc_disconnected, CALENDAR_ERROR_IPC);
+
+       pims_ipc_h ipc_handle = __cal_client_ipc_get_handle();
+
+       __cal_client_ipc_lock();
+
+       ret = pims_ipc_call(ipc_handle, module, function, data_in, data_out);
+
+       __cal_client_ipc_unlock();
+
+       return ret;
+}
+
+int _cal_client_ipc_call_async(char *module, char *function, pims_ipc_h data_in, pims_ipc_call_async_cb callback, void *userdata)
+{
+       int ret = 0;
+       retv_if(_cal_ipc_disconnected, CALENDAR_ERROR_IPC);
+
+       pims_ipc_h ipc_handle = __cal_client_ipc_get_handle();
+
+       __cal_client_ipc_lock();
+
+       ret = pims_ipc_call_async(ipc_handle, module, function, data_in, callback, userdata);
+
+       __cal_client_ipc_unlock();
+
+       return ret;
+}
+
+void _cal_client_ipc_set_change_version(int version)
+{
+       cal_ipc_s *ci = _cal_get_ipc_data();
+       retm_if(NULL == ci, "_cal_get_ipc_data() Fail");
+       ci->change_version = version;
+       DBG("change_version=%d",version);
+}
+
+int _cal_client_ipc_get_change_version(void)
+{
+       cal_ipc_s *ci = _cal_get_ipc_data();
+       retvm_if(NULL == ci, 0, "_cal_get_ipc_data() Fail");
+       return ci->change_version;
+}
+
+int cal_client_ipc_client_check_permission(int permission, bool *result)
+{
+       int ret = 0;
+       pims_ipc_data_h indata = NULL;
+       pims_ipc_data_h outdata = NULL;
+
+       retv_if(_cal_ipc_disconnected, CALENDAR_ERROR_IPC);
+
+       if (result)
+               *result = false;
+
+       indata = pims_ipc_data_create(0);
+       if (indata == NULL) {
+               ERR("ipc data created fail !");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       ret = _cal_ipc_marshal_int(permission, indata);
+       if (ret != CALENDAR_ERROR_NONE) {
+               ERR("marshal fail");
+               pims_ipc_data_destroy(indata);
+               return ret;
+       }
+
+       if (_cal_client_ipc_call(CAL_IPC_MODULE, CAL_IPC_SERVER_CHECK_PERMISSION, indata, &outdata) != 0) {
+               ERR("_cal_client_ipc_call failed");
+               pims_ipc_data_destroy(indata);
+               return CALENDAR_ERROR_IPC;
+       }
+
+       pims_ipc_data_destroy(indata);
+
+       if (outdata) {
+               unsigned int size = 0;
+               ret = *(int*) pims_ipc_data_get(outdata,&size);
+
+               if (ret == CALENDAR_ERROR_NONE) {
+                       if (result)
+                               *result = *(bool*) pims_ipc_data_get(outdata, &size);
+               }
+               pims_ipc_data_destroy(outdata);
+       }
+
+       return ret;
+}
diff --git a/client/cal_client_ipc.h b/client/cal_client_ipc.h
new file mode 100644 (file)
index 0000000..206d534
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CAL_CLIENT_IPC_H__
+#define __CAL_CLIENT_IPC_H__
+
+#include <pims-ipc.h>
+
+bool _cal_client_ipc_is_call_inprogress(void);
+
+int _cal_client_ipc_call(char *module, char *function, pims_ipc_h data_in,
+               pims_ipc_data_h *data_out);
+int _cal_client_ipc_call_async(char *module, char *function, pims_ipc_h data_in,
+               pims_ipc_call_async_cb callback, void *userdata);
+
+void _cal_client_ipc_set_change_version(int version);
+int _cal_client_ipc_get_change_version(void);
+
+int cal_client_ipc_client_check_permission(int permission, bool *result);
+
+#endif // __CAL_CLIENT_IPC_H__
diff --git a/client/cal_client_reminder.c b/client/cal_client_reminder.c
new file mode 100644 (file)
index 0000000..a789bf2
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>     //calloc
+#include <pims-ipc.h>
+
+#include "calendar_service.h"
+#include "calendar_db.h"
+#include "calendar_types.h"
+#include "calendar_reminder.h"
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_inotify.h"
+#include "cal_view.h"
+#include "cal_record.h"
+#include "cal_list.h"
+#include "cal_mutex.h"
+
+#include "cal_ipc.h"
+#include "cal_ipc_marshal.h"
+
+#include "cal_client_ipc.h"
+
+typedef struct {
+       calendar_reminder_cb cb;
+       void *user_data;
+} callback_info_s;
+
+
+static pims_ipc_h __ipc = NULL;
+static GSList *__subscribe_list = NULL;
+
+int _cal_client_reminder_create_for_subscribe(void)
+{
+       _cal_mutex_lock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+       if (!__ipc) {
+               __ipc = pims_ipc_create_for_subscribe(CAL_IPC_SOCKET_PATH_FOR_SUBSCRIPTION);
+               if (!__ipc) {
+                       ERR("pims_ipc_create_for_subscribe");
+                       _cal_mutex_unlock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+                       return CALENDAR_ERROR_IPC;
+               }
+       }
+       _cal_mutex_unlock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_client_reminder_recover_for_subscribe(void)
+{
+       _cal_mutex_lock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+       __ipc = pims_ipc_create_for_subscribe(CAL_IPC_SOCKET_PATH_FOR_SUBSCRIPTION);
+       if (!__ipc) {
+               ERR("pims_ipc_create_for_subscribe");
+               _cal_mutex_unlock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+               return CALENDAR_ERROR_IPC;
+       }
+       _cal_mutex_unlock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_client_reminder_destroy_for_subscribe(void)
+{
+       _cal_mutex_lock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+
+       pims_ipc_destroy_for_subscribe(__ipc);
+       __ipc = NULL;
+
+       _cal_mutex_unlock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_client_reminder_subscribe_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data)
+{
+       unsigned int size = 0;
+       const char *str = NULL;
+       int len = 0;
+
+       if (data) {
+               len = (int)pims_ipc_data_get(data, &size);
+               if (0 == len) {
+                       ERR("pims_ipc_data_get() failed");
+                       return;
+               }
+               str = (const char *)pims_ipc_data_get(data, &size);
+               if (!str) {
+                       ERR("pims_ipc_data_get() failed");
+                       return;
+               }
+       }
+
+       if (__subscribe_list) {
+               GSList *l = NULL;
+               for (l = __subscribe_list; l; l = l->next) {
+                       callback_info_s *cb_info = l->data;
+                       if (NULL == cb_info) continue;
+
+                       cb_info->cb(str, cb_info->user_data);
+               }
+       }
+}
+
+API int calendar_reminder_add_cb(calendar_reminder_cb callback, void *user_data)
+{
+       GSList *it = NULL;
+       callback_info_s *cb_info = NULL;
+       int ret;
+       bool result = false;
+
+       if (NULL == callback) {
+               ERR("Invalid parameter: callback is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = cal_client_ipc_client_check_permission(CAL_PERMISSION_READ, &result);
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "ctsvc_ipc_client_check_permission fail (%d)", ret);
+       retvm_if(result == false, CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied (calendar read)");
+
+       _cal_mutex_lock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+
+       if (!__subscribe_list) {
+               if (pims_ipc_subscribe(__ipc, CAL_IPC_MODULE_FOR_SUBSCRIPTION, (char *)CAL_NOTI_REMINDER_CAHNGED,
+                                       __cal_client_reminder_subscribe_callback, NULL) != 0) {
+                       ERR("pims_ipc_subscribe() failed");
+                       _cal_mutex_unlock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+                       return CALENDAR_ERROR_IPC;
+               }
+       }
+
+       // Check duplication
+       for (it = __subscribe_list; it; it = it->next) {
+               if (NULL == it->data) continue;
+
+               callback_info_s *cb_info = it->data;
+               if (callback == cb_info->cb && user_data == cb_info->user_data) {
+                       ERR("The same callback(%s) is already exist");
+                       _cal_mutex_unlock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       cb_info = calloc(1, sizeof(callback_info_s));
+       cb_info->user_data = user_data;
+       cb_info->cb = callback;
+       __subscribe_list = g_slist_append(__subscribe_list, cb_info);
+
+       _cal_mutex_unlock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_reminder_remove_cb(calendar_reminder_cb callback, void *user_data)
+{
+       GSList *it = NULL;
+
+       if (NULL == callback) {
+               ERR("Invalid parameter: callback is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       _cal_mutex_lock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+
+       for (it = __subscribe_list; it; it = it->next) {
+               if (NULL == it->data) continue;
+
+               callback_info_s *cb_info = it->data;
+               if (callback == cb_info->cb && user_data == cb_info->user_data) {
+                       __subscribe_list = g_slist_remove(__subscribe_list, cb_info);
+                       free(cb_info);
+                       break;
+               }
+       }
+
+       if (g_slist_length(__subscribe_list) == 0) {
+               pims_ipc_unsubscribe(__ipc, CAL_IPC_MODULE_FOR_SUBSCRIPTION, (char *)CAL_NOTI_REMINDER_CAHNGED);
+               g_slist_free(__subscribe_list);
+               __subscribe_list = NULL;
+       }
+
+       _cal_mutex_unlock(CAL_MUTEX_PIMS_IPC_PUBSUB);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+
old mode 100755 (executable)
new mode 100644 (file)
similarity index 56%
rename from src/cals-inotify.h
rename to client/cal_client_reminder.h
index 7f1d839..56a8c1e
@@ -1,7 +1,7 @@
 /*
  * Calendar Service
  *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  *
  */
-#ifndef __CALENDAR_SVC_INOTIFY_H__
-#define __CALENDAR_SVC_INOTIFY_H__
 
-int cals_inotify_init(void);
-void cals_inotify_close(void);
-int cals_inotify_subscribe(const char *path, void (*cb)(void *), void *data);
-int cals_inotify_unsubscribe(const char *path, void (*cb)(void *));
-int cals_inotify_unsubscribe_with_data(const char *path,
-               void (*cb)(void *), void *user_data);
+#ifndef __CAL_CLIENT_REMINDER_H__
+#define __CAL_CLIENT_REMINDER_H__
 
+int _cal_client_reminder_create_for_subscribe(void);
+int _cal_client_reminder_recover_for_subscribe(void);
+int _cal_client_reminder_destroy_for_subscribe(void);
 
-#endif //__CALENDAR_SVC_INOTIFY_H__
\ No newline at end of file
+#endif // __CAL_CLIENT_REMINDER_H__
diff --git a/client/calendar-service2.pc.in b/client/calendar-service2.pc.in
new file mode 100644 (file)
index 0000000..0085757
--- /dev/null
@@ -0,0 +1,13 @@
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: @CALSVC2@
+Description: @CALSVC2@ library
+Version: @VERSION@
+Requires: glib-2.0 alarm-service capi-base-common
+Libs: -L${libdir} -l@CALSVC2@
+Cflags: -I${includedir}2
diff --git a/common/cal_filter.c b/common/cal_filter.c
new file mode 100644 (file)
index 0000000..83efbbf
--- /dev/null
@@ -0,0 +1,390 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+#include "cal_filter.h"
+
+static int __cal_filter_create_attribute(cal_composite_filter_s *com_filter, unsigned int property_id,
+               int match, int filter_type, cal_attribute_filter_s **out_filter);
+
+static int __cal_filter_destroy_composite(cal_composite_filter_s* filter);
+static int __cal_filter_destroy_attribute(cal_attribute_filter_s* filter);
+
+static int __cal_filter_clone_composite(cal_composite_filter_s* filter,
+               cal_composite_filter_s **out_filter);
+static int __cal_filter_clone_attribute(cal_attribute_filter_s* filter,
+               cal_attribute_filter_s **out_filter);
+
+API int calendar_filter_create(const char* view_uri, calendar_filter_h* out_filter)
+{
+       cal_composite_filter_s *com_filter;
+
+       retv_if(NULL == view_uri || NULL == out_filter, CALENDAR_ERROR_INVALID_PARAMETER);
+       com_filter = (cal_composite_filter_s *)calloc(1, sizeof(cal_composite_filter_s));
+       retv_if(NULL == com_filter, CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       com_filter->filter_type = CAL_FILTER_COMPOSITE;
+       com_filter->view_uri = strdup(view_uri);
+       com_filter->properties = (cal_property_info_s *)_cal_view_get_property_info(view_uri, &com_filter->property_count);
+       *out_filter = (calendar_filter_h)com_filter;
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_filter_add_operator(calendar_filter_h filter, calendar_filter_operator_e op)
+{
+       cal_composite_filter_s *com_filter;
+
+       retv_if(NULL == filter, CALENDAR_ERROR_INVALID_PARAMETER);
+       retvm_if(op >= CALENDAR_FILTER_OPERATOR_MAX, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: operator(%d)", op);
+
+       com_filter = (cal_composite_filter_s*)filter;
+
+       retvm_if(g_slist_length(com_filter->filter_ops) != (g_slist_length(com_filter->filters)-1),
+                       CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter : Please check the operator of filter");
+       com_filter->filter_ops = g_slist_append(com_filter->filter_ops, (void*)op);
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_filter_add_filter(calendar_filter_h filter, calendar_filter_h add_filter)
+{
+       cal_composite_filter_s *com_filter;
+       cal_composite_filter_s *com_filter2;
+       calendar_filter_h f = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retv_if(NULL == filter || NULL == add_filter, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       com_filter = (cal_composite_filter_s*)filter;
+       com_filter2 = (cal_composite_filter_s*)add_filter;
+
+       retvm_if(g_slist_length(com_filter->filter_ops) != g_slist_length(com_filter->filters),
+                       CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter :Please check the operator of filter");
+       retvm_if (0 != strcmp(com_filter->view_uri, com_filter2->view_uri), CALENDAR_ERROR_INVALID_PARAMETER,
+                       "The filter view_uri is different (filter1:%s, filter2:%s)", com_filter->view_uri, com_filter2->view_uri);
+
+       ret = _cal_filter_clone(add_filter, &f);
+       retv_if(ret != CALENDAR_ERROR_NONE, ret);
+
+       com_filter->filters = g_slist_append(com_filter->filters, f);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_filter_create_attribute(cal_composite_filter_s *com_filter, unsigned int property_id, int match, int filter_type, cal_attribute_filter_s **out_filter)
+{
+       cal_attribute_filter_s *filter;
+       //int type;
+       //bool find = false;
+
+       retvm_if(g_slist_length(com_filter->filter_ops) != g_slist_length(com_filter->filters),
+                       CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter :Please check the operator of filter");
+
+       filter = (cal_attribute_filter_s *)calloc(1, sizeof(cal_attribute_filter_s));
+       retvm_if(NULL == filter, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
+       filter->filter_type = filter_type;
+       filter->property_id = property_id;
+       filter->match = match;
+
+       com_filter->filters = g_slist_append(com_filter->filters, filter);
+       *out_filter = filter;
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_filter_add_str(calendar_filter_h filter, unsigned int property_id, calendar_match_str_flag_e match, const char* match_value)
+{
+       cal_composite_filter_s *com_filter;
+       cal_attribute_filter_s *str_filter;
+       int ret;
+       bool bcheck;
+
+       retv_if(NULL == filter || NULL == match_value, CALENDAR_ERROR_INVALID_PARAMETER);
+       retvm_if(match >= CALENDAR_MATCH_STR_MAX, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: check match value(%d)", match);
+
+       bcheck = CAL_PROPERTY_CHECK_DATA_TYPE(property_id,CAL_PROPERTY_DATA_TYPE_STR);
+       retvm_if(false == bcheck, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property_id(%d) is not supported)", property_id);
+
+       bcheck = CAL_PROPERTY_CHECK_FLAGS(property_id,CAL_PROPERTY_FLAGS_PROJECTION);
+       retvm_if(true == bcheck, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property_id(%d) is not supported)", property_id);
+
+       com_filter = (cal_composite_filter_s*)filter;
+       ret = __cal_filter_create_attribute(com_filter, property_id, match, CAL_FILTER_STR, &str_filter);
+       retvm_if(CALENDAR_ERROR_NONE !=ret, ret,
+                       "Invalid parameter : The paramter is not proper (view_uri:, property_id:%d, match:%d, match_value :%s",
+                       property_id, match, match_value);
+
+       str_filter->value.s = SAFE_STRDUP(match_value);
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_filter_add_int(calendar_filter_h filter, unsigned int property_id, calendar_match_int_flag_e match, int match_value)
+{
+       cal_composite_filter_s *com_filter;
+       cal_attribute_filter_s *int_filter;
+       int ret;
+       bool bcheck;
+
+       retv_if(NULL == filter, CALENDAR_ERROR_INVALID_PARAMETER);
+       retvm_if(match >= CALENDAR_MATCH_INT_MAX, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: check match value(%d)", match);
+
+       bcheck = CAL_PROPERTY_CHECK_DATA_TYPE(property_id,CAL_PROPERTY_DATA_TYPE_INT);
+       retvm_if(false == bcheck, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property_id(%d) is not supported)", property_id);
+
+       bcheck = CAL_PROPERTY_CHECK_FLAGS(property_id,CAL_PROPERTY_FLAGS_PROJECTION);
+       retvm_if(true == bcheck, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property_id(%d) is not supported)", property_id);
+
+       com_filter = (cal_composite_filter_s*)filter;
+       ret = __cal_filter_create_attribute(com_filter, property_id, match, CAL_FILTER_INT, &int_filter);
+       retvm_if(CALENDAR_ERROR_NONE !=ret, ret,
+                       "Invalid parameter : The paramter is not proper (view_uri:, property_id:%d, match:%d, match_value :%d",
+                       property_id, match, match_value);
+
+       int_filter->value.i = match_value;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_filter_add_double(calendar_filter_h filter, unsigned int property_id, calendar_match_int_flag_e match, double match_value)
+{
+       cal_composite_filter_s *com_filter;
+       cal_attribute_filter_s *int_filter;
+       int ret;
+       bool bcheck;
+
+       retv_if(NULL == filter, CALENDAR_ERROR_INVALID_PARAMETER);
+       retvm_if(match >= CALENDAR_MATCH_INT_MAX, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: check match value(%d)", match);
+
+       bcheck = CAL_PROPERTY_CHECK_DATA_TYPE(property_id,CAL_PROPERTY_DATA_TYPE_DOUBLE);
+       retvm_if(false == bcheck, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property_id(%d) is not supported)", property_id);
+
+       bcheck = CAL_PROPERTY_CHECK_FLAGS(property_id,CAL_PROPERTY_FLAGS_PROJECTION);
+       retvm_if(true == bcheck, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property_id(%d) is not supported)", property_id);
+
+       com_filter = (cal_composite_filter_s*)filter;
+       ret = __cal_filter_create_attribute(com_filter, property_id, match, CAL_FILTER_DOUBLE, &int_filter);
+       retvm_if(CALENDAR_ERROR_NONE !=ret, ret,
+                       "Invalid parameter : The paramter is not proper (view_uri:, property_id:%d, match:%d, match_value :%d",
+                       property_id, match, match_value);
+
+       int_filter->value.d = match_value;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_filter_add_lli(calendar_filter_h filter, unsigned int property_id, calendar_match_int_flag_e match, long long int match_value)
+{
+       cal_composite_filter_s *com_filter;
+       cal_attribute_filter_s *int_filter;
+       int ret;
+       bool bcheck;
+
+       retv_if(NULL == filter, CALENDAR_ERROR_INVALID_PARAMETER);
+       retvm_if(match >= CALENDAR_MATCH_INT_MAX, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: check match value(%d)", match);
+
+       bcheck = CAL_PROPERTY_CHECK_DATA_TYPE(property_id,CAL_PROPERTY_DATA_TYPE_LLI);
+       retvm_if(false == bcheck, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property_id(%d) is not supported)", property_id);
+
+       bcheck = CAL_PROPERTY_CHECK_FLAGS(property_id,CAL_PROPERTY_FLAGS_PROJECTION);
+       retvm_if(true == bcheck, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property_id(%d) is not supported)", property_id);
+
+       com_filter = (cal_composite_filter_s*)filter;
+       ret = __cal_filter_create_attribute(com_filter, property_id, match, CAL_FILTER_LLI, &int_filter);
+       retvm_if(CALENDAR_ERROR_NONE !=ret, ret,
+                       "Invalid parameter : The paramter is not proper (view_uri:, property_id:%d, match:%d, match_value :%d",
+                       property_id, match, match_value);
+
+       int_filter->value.lli = match_value;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_filter_add_caltime(calendar_filter_h filter, unsigned int property_id, calendar_match_int_flag_e match, calendar_time_s match_value)
+{
+       cal_composite_filter_s *com_filter;
+       cal_attribute_filter_s *int_filter;
+       int ret;
+       bool bcheck;
+
+       retv_if(NULL == filter, CALENDAR_ERROR_INVALID_PARAMETER);
+       retvm_if(match >= CALENDAR_MATCH_INT_MAX, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: check match value(%d)", match);
+
+       bcheck = CAL_PROPERTY_CHECK_DATA_TYPE(property_id,CAL_PROPERTY_DATA_TYPE_CALTIME);
+       retvm_if(false == bcheck, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property_id(%d) is not supported)", property_id);
+
+       bcheck = CAL_PROPERTY_CHECK_FLAGS(property_id,CAL_PROPERTY_FLAGS_PROJECTION);
+       retvm_if(true == bcheck, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property_id(%d) is not supported)", property_id);
+
+       com_filter = (cal_composite_filter_s*)filter;
+       ret = __cal_filter_create_attribute(com_filter, property_id, match, CAL_FILTER_CALTIME, &int_filter);
+       retvm_if(CALENDAR_ERROR_NONE !=ret, ret,
+                       "Invalid parameter : The paramter is not proper (view_uri:, property_id:%d, match:%d, match_value :%d",
+                       property_id, match, match_value);
+
+       int_filter->value.caltime = match_value;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_filter_destroy(calendar_filter_h filter)
+{
+       retv_if(NULL == filter, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       return __cal_filter_destroy_composite((cal_composite_filter_s*)filter);
+}
+
+int _cal_filter_clone(calendar_filter_h filter, calendar_filter_h* out_filter)
+{
+       retv_if(NULL == filter || NULL == out_filter, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       return __cal_filter_clone_composite((cal_composite_filter_s*)filter, (cal_composite_filter_s**)out_filter);
+}
+
+static int __cal_filter_destroy_composite(cal_composite_filter_s* filter)
+{
+       GSList *cursor = NULL;
+
+       retv_if(NULL == filter, CALENDAR_ERROR_INVALID_PARAMETER);
+       for(cursor=filter->filters;cursor;cursor=cursor->next)
+       {
+               cal_filter_s *src = (cal_filter_s *)cursor->data;
+               if (src == NULL)
+                       continue;
+               if (src->filter_type == CAL_FILTER_COMPOSITE)
+               {
+                       __cal_filter_destroy_composite((cal_composite_filter_s*)src);
+               }
+               else
+               {
+                       __cal_filter_destroy_attribute((cal_attribute_filter_s*)src);
+               }
+
+       }
+       CAL_FREE(filter->view_uri);
+       g_slist_free(filter->filters);
+       g_slist_free(filter->filter_ops);
+       CAL_FREE(filter);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_filter_destroy_attribute(cal_attribute_filter_s* filter)
+{
+       retv_if(NULL == filter, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (filter->filter_type == CAL_FILTER_STR)
+       {
+               CAL_FREE(filter->value.s);
+       }
+       CAL_FREE(filter);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_filter_clone_composite(cal_composite_filter_s* filter,
+               cal_composite_filter_s **out_filter)
+{
+       GSList *cursor;
+       cal_composite_filter_s *out;
+       int ret = CALENDAR_ERROR_NONE;
+
+       ret = calendar_filter_create(filter->view_uri, (calendar_filter_h *)&out);
+       retv_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       for(cursor=filter->filters; cursor ; cursor=cursor->next)
+       {
+               cal_filter_s *src = (cal_filter_s *)cursor->data;
+               cal_filter_s *dest = NULL;
+
+               if (src == NULL)
+                       continue;
+
+               if (src->filter_type == CAL_FILTER_COMPOSITE)
+               {
+                       ret = __cal_filter_clone_composite((cal_composite_filter_s *)src,
+                                       (cal_composite_filter_s **)&dest);
+               }
+               else
+               {
+                       ret = __cal_filter_clone_attribute((cal_attribute_filter_s *)src,
+                                       (cal_attribute_filter_s **)&dest);
+               }
+               if (ret == CALENDAR_ERROR_NONE)
+               {
+                       out->filters = g_slist_append(out->filters, dest);
+               }
+               else
+               {
+                       calendar_filter_destroy((calendar_filter_h)out);
+                       return ret;
+               }
+       }
+
+       out->filter_ops = g_slist_copy(filter->filter_ops);
+       *out_filter = out;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_filter_clone_attribute(cal_attribute_filter_s* filter,
+               cal_attribute_filter_s **out_filter)
+{
+       cal_attribute_filter_s *out;
+       out = (cal_attribute_filter_s *)calloc(1, sizeof(cal_attribute_filter_s));
+       retv_if(NULL == out, CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       out->filter_type = filter->filter_type;
+       out->match = filter->match;
+       out->property_id = filter->property_id;
+       switch(filter->filter_type)
+       {
+       case CAL_FILTER_STR:
+               out->value.s = SAFE_STRDUP(filter->value.s);
+               break;
+       case CAL_FILTER_INT:
+               out->value.i = filter->value.i;
+               break;
+       case CAL_FILTER_DOUBLE:
+               out->value.d = filter->value.d;
+               break;
+       case CAL_FILTER_LLI:
+               out->value.lli = filter->value.lli;
+               break;
+       case CAL_FILTER_CALTIME:
+               out->value.caltime = filter->value.caltime;
+               break;
+       default:
+               break;
+       }
+
+       *out_filter = out;
+       return CALENDAR_ERROR_NONE;
+}
old mode 100755 (executable)
new mode 100644 (file)
similarity index 67%
rename from src/cals-struct.h
rename to common/cal_filter.h
index c295df9..8bc1b63
@@ -1,7 +1,7 @@
 /*
  * Calendar Service
  *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  *
  */
-#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);
+#ifndef __CALENDAR_SVC_FILTER_H__
+#define __CALENDAR_SVC_FILTER_H__
 
-#endif // _CALENDAR_SVC_STRUCT_INTERNAL_H_
+#include "calendar_filter.h"
+
+int _cal_filter_clone(calendar_filter_h filter, calendar_filter_h* out_filter);
+
+#endif //__CALENDAR_SVC_FILTER_H__
diff --git a/common/cal_inotify.c b/common/cal_inotify.c
new file mode 100644 (file)
index 0000000..0988e0e
--- /dev/null
@@ -0,0 +1,577 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/inotify.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+#include "cal_inotify.h"
+
+#ifdef CAL_IPC_CLIENT
+#include "cal_client_ipc.h"
+#include "cal_mutex.h"
+#endif
+
+typedef struct {
+       int wd;
+       calendar_db_changed_cb callback;
+       void *cb_data;
+       cal_noti_type_e noti_type;
+       bool blocked;
+} noti_info_s;
+
+typedef struct {
+       int wd;
+       void (*cb)(void *);
+       void *cb_data;
+} sock_info_s;
+
+static int inoti_fd = -1;
+static guint inoti_handler;
+static GSList *noti_list;
+static sock_info_s *_cal_socket_init_info = NULL;
+static int _cal_socket_init_count = 0;
+
+#ifdef CAL_IPC_CLIENT
+
+static int calendar_inoti_count = 0;
+
+void _cal_inotify_call_pending_callback(void)
+{
+       noti_info_s *noti;
+       GSList *cursor = NULL;
+
+       cursor = noti_list;
+       while (cursor)
+       {
+               noti = (noti_info_s *)cursor->data;
+               if (noti->callback && noti->blocked)
+               {
+                       noti->blocked = false;
+                       switch (noti->noti_type)
+                       {
+                       case CAL_NOTI_TYPE_CALENDAR:
+                               noti->callback(CALENDAR_VIEW_CALENDAR, noti->cb_data);
+                               break;
+                       case CAL_NOTI_TYPE_EVENT:
+                               noti->callback(CALENDAR_VIEW_EVENT, noti->cb_data);
+                               break;
+                       case CAL_NOTI_TYPE_TODO:
+                               noti->callback(CALENDAR_VIEW_TODO, noti->cb_data);
+                               break;
+                       default:
+                               break;
+                       }
+               }
+               cursor = cursor->next;
+       }
+}
+#endif
+
+static inline void _handle_callback(GSList *noti_list, int wd, uint32_t mask)
+{
+       noti_info_s *noti;
+       GSList *cursor;
+
+       cursor = noti_list;
+       while (cursor)
+       {
+               noti = (noti_info_s *)cursor->data;
+               if (noti->wd == wd)
+               {
+#ifdef CAL_IPC_CLIENT
+                       if (_cal_client_ipc_is_call_inprogress())
+                       {
+                               noti->blocked = true;
+                               continue;
+                       }
+#endif
+
+                       if ((mask & IN_CLOSE_WRITE) && noti->callback)
+                       {
+                               switch(noti->noti_type)
+                               {
+                               case CAL_NOTI_TYPE_CALENDAR:
+                                       noti->callback(CALENDAR_VIEW_CALENDAR, noti->cb_data);
+                                       break;
+                               case CAL_NOTI_TYPE_EVENT:
+                                       noti->callback(CALENDAR_VIEW_EVENT, noti->cb_data);
+                                       break;
+                               case CAL_NOTI_TYPE_TODO:
+                                       noti->callback(CALENDAR_VIEW_TODO, noti->cb_data);
+                                       break;
+                               default:
+                                       break;
+                               }
+                       }
+               }
+               cursor = cursor->next;
+       }
+}
+
+static gboolean _inotify_gio_cb(GIOChannel *src, GIOCondition cond, gpointer data)
+{
+       int fd, ret;
+       struct inotify_event ie;
+       char name[FILENAME_MAX] = {0};
+
+       fd = g_io_channel_unix_get_fd(src);
+
+       while (0 < (ret = read(fd, &ie, sizeof(ie)))) {
+               if (sizeof(ie) == ret) {
+                       if (_cal_socket_init_info && _cal_socket_init_info->wd == ie.wd)
+                               _cal_socket_init_info->cb(_cal_socket_init_info->cb_data);
+                       else if (noti_list)
+                               _handle_callback(noti_list, ie.wd, ie.mask);
+                       else
+                               DBG("no noti_list");
+
+                       while (0 != ie.len) {
+                               ret = read(fd, name, (ie.len<sizeof(name))?ie.len:sizeof(name));
+                               if (-1 == ret) {
+                                       if (EINTR == errno)
+                                               continue;
+                                       else
+                                               return TRUE;
+                               }
+                               if (ret > ie.len)
+                                       ie.len = 0;
+                               else
+                                       ie.len -= ret;
+                       }
+               } else {
+                       while (ret < sizeof(ie)) {
+                               int read_size;
+                               read_size = read(fd, name, sizeof(ie)-ret);
+                               if (-1 == read_size) {
+                                       if (EINTR == errno)
+                                               continue;
+                                       else
+                                               return TRUE;
+                               }
+                               ret += read_size;
+                       }
+               }
+       }
+       return TRUE;
+}
+
+int cal_inotify_unsubscribe_ipc_ready(void)
+{
+       if (_cal_socket_init_count < 1) {
+               DBG("Nothing to unsubscribe ipc ready");
+               return CALENDAR_ERROR_NONE;
+       }
+       if (1 < _cal_socket_init_count) {
+               DBG("_cal_socket_init_count(%d)", _cal_socket_init_count);
+               _cal_socket_init_count--;
+               return CALENDAR_ERROR_NONE;
+       }
+
+       int wd = _cal_socket_init_info->wd;
+       inotify_rm_watch(inoti_fd, wd);
+       free(_cal_socket_init_info);
+       _cal_socket_init_info = NULL;
+       _cal_socket_init_count = 0;
+       return CALENDAR_ERROR_NONE;
+}
+
+static inline int _inotify_attach_handler(int fd)
+{
+       guint ret;
+       GIOChannel *channel;
+
+       if (fd < 0)
+       {
+               ERR("Invalid argument: fd is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       channel = g_io_channel_unix_new(fd);
+       if (channel == NULL)
+       {
+               ERR("Failed to new channel");
+               return -1; // CALENDAR_ERROR_FAILED_INOTIFY
+       }
+
+       g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL);
+
+       ret = g_io_add_watch(channel, G_IO_IN, _inotify_gio_cb, NULL);
+       g_io_channel_unref(channel);
+
+       return ret;
+}
+
+int _cal_inotify_initialize(void)
+{
+       int ret;
+
+#ifdef CAL_IPC_CLIENT
+       _cal_mutex_lock(CAL_MUTEX_INOTIFY);
+       calendar_inoti_count++;
+
+       if (calendar_inoti_count > 1)
+       {
+               CAL_DBG("inotify count =%d",calendar_inoti_count);
+               _cal_mutex_unlock(CAL_MUTEX_INOTIFY);
+               return CALENDAR_ERROR_NONE;
+       }
+       CAL_DBG("inotify count =%d",calendar_inoti_count);
+       _cal_mutex_unlock(CAL_MUTEX_INOTIFY);
+#endif
+       inoti_fd = inotify_init();
+       if (inoti_fd == -1)
+       {
+               ERR("Failed to init inotify(err:%d)", errno);
+#ifdef CAL_IPC_CLIENT
+               _cal_mutex_lock(CAL_MUTEX_INOTIFY);
+               calendar_inoti_count = 0;
+               _cal_mutex_unlock(CAL_MUTEX_INOTIFY);
+#endif
+               return -1; // CALENDAR_ERROR_FAILED_INOTIFY;
+       }
+
+       ret = fcntl(inoti_fd, F_SETFD, FD_CLOEXEC);
+       warn_if(ret < 0, "fcntl failed(%d)", ret);
+       ret = fcntl(inoti_fd, F_SETFL, O_NONBLOCK);
+       warn_if(ret < 0, "fcntl failed(%d)", ret);
+
+       inoti_handler = _inotify_attach_handler(inoti_fd);
+       if (inoti_handler <= 0)
+       {
+               ERR("_inotify_attach_handler() Failed");
+               close(inoti_fd);
+               inoti_fd = -1;
+               inoti_handler = 0;
+#ifdef CAL_IPC_CLIENT
+               _cal_mutex_lock(CAL_MUTEX_INOTIFY);
+               calendar_inoti_count = 0;
+               _cal_mutex_unlock(CAL_MUTEX_INOTIFY);
+#endif
+               return -1; // CALENDAR_ERROR_FAILED_INOTIFY
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static inline int __cal_inotify_get_wd(int fd, const char *notipath)
+{
+       return inotify_add_watch(fd, notipath, IN_ACCESS);
+}
+
+static inline int __cal_inotify_add_watch(int fd, const char *notipath)
+{
+       int ret;
+
+       ret = inotify_add_watch(fd, notipath, IN_CLOSE_WRITE);
+       if (ret < 0)
+       {
+               ERR("Failed to add watch(ret:%d)", ret);
+               return -1; // CALENDAR_ERROR_FAILED_INOTIFY
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_inotify_subscribe(cal_noti_type_e type, const char *path, calendar_db_changed_cb callback, void *data)
+{
+       int ret, wd;
+       noti_info_s *noti, *same_noti = NULL;
+       GSList *cursor;
+
+       if (path == NULL)
+       {
+               ERR("Invalid argument: path is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (callback == NULL)
+       {
+               ERR("Invalid argument: callback is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (inoti_fd < 0)
+       {
+               ERR("Invalid argument: iinoti_fd(%d) is invalid", inoti_fd);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       wd = __cal_inotify_get_wd(inoti_fd, path);
+       if (wd == -1)
+       {
+               ERR("Failed to get wd(err:%d)", errno);
+               if (errno == EACCES)
+                       return CALENDAR_ERROR_PERMISSION_DENIED;
+               return CALENDAR_ERROR_SYSTEM;
+       }
+
+       cursor = noti_list;
+       while (cursor)
+       {
+               if (cursor->data == NULL)
+               {
+                       DBG("No data exist");
+                       cursor = cursor->next;
+                       continue;
+               }
+
+               same_noti = cursor->data;
+               if (same_noti->wd == wd && same_noti->callback == callback && same_noti->cb_data == data) {
+                       break;
+
+               }
+               else
+               {
+                       same_noti = NULL;
+               }
+
+               cursor = cursor->next;
+       }
+
+       if (same_noti)
+       {
+               __cal_inotify_add_watch(inoti_fd, path);
+               ERR("The same callback(%s) is already exist", path);
+               return CALENDAR_ERROR_SYSTEM;
+       }
+
+       ret = __cal_inotify_add_watch(inoti_fd, path);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("Failed to add watch");
+               return CALENDAR_ERROR_SYSTEM;
+       }
+
+       noti = calloc(1, sizeof(noti_info_s));
+       if (noti == NULL)
+       {
+               ERR("Failed to alloc");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       noti->wd = wd;
+       noti->cb_data = data;
+       noti->callback = callback;
+       noti->noti_type = type;
+       noti->blocked = false;
+       noti_list = g_slist_append(noti_list, noti);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int cal_inotify_subscribe_ipc_ready(void (*cb)(void *), void *user_data)
+{
+       int ret = 0;
+
+       if (0 == _cal_socket_init_count) {
+               int wd = __cal_inotify_get_wd(inoti_fd, CAL_NOTI_IPC_READY);
+               if (-1 == wd) {
+                       ERR("__cal_inotify_get_wd() Fail(%d)", errno);
+                       if (EACCES == errno)
+                               return CALENDAR_ERROR_PERMISSION_DENIED;
+                       return CALENDAR_ERROR_SYSTEM;
+               }
+               ret = __cal_inotify_add_watch(inoti_fd, CAL_NOTI_IPC_READY);
+               retvm_if(CALENDAR_ERROR_NONE != ret, ret, "__cal_inotify_add_watch() Fail(%d)", ret);
+               _cal_socket_init_info = calloc(1, sizeof(sock_info_s));
+               retvm_if(NULL == _cal_socket_init_info, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
+               _cal_socket_init_info->wd = wd;
+               _cal_socket_init_info->cb = cb;
+               _cal_socket_init_info->cb_data = user_data;
+       }
+       _cal_socket_init_count++;
+       return CALENDAR_ERROR_NONE;
+}
+
+static inline int __cal_inotify_delete_noti_with_data(GSList **noti_list, int wd,
+               calendar_db_changed_cb callback, void *user_data)
+{
+       int del_cnt, remain_cnt;
+       GSList *cursor, *result;
+
+       del_cnt = 0;
+       remain_cnt = 0;
+
+       cursor = result = *noti_list;
+       while (cursor)
+       {
+               noti_info_s *noti = cursor->data;
+               if (noti && wd == noti->wd)
+               {
+                       if (callback == noti->callback && user_data == noti->cb_data) {
+                               cursor = cursor->next;
+                               result = g_slist_remove(result , noti);
+                               free(noti);
+                               del_cnt++;
+                               continue;
+                       }
+                       else
+                       {
+                               remain_cnt++;
+                       }
+               }
+               cursor = cursor->next;
+       }
+
+       if (del_cnt == 0)
+       {
+               ERR("Nothing to delete");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+
+       *noti_list = result;
+
+       return remain_cnt;
+}
+
+static inline int __cal_notify_delete_noti(GSList **noti_list, int wd, calendar_db_changed_cb callback)
+{
+       int del_cnt, remain_cnt;
+       GSList *cursor, *result;
+
+       del_cnt = 0;
+       remain_cnt = 0;
+
+       cursor = result = *noti_list;
+       while (cursor)
+       {
+               noti_info_s *noti = cursor->data;
+               if (noti && wd == noti->wd)
+               {
+                       if (NULL == callback || noti->callback == callback)
+                       {
+                               cursor = cursor->next;
+                               result = g_slist_remove(result, noti);
+                               free(noti);
+                               del_cnt++;
+                               continue;
+                       }
+                       else
+                       {
+                               remain_cnt++;
+                       }
+               }
+               cursor = cursor->next;
+       }
+
+       if (del_cnt == 0)
+       {
+               ERR("Nothing to delete");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+
+       *noti_list = result;
+
+       return remain_cnt;
+}
+
+int _cal_inotify_unsubscribe_with_data(const char *path, calendar_db_changed_cb callback, void *user_data)
+{
+       int wd;
+       int ret;
+
+       if (path == NULL)
+       {
+               ERR("Invalid argument: path is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (callback == NULL)
+       {
+               ERR("Invalid argument: callback is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (inoti_fd < 0)
+       {
+               ERR("Invalid argument: iinoti_fd(%d) is invalid", inoti_fd);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       wd = __cal_inotify_get_wd(inoti_fd, path);
+       if (wd == -1)
+       {
+               ERR("Failed to get wd(err:%d)", errno);
+               if (errno == EACCES)
+                       return CALENDAR_ERROR_PERMISSION_DENIED;
+               return CALENDAR_ERROR_SYSTEM;
+       }
+
+       ret = __cal_inotify_delete_noti_with_data(&noti_list, wd, callback, user_data);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               WARN("Failed to delete noti(err:%d)", ret);
+               return __cal_inotify_add_watch(inoti_fd, path);
+       }
+
+       ret = inotify_rm_watch(inoti_fd, wd);
+       return (ret == 0) ? CALENDAR_ERROR_NONE : CALENDAR_ERROR_SYSTEM;
+}
+
+static inline gboolean __cal_inotify_detach_handler(guint id)
+{
+       return g_source_remove(id);
+}
+
+static void __clear_nslot_list(gpointer data, gpointer user_data)
+{
+       free(data);
+}
+
+void _cal_inotify_finalize(void)
+{
+#ifdef CAL_IPC_CLIENT
+       _cal_mutex_lock(CAL_MUTEX_INOTIFY);
+       calendar_inoti_count--;
+
+       if (calendar_inoti_count > 0)
+       {
+               CAL_DBG("inotify count =%d",calendar_inoti_count);
+               _cal_mutex_unlock(CAL_MUTEX_INOTIFY);
+               return ;
+       }
+       CAL_DBG("inotify count =%d",calendar_inoti_count);
+       _cal_mutex_unlock(CAL_MUTEX_INOTIFY);
+#endif
+       if (inoti_handler)
+       {
+               __cal_inotify_detach_handler(inoti_handler);
+               inoti_handler = 0;
+       }
+
+       if (noti_list)
+       {
+               g_slist_foreach(noti_list, __clear_nslot_list, NULL);
+               g_slist_free(noti_list);
+               noti_list = NULL;
+       }
+
+       if (inoti_fd >= 0)
+       {
+               close(inoti_fd);
+               inoti_fd = -1;
+       }
+}
+
diff --git a/common/cal_inotify.h b/common/cal_inotify.h
new file mode 100644 (file)
index 0000000..eef3253
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_INOTIFY_H__
+#define __CALENDAR_SVC_INOTIFY_H__
+
+#include "calendar_db.h"
+#include "cal_typedef.h"
+
+#ifdef CAL_IPC_CLIENT
+void _cal_inotify_call_pending_callback(void);
+#endif
+
+int _cal_inotify_initialize(void);
+int _cal_inotify_subscribe(cal_noti_type_e type, const char *path, calendar_db_changed_cb callback, void *data);
+int _cal_inotify_unsubscribe_with_data(const char *path, calendar_db_changed_cb callback, void *user_data);
+void _cal_inotify_finalize(void);
+int cal_inotify_subscribe_ipc_ready(void (*cb)(void *), void *user_data);
+int cal_inotify_unsubscribe_ipc_ready(void);
+
+#endif // __CALENDAR_SVC_INOTIFY_H__
old mode 100755 (executable)
new mode 100644 (file)
similarity index 52%
rename from include/cals-internal.h
rename to common/cal_internal.h
index 2e7bccc..4f4e751
@@ -1,7 +1,7 @@
 /*
  * Calendar Service
  *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 #include <stdio.h>
 #include <string.h>
-#include <alarm.h>
-
-#define EVENT_UPDATE "calendar_event_update"
-#define CALENDARBOOK_UPDATE "calendar_book_update"
-#define TASK_UPDATE "task_update"
 
 #ifndef API
 #define API __attribute__ ((visibility("default")))
 
 #define SAFE_STRDUP(src) (src)?strdup((char *)src):NULL
 
-#define CALS_DEBUGGING
+#define CAL_DEBUGGING
 
 #define LOG_TAG "CALENDAR_SVC"
 #include <dlog.h>
+
+#define COLOR_GREEN "\033[0;32m"
+#define COLOR_END              "\033[0;m"
+
+#define ENTER() SLOGD(COLOR_GREEN"BEGIN >>>>"COLOR_END)
+#define LEAVE() SLOGD(COLOR_GREEN"END <<<<"COLOR_END)
+
 #define DLOG(prio, fmt, arg...) \
-  do { SLOG(prio, LOG_TAG, fmt, ##arg); } while(0);
+       do { SLOG(prio, LOG_TAG, fmt, ##arg); } while(0);
 #define INFO(fmt, arg...) SLOGI(fmt, ##arg)
-#define WARN(fmt, arg...) SLOGW("%s:%d " fmt, __FUNCTION__, __LINE__, ##arg)
-#define ERR(fmt, arg...) SLOGE("%s:%d " fmt, __FUNCTION__, __LINE__, ##arg)
-#define DBG(fmt, arg...) SLOGD("%s:" fmt, __FUNCTION__, ##arg)
-
-//#define CALS_DEBUGGING
-#ifdef CALS_DEBUGGING
-    #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
-#define CALS_DBG(fmt, arg...)
-#endif /* CALS_DEBUGGING */
-
-
-#define TMDUMP(_X_)\
-{\
-       ERR("tm(%d/%d/%d %d:%d)",(_X_).tm_year+1900,(_X_).tm_mon+1,(_X_).tm_mday,(_X_).tm_hour,(_X_).tm_min);\
-}
+#define WARN(fmt, arg...) SLOGW(fmt, ##arg)
+#define ERR(fmt, arg...) SLOGE(fmt, ##arg)
+#define DBG(fmt, arg...) SLOGD(fmt, ##arg)
+#define SEC_INFO(fmt, arg...) SECURE_LOGI(fmt, ##arg)
+#define SEC_ERR(fmt, arg...) SECURE_LOGE(fmt, ##arg)
+#define SEC_DBG(fmt, arg...) SECURE_LOGD(fmt, ##arg)
+
+//#define CAL_DEBUGGING
+#ifdef CAL_DEBUGGING
+#if defined(CAL_IPC_SERVER)
+#define CAL_FN_CALL DBG("SERVER:>>>>>>>>%s called", __FUNCTION__)
+#define CAL_FN_END DBG("SERVER:<<<<<<<<%s ended", __FUNCTION__)
+#elif defined(CAL_IPC_CLIENT)
+#define CAL_FN_CALL DBG("CLIENT:>>>>>>>>%s called", __FUNCTION__)
+#define CAL_FN_END DBG("CLIENT:<<<<<<<<%s ended", __FUNCTION__)
+#else
+#define CAL_FN_CALL DBG(">>>>>>>>%s called", __FUNCTION__)
+#define CAL_FN_END DBG("<<<<<<<<%s ended", __FUNCTION__)
+#endif
+
+#if defined(CAL_IPC_SERVER)
+#define CAL_DBG(fmt, arg...) DBG("SERVER:%d " fmt, __LINE__, ##arg)
+#elif defined(CAL_IPC_CLIENT)
+#define CAL_DBG(fmt, arg...) DBG("CLIENT:%d " fmt, __LINE__, ##arg)
+#else
+#define CAL_DBG(fmt, arg...) DBG("%d " fmt, __LINE__, ##arg)
+#endif
+#else /* CAL_DEBUGGING */
+#define CAL_FN_CALL
+#define CAL_FN_END
+#define CAL_DBG(fmt, arg...)
+#endif /* CAL_DEBUGGING */
 
 #define warn_if(expr, fmt, arg...) do { \
        if (expr) { \
 } while (0)
 
 #define retex_if(expr, val, fmt, arg...) do { \
-         if(expr) { \
-                ERR(fmt, ##arg); \
-                val; \
-                goto CATCH; \
-         } \
-       } while (0);
+       if(expr) { \
+               ERR(fmt, ##arg); \
+               val; \
+               goto CATCH; \
+       } \
+} while (0);
 
 #define CAL_PROFILE
 #ifdef CAL_PROFILE
 #endif
 
 #define CAL_FREE(ptr) \
- do { \
-  free(ptr); \
-  ptr = NULL; \
- }while(0);
+       do { \
+               if (ptr) \
+               free(ptr); \
+               ptr = NULL; \
+       } while(0)
+
+
+// Thread-local storage
+#if defined(CAL_IPC_SERVER)
+#define TLS __thread
+#elif defined(CAL_IPC_CLIENT)
+#define TLS __thread
+#else   //CAL_NATIVE
+#define TLS
+#endif
 
 #endif /* __CALENDAR_SVC_INTERNAL_H__ */
 
diff --git a/common/cal_list.c b/common/cal_list.c
new file mode 100644 (file)
index 0000000..1bbfa25
--- /dev/null
@@ -0,0 +1,343 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_list.h"
+
+API int calendar_list_create( calendar_list_h* out_list )
+{
+       if (NULL == out_list)
+       {
+               ERR("Invalid parameter: list is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       cal_list_s *l;
+
+       l = (cal_list_s *)calloc(1, sizeof(cal_list_s));
+       if (l == NULL) {
+               ERR("Failed to calloc");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       l->count = 0;
+       l->record = NULL;
+       l->cursor = NULL;
+
+       *out_list = (calendar_list_h)l;
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_list_get_count( calendar_list_h list, int *count )
+{
+       cal_list_s *l;
+
+       if (list == NULL) {
+               ERR("Invalid argument: calendar_list_h is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (count == NULL) {
+               ERR("Invalid argument: count is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       l = (cal_list_s *)list;
+
+       *count = l->count;
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_list_add( calendar_list_h list, calendar_record_h record )
+{
+       cal_list_s *l;
+
+       if (list == NULL) {
+               ERR("Invalid argument: calendar_list_h is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (record == NULL) {
+               ERR("Invalid argument: calendar_record_h is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       l = (cal_list_s *)list;
+
+       l->count++;
+       l->record = g_list_append(l->record, record);
+       //l->cursor = g_list_nth(l->record, (l->count) -1);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_list_remove( calendar_list_h list, calendar_record_h record )
+{
+       GList *cursor;
+       cal_list_s *l;
+
+       if (list == NULL) {
+               ERR("Invalid argument: calendar_list_h is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (record == NULL) {
+               ERR("Invalid argument: calendar_record_h is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       l = (cal_list_s *)list;
+
+       cursor = l->record;
+       while (cursor) {
+               if (cursor->data == record) {
+                       l->cursor = cursor->next;
+                       l->record = g_list_remove(l->record, cursor->data);
+                       l->count--;
+                       return CALENDAR_ERROR_NONE;
+               }
+               cursor = cursor->next;
+       }
+       return CALENDAR_ERROR_NO_DATA;
+}
+
+API int calendar_list_get_current_record_p( calendar_list_h list, calendar_record_h* record )
+{
+       cal_list_s *l;
+
+       if (list == NULL) {
+               ERR("Invalid argument: calendar_list_h is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (record == NULL) {
+               ERR("Invalid argument: calendar_record_h is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       l = (cal_list_s *)list;
+       if (l->cursor == NULL) {
+               *record = NULL;
+               return CALENDAR_ERROR_NO_DATA;
+       }
+
+       *record = l->cursor->data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_list_prev( calendar_list_h list )
+{
+       cal_list_s *l;
+
+       if (list == NULL) {
+               ERR("Invalid argument: calendar_list_h is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       l = (cal_list_s *)list;
+       l->cursor = g_list_previous(l->cursor);
+       if (l->cursor == NULL) {
+               DBG("No prev list");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_list_next( calendar_list_h list )
+{
+       cal_list_s *l;
+
+       if (list == NULL) {
+               ERR("Invalid argument: calendar_list_h is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       l = (cal_list_s *)list;
+       l->cursor = g_list_next(l->cursor);
+       if (l->cursor == NULL) {
+               //DBG("No next list");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_list_first( calendar_list_h list )
+{
+       cal_list_s *l;
+
+       if (list == NULL) {
+               ERR("Invalid argument: calendar_list_h is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       l = (cal_list_s *)list;
+       l->cursor = g_list_first(l->record);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_list_last( calendar_list_h list )
+{
+       cal_list_s *l;
+
+       if (list == NULL) {
+               ERR("Invalid argument: calendar_list_h is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       l = (cal_list_s *)list;
+       l->cursor = g_list_last(l->record);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_list_destroy( calendar_list_h list, bool delete_record )
+{
+       GList *cursor;
+       cal_list_s *l = NULL;
+
+       if (list == NULL) {
+               ERR("Invalid argument: calendar_list_h is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       l = (cal_list_s *)list;
+
+       if (delete_record == true)
+       {
+               cursor = l->record;
+
+               while (cursor)
+               {
+                       if (cursor->data)
+                       {
+                               calendar_record_destroy((calendar_record_h)(cursor->data), true);
+                       }
+                       cursor = cursor->next;
+               }
+       }
+       if(l->record)
+       {
+               g_list_free(l->record);
+       }
+       CAL_FREE(l);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_list_clone(calendar_list_h list, calendar_list_h *out_list)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       int count = 0, i = 0;
+       calendar_list_h l = NULL;
+
+       if (NULL == list || NULL == out_list)
+       {
+               ERR("Invalid parameter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = calendar_list_get_count(list, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               return ret;
+       }
+
+       ret = calendar_list_first(list);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               return ret;
+       }
+
+       ret = calendar_list_create(&l);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               return ret;
+       }
+
+       for(i = 0; i < count; i++)
+       {
+               calendar_record_h record = NULL;
+               calendar_record_h clone_record = NULL;
+               if (calendar_list_get_current_record_p(list,&record) != CALENDAR_ERROR_NONE)
+               {
+                       ERR("calendar_list_get_count fail");
+                       calendar_list_destroy(l, true);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+
+               if (calendar_record_clone(record, &clone_record) != CALENDAR_ERROR_NONE)
+               {
+                       ERR("calendar_list_get_count fail");
+                       calendar_list_destroy(l, true);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+
+               if (calendar_list_add(l, clone_record) != CALENDAR_ERROR_NONE)
+               {
+                       ERR("calendar_list_get_count fail");
+                       calendar_list_destroy(l, true);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+
+               calendar_list_next(list);
+       }
+
+       *out_list = l;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_list_get_nth_record_p(cal_list_s *list_s, int index, calendar_record_h *record)
+{
+       retv_if(index < 0, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       retv_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER);
+       *record = NULL;
+
+       retv_if(NULL == list_s, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (index < list_s->count) {
+               *record = g_list_nth_data(list_s->record, index);
+               return CALENDAR_ERROR_NONE;
+       }
+
+       ERR("Check index(%d) > count(%d)", index, list_s->count);
+       return CALENDAR_ERROR_NO_DATA;
+}
+
+int _cal_list_clear(cal_list_s *list_s)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_record_h record = NULL;
+       calendar_list_h list = (calendar_list_h)list_s;
+       retv_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       calendar_list_first(list);
+       while (CALENDAR_ERROR_NONE == calendar_list_get_current_record_p(list, &record)) {
+               ret = calendar_list_remove(list, record);
+               if (CALENDAR_ERROR_NONE != ret) {
+                       ERR("calendar_list_remove() Failed(%d)", ret);
+                       break;
+               }
+       }
+       return ret;
+}
+
diff --git a/common/cal_list.h b/common/cal_list.h
new file mode 100644 (file)
index 0000000..7b29c71
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __CALENDAR_SVC_LIST_H__
+#define __CALENDAR_SVC_LIST_H__
+
+#include "calendar_list.h"
+
+int _cal_list_clone(calendar_list_h list, calendar_list_h *out_list);
+int _cal_list_get_nth_record_p(cal_list_s *list_s, int index, calendar_record_h *record);
+int _cal_list_clear(cal_list_s *list_s);
+
+#endif // __CALENDAR_SVC_LIST_H__
diff --git a/common/cal_mutex.c b/common/cal_mutex.c
new file mode 100644 (file)
index 0000000..df58acf
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <pthread.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_mutex.h"
+
+static pthread_mutex_t __cal_property_hash_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t __cal_connection_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t __cal_pims_ipc_call_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t __cal_inotify_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t __cal_pims_ipc_pubsub_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t __cal_access_control_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+static inline pthread_mutex_t* __cal_mutex_get_mutex(int type)
+{
+       pthread_mutex_t *ret_val;
+
+       switch (type) {
+       case CAL_MUTEX_PROPERTY_HASH:
+               ret_val = &__cal_property_hash_mutex;
+               break;
+       case CAL_MUTEX_CONNECTION:
+               ret_val = &__cal_connection_mutex;
+               break;
+       case CAL_MUTEX_PIMS_IPC_CALL:
+               ret_val = &__cal_pims_ipc_call_mutex;
+               break;
+       case CAL_MUTEX_INOTIFY:
+               ret_val = &__cal_inotify_mutex;
+               break;
+       case CAL_MUTEX_PIMS_IPC_PUBSUB:
+               ret_val = &__cal_pims_ipc_pubsub_mutex;
+               break;
+       case CAL_MUTEX_ACCESS_CONTROL:
+               ret_val = &__cal_access_control_mutex;
+               break;
+       default:
+               ERR("unknown type(%d)", type);
+               ret_val = NULL;
+               break;
+       }
+       return ret_val;
+}
+
+void _cal_mutex_lock(int type)
+{
+       int ret;
+       pthread_mutex_t *mutex;
+
+       mutex = __cal_mutex_get_mutex(type);
+
+       if (mutex != NULL)
+       {
+               ret = pthread_mutex_lock(mutex);
+               retm_if(ret, "mutex_lock Failed(%d)", ret);
+       }
+}
+
+void _cal_mutex_unlock(int type)
+{
+       int ret;
+       pthread_mutex_t *mutex;
+
+       mutex = __cal_mutex_get_mutex(type);
+
+       if (mutex != NULL)
+       {
+               ret = pthread_mutex_unlock(mutex);
+               retm_if(ret, "mutex_unlock Failed(%d)", ret);
+       }
+}
similarity index 59%
rename from test/timetest.h
rename to common/cal_mutex.h
index a0633a8..ea8c7d1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Calendar Service
  *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  *
  */
-#ifndef _TIMETEST_H_
-#define _TIMETEST_H_
 
-int init_time(void);
-double set_start_time(void);
-double exec_time(double start);
+#ifndef __CALENDAR_SVC_MUTEX_H__
+#define __CALENDAR_SVC_MUTEX_H__
 
-int print_time(char *prn_args, double time);
-int print_argument(char *prn_args);
-int print_milestone(char *prn_args, int level);
-int std_output(char *prn_args, double time);
-int file_print_init(char *filename);
+enum {
+       CAL_MUTEX_CONNECTION,
+       CAL_MUTEX_PIMS_IPC_CALL,
+       CAL_MUTEX_INOTIFY,
+       CAL_MUTEX_PROPERTY_HASH,
+       CAL_MUTEX_PIMS_IPC_PUBSUB,
+       CAL_MUTEX_ACCESS_CONTROL,
+};
 
+void _cal_mutex_lock(int type);
+void _cal_mutex_unlock(int type);
 
-#endif //_TIMETEST_H_
+#endif  //__CALENDAR_SVC_MUTEX_H__
diff --git a/common/cal_query.c b/common/cal_query.c
new file mode 100644 (file)
index 0000000..d55e8c6
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_filter.h"
+
+#include "cal_query.h"
+
+static bool __cal_query_property_check(const cal_property_info_s *properties,
+               int count, unsigned int property_id)
+{
+       int i;
+
+       for (i=0;i<count;i++)
+       {
+               cal_property_info_s *p = (cal_property_info_s*)&(properties[i]);
+               if (property_id == p->property_id) {
+                       return true;
+               }
+       }
+       return false;
+}
+
+API int calendar_query_create( const char* view_uri, calendar_query_h* out_query )
+{
+       cal_query_s *query;
+
+       retv_if(NULL == view_uri || NULL == out_query, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       query = (cal_query_s *)calloc(1, sizeof(cal_query_s));
+       retv_if(NULL == query, CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       query->view_uri = strdup(view_uri);
+       query->properties = (cal_property_info_s *)_cal_view_get_property_info(view_uri, &query->property_count);
+       *out_query = (calendar_query_h)query;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_query_set_projection(calendar_query_h query, unsigned int property_ids[], int count)
+{
+       cal_query_s *que = NULL;
+       int i;
+       bool find;
+
+       retv_if(NULL == query, CALENDAR_ERROR_INVALID_PARAMETER);
+       retvm_if(NULL == property_ids, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid paramter: property_ids is NULL");
+       retvm_if(count < 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: check count(%d)", count);
+
+       que = (cal_query_s *)query;
+
+       for (i=0;i<count;i++)
+       {
+               find = __cal_query_property_check(que->properties, que->property_count, property_ids[i]);
+               retvm_if(false == find, CALENDAR_ERROR_INVALID_PARAMETER,
+                               "Invalid parameter : property_id(%d) is not supported on view_uri(%s)", property_ids[i], que->view_uri);
+
+               find = CAL_PROPERTY_CHECK_FLAGS(property_ids[i], CAL_PROPERTY_FLAGS_FILTER);
+               retvm_if(true == find, CALENDAR_ERROR_INVALID_PARAMETER,
+                               "Invalid parameter : property_id(%d) is not supported on view_uri(%s)", property_ids[i], que->view_uri);
+       }
+
+       CAL_FREE(que->projection);
+
+       que->projection = calloc(count, sizeof(unsigned int));
+       retvm_if(NULL == que->projection, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
+       memcpy(que->projection, property_ids, sizeof(unsigned int) * count);
+       que->projection_count = count;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_query_set_distinct(calendar_query_h query, bool set)
+{
+       cal_query_s *que = NULL;
+
+       retv_if(NULL == query, CALENDAR_ERROR_INVALID_PARAMETER);
+       que = (cal_query_s *)query;
+
+       que->distinct = set;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_query_set_filter(calendar_query_h query, calendar_filter_h filter)
+{
+       cal_query_s *que;
+       calendar_filter_h new_filter;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retv_if(NULL == query || NULL == filter, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       que = (cal_query_s *)query;
+
+       if(((cal_composite_filter_s*)filter)->filters == NULL)
+       {
+               ERR("Empty filter");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+
+       ret = _cal_filter_clone(filter,&new_filter);
+       retv_if(ret!=CALENDAR_ERROR_NONE, ret);
+
+       if (que->filter)
+       {
+               calendar_filter_destroy((calendar_filter_h)que->filter);
+       }
+
+       que->filter = (cal_composite_filter_s*)new_filter;
+
+       return ret;
+}
+
+API int calendar_query_set_sort(calendar_query_h query, unsigned int property_id, bool asc)
+{
+       cal_query_s *que;
+       bool find = false;
+
+       retv_if(NULL == query, CALENDAR_ERROR_INVALID_PARAMETER);
+       que = (cal_query_s *)query;
+
+
+       find = __cal_query_property_check(que->properties, que->property_count, property_id);
+       retvm_if(false == find, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid paramter : property_id(%d) is not supported on view_uri(%s)", property_id, que->view_uri);
+
+       que->sort_property_id = property_id;
+       que->asc = asc;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_query_destroy( calendar_query_h query )
+{
+       cal_query_s *que;
+
+       retv_if(NULL == query, CALENDAR_ERROR_INVALID_PARAMETER);
+       que = (cal_query_s *)query;
+
+       if (que->filter)
+       {
+               calendar_filter_destroy((calendar_filter_h)que->filter);
+       }
+
+       CAL_FREE(que->view_uri);
+       CAL_FREE(que->projection);
+       CAL_FREE(que);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_query_clone(calendar_query_h query, calendar_query_h* out_query)
+{
+       cal_query_s *que;
+       cal_query_s *out_que;
+       cal_filter_s *out_filter = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retv_if(NULL == query, CALENDAR_ERROR_INVALID_PARAMETER);
+       que = (cal_query_s *)query;
+
+       ret = calendar_query_create(que->view_uri, out_query);
+       retv_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_OUT_OF_MEMORY);
+       out_que = (cal_query_s *)*out_query;
+
+       if (que->filter)
+       {
+               _cal_filter_clone((calendar_filter_h)que->filter,(calendar_filter_h*)&out_filter);
+       }
+
+       if (que->projection_count > 0)
+       {
+               out_que->projection = calloc(que->projection_count, sizeof(unsigned int));
+               retvm_if(NULL == out_que->projection, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
+               memcpy(out_que->projection, que->projection , sizeof(unsigned int) * que->projection_count);
+               out_que->projection_count = que->projection_count;
+       }
+       out_que->sort_property_id = que->sort_property_id;
+       out_que->asc = que->asc;
+
+       return CALENDAR_ERROR_NONE;
+}
+
similarity index 51%
rename from test/test-log.h
rename to common/cal_query.h
index c4d1490..85e847a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Calendar Service
  *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  *
  */
-#ifndef __TEST_LOG_H__
-#define __TEST_LOG_H__
 
-#include <stdio.h>
-#include <unistd.h>
+#ifndef __CALENDAR_SVC_QUERY_H__
+#define __CALENDAR_SVC_QUERY_H__
 
-#define PRT(prio, fmt, arg...) \
-       do { fprintf((prio?stderr:stdout),fmt"\n", ##arg); } while (0)
-#define INFO(fmt, arg...) PRT(0, fmt, ##arg)
-#define ERR(fmt, arg...) PRT(1,"\x1b[101;38m[ERROR]\x1b[0m%s:%d" fmt, __FUNCTION__, __LINE__, ##arg)
-#define DBG(fmt, arg...) \
-       do { \
-               printf(fmt"\n", ##arg); \
-       } while (0)
+#include "calendar_query.h"
 
-#define TEST_FN_START DBG("[START] \x1b[105;37m[%s]\x1b[0m", __FUNCTION__)
+int _cal_query_clone(calendar_query_h query, calendar_query_h* out_query);
 
-#endif /* __TEST_LOG_H__ */
+#endif  //__CALENDAR_SVC_QUERY_H__
diff --git a/common/cal_record.c b/common/cal_record.c
new file mode 100644 (file)
index 0000000..b2b4cfe
--- /dev/null
@@ -0,0 +1,549 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#include <stdlib.h>            //calloc
+#include <stdbool.h>           //bool
+#include <string.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+#include "cal_record.h"
+
+#define __CHECK_READ_ONLY_PROPERTY() \
+       if (CAL_PROPERTY_CHECK_FLAGS(property_id,CAL_PROPERTY_FLAGS_READ_ONLY) == true) \
+{ \
+       ERR("Invalid parameter: Don't try to change read-only property."); \
+       return CALENDAR_ERROR_NOT_PERMITTED; \
+}
+
+extern cal_record_plugin_cb_s _cal_record_calendar_plugin_cb;
+extern cal_record_plugin_cb_s _cal_record_event_plugin_cb;
+extern cal_record_plugin_cb_s _cal_record_todo_plugin_cb;
+extern cal_record_plugin_cb_s _cal_record_alarm_plugin_cb;
+extern cal_record_plugin_cb_s _cal_record_attendee_plugin_cb;
+extern cal_record_plugin_cb_s _cal_record_timezone_plugin_cb;
+extern cal_record_plugin_cb_s _cal_record_updated_info_plugin_cb;
+extern cal_record_plugin_cb_s _cal_record_instance_normal_plugin_cb;
+extern cal_record_plugin_cb_s _cal_record_instance_allday_plugin_cb;
+extern cal_record_plugin_cb_s _cal_record_instance_normal_extended_plugin_cb;
+extern cal_record_plugin_cb_s _cal_record_instance_allday_extended_plugin_cb;
+extern cal_record_plugin_cb_s _cal_record_search_plugin_cb;
+extern cal_record_plugin_cb_s _cal_record_extended_plugin_cb;
+
+cal_record_plugin_cb_s* _cal_record_get_plugin_cb(cal_record_type_e type)
+{
+       switch (type)
+       {
+       case CAL_RECORD_TYPE_CALENDAR:
+               return (&_cal_record_calendar_plugin_cb);
+       case CAL_RECORD_TYPE_EVENT:
+               return (&_cal_record_event_plugin_cb);
+       case CAL_RECORD_TYPE_TODO:
+               return (&_cal_record_todo_plugin_cb);
+       case CAL_RECORD_TYPE_ALARM:
+               return (&_cal_record_alarm_plugin_cb);
+       case CAL_RECORD_TYPE_ATTENDEE:
+               return (&_cal_record_attendee_plugin_cb);
+       case CAL_RECORD_TYPE_TIMEZONE:
+               return (&_cal_record_timezone_plugin_cb);
+       case CAL_RECORD_TYPE_INSTANCE_NORMAL:
+               return (&_cal_record_instance_normal_plugin_cb);
+       case CAL_RECORD_TYPE_INSTANCE_ALLDAY:
+               return (&_cal_record_instance_allday_plugin_cb);
+       case CAL_RECORD_TYPE_INSTANCE_NORMAL_EXTENDED:
+               return (&_cal_record_instance_normal_extended_plugin_cb);
+       case CAL_RECORD_TYPE_INSTANCE_ALLDAY_EXTENDED:
+               return (&_cal_record_instance_allday_extended_plugin_cb);
+       case CAL_RECORD_TYPE_UPDATED_INFO:
+               return (&_cal_record_updated_info_plugin_cb);
+       case CAL_RECORD_TYPE_SEARCH:
+               return (&_cal_record_search_plugin_cb);
+       case CAL_RECORD_TYPE_EXTENDED:
+               return (&_cal_record_extended_plugin_cb);
+       default:
+               return NULL;
+       }
+}
+
+static inline void __cal_record_set_property_flag(calendar_record_h record, unsigned int property_id, cal_properties_flag_e flag)
+{
+       int index;
+       cal_record_s *_record = NULL;
+
+       _record = (cal_record_s *)record;
+       index = property_id & 0x00000FFF;
+
+       if (_record->properties_flags == NULL)
+       {
+               int count = 0;
+               _cal_view_get_property_info(_record->view_uri,&count);
+
+               if (count > 0)
+               {
+                       _record->properties_flags = calloc(count, sizeof(char));
+                       _record->properties_max_count = count;
+                       if (_record->properties_flags == NULL)
+                       {
+                               ERR("calloc fail");
+                               return ;
+                       }
+               }
+               else
+               {
+                       ERR("get property_info_fail");
+                       return ;
+               }
+       }
+
+       _record->properties_flags[index] |= flag;
+       _record->property_flag |= flag;
+}
+
+bool _cal_record_check_property_flag(calendar_record_h record, unsigned int property_id, cal_properties_flag_e flag)
+{
+       int index;
+       cal_record_s *_record = NULL;
+
+       _record = (cal_record_s *)record;
+       index = property_id & 0x00000FFF;
+
+       if (_record->properties_flags == NULL)
+       {
+               if (flag == CAL_PROPERTY_FLAG_PROJECTION)
+                       return true;
+               else
+                       return false;
+       }
+
+       if (flag == CAL_PROPERTY_FLAG_PROJECTION)
+       {
+               if (_record->property_flag & CAL_PROPERTY_FLAG_PROJECTION )
+               {
+                       if (_record->properties_flags[index] & CAL_PROPERTY_FLAG_PROJECTION )
+                               return true;
+                       else
+                               return false;
+               }
+
+               return true;
+       }
+
+       return (_record->properties_flags[index] & flag) ? true : false;
+
+}
+
+int _cal_record_set_projection(calendar_record_h record, const unsigned int *projection, const int projection_count, int properties_max_count)
+{
+       int i;
+
+       cal_record_s *_record = NULL;
+
+       retv_if(record == NULL, -1);
+
+       _record = (cal_record_s *)record;
+
+       CAL_FREE(_record->properties_flags);
+       _record->properties_flags  = calloc(properties_max_count, sizeof(char));
+
+       retvm_if(NULL == _record->properties_flags, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc fail");
+
+       _record->properties_max_count = properties_max_count;
+
+       for (i = 0; i < projection_count; i++)
+       {
+               __cal_record_set_property_flag(record, projection[i], CAL_PROPERTY_FLAG_PROJECTION);
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_record_create( const char* view_uri, calendar_record_h* out_record )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+
+       retvm_if(NULL == view_uri || NULL == out_record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       type =_cal_view_get_type(view_uri);
+       retv_if(CAL_RECORD_TYPE_INVALID == type, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       cal_record_plugin_cb_s *plugin_cb = _cal_record_get_plugin_cb(type);
+       retvm_if(NULL == plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == plugin_cb->create, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted in [%s]", view_uri);
+
+       ret = plugin_cb->create(out_record);
+
+       if(ret == CALENDAR_ERROR_NONE)
+       {
+               CAL_RECORD_INIT_COMMON((cal_record_s*)*out_record, type, plugin_cb, _cal_view_get_uri(view_uri));
+       }
+
+       return ret;
+}
+
+API int calendar_record_destroy( calendar_record_h record, bool delete_child )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       retvm_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == temp->plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->destroy, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted in [%s]", temp->view_uri);
+
+       CAL_FREE(temp->properties_flags);
+
+       ret = temp->plugin_cb->destroy(record, delete_child);
+
+       return ret;
+}
+
+API int calendar_record_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb || NULL == out_record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->clone, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted in [%s]", temp->view_uri);
+
+       ret = temp->plugin_cb->clone(record, out_record);
+
+       return ret;
+}
+
+API int calendar_record_get_uri_p( calendar_record_h record, char** out_str )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == out_str, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       *out_str = (char*)(temp->view_uri);
+
+       return ret;
+}
+
+// Record get/set int,str, etc..
+API int calendar_record_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb || NULL == out_str, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->get_str, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->get_str(record, property_id, out_str);
+
+       return ret;
+}
+
+API int calendar_record_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb || NULL == out_str, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->get_str_p, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->get_str_p(record, property_id, out_str);
+
+       return ret;
+}
+API int calendar_record_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb || NULL == out_value, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->get_int, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->get_int(record, property_id, out_value);
+
+       return ret;
+}
+
+API int calendar_record_get_double( calendar_record_h record, unsigned int property_id, double* out_value )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb || NULL == out_value, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->get_double, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->get_double(record, property_id, out_value);
+
+       return ret;
+}
+API int calendar_record_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb || NULL == out_value, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->get_lli, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->get_lli(record, property_id, out_value);
+
+       return ret;
+}
+
+API int calendar_record_get_caltime(calendar_record_h record, unsigned int property_id, calendar_time_s *out_value )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb || NULL == out_value, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->get_caltime, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->get_caltime(record, property_id, out_value);
+
+       return ret;
+}
+
+API int calendar_record_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       retvm_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       __CHECK_READ_ONLY_PROPERTY();
+
+       int ret = _cal_record_set_str(record, property_id, value);
+
+       return ret;
+}
+
+API int calendar_record_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       retvm_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       __CHECK_READ_ONLY_PROPERTY();
+
+       int ret = _cal_record_set_int(record, property_id, value);
+
+       return ret;
+}
+
+API int calendar_record_set_double( calendar_record_h record, unsigned int property_id, double value )
+{
+       retvm_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       __CHECK_READ_ONLY_PROPERTY();
+
+       int ret = _cal_record_set_double(record, property_id, value);
+
+       return ret;
+}
+
+API int calendar_record_set_lli( calendar_record_h record, unsigned int property_id, long long int value )
+{
+       retvm_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       __CHECK_READ_ONLY_PROPERTY();
+
+       int ret = _cal_record_set_lli(record, property_id, value);
+
+       return ret;
+}
+
+API int calendar_record_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value )
+{
+       retvm_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       __CHECK_READ_ONLY_PROPERTY();
+
+       int ret = _cal_record_set_caltime(record, property_id, value);
+
+       return ret;
+}
+
+// Record get/set child records
+API int calendar_record_add_child_record( calendar_record_h record, unsigned int property_id, calendar_record_h child_record )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb || NULL == child_record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->add_child_record, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->add_child_record(record, property_id, child_record);
+
+       return ret;
+}
+API int calendar_record_remove_child_record( calendar_record_h record, unsigned int property_id, calendar_record_h child_record )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb || NULL == child_record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->remove_child_record, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->remove_child_record(record, property_id, child_record);
+
+       return ret;
+}
+
+API int calendar_record_get_child_record_count( calendar_record_h record, unsigned int property_id, unsigned int* count  )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb || NULL == count, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->get_child_record_count, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->get_child_record_count(record, property_id, count);
+
+       return ret;
+}
+API int calendar_record_get_child_record_at_p( calendar_record_h record, unsigned int property_id, int index, calendar_record_h* child_record )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb || NULL == child_record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->get_child_record_at_p, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->get_child_record_at_p(record, property_id, index, child_record);
+
+       return ret;
+}
+
+API int calendar_record_clone_child_record_list( calendar_record_h record, unsigned int property_id, calendar_list_h* out_list )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb || NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->clone_child_record_list, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->clone_child_record_list(record, property_id, out_list);
+
+       return ret;
+}
+
+int _cal_record_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->set_str, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->set_str(record, property_id, value);
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               __cal_record_set_property_flag(record,property_id,CAL_PROPERTY_FLAG_DIRTY);
+       }
+       return ret;
+}
+
+int _cal_record_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->set_int, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->set_int(record, property_id, value);
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               __cal_record_set_property_flag(record,property_id,CAL_PROPERTY_FLAG_DIRTY);
+       }
+       return ret;
+}
+
+int _cal_record_set_double( calendar_record_h record, unsigned int property_id, double value )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->set_double, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->set_double(record, property_id, value);
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               __cal_record_set_property_flag(record,property_id,CAL_PROPERTY_FLAG_DIRTY);
+       }
+       return ret;
+}
+
+int _cal_record_set_lli( calendar_record_h record, unsigned int property_id, long long int value )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->set_lli, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->set_lli(record, property_id, value);
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               __cal_record_set_property_flag(record,property_id,CAL_PROPERTY_FLAG_DIRTY);
+       }
+       return ret;
+}
+
+int _cal_record_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == temp->plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == temp->plugin_cb->set_caltime, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted(%x) in [%s]", property_id, temp->view_uri);
+       retvm_if(false == _cal_record_check_property_flag(record, property_id,CAL_PROPERTY_FLAG_PROJECTION), CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = temp->plugin_cb->set_caltime(record, property_id, value);
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               __cal_record_set_property_flag(record,property_id,CAL_PROPERTY_FLAG_DIRTY);
+       }
+       return ret;
+}
diff --git a/common/cal_record.h b/common/cal_record.h
new file mode 100644 (file)
index 0000000..4968bfb
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __CALENDAR_SVC_RECORD_H__
+#define __CALENDAR_SVC_RECORD_H__
+
+#include "calendar_record.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum
+{
+       CAL_RECORD_TYPE_INVALID = 0,
+       CAL_RECORD_TYPE_CALENDAR,
+       CAL_RECORD_TYPE_EVENT ,
+       CAL_RECORD_TYPE_TODO,
+       CAL_RECORD_TYPE_TIMEZONE,
+       CAL_RECORD_TYPE_ATTENDEE,
+       CAL_RECORD_TYPE_ALARM,
+       CAL_RECORD_TYPE_INSTANCE_NORMAL,
+       CAL_RECORD_TYPE_INSTANCE_ALLDAY,
+       CAL_RECORD_TYPE_INSTANCE_NORMAL_EXTENDED,
+       CAL_RECORD_TYPE_INSTANCE_ALLDAY_EXTENDED,
+       CAL_RECORD_TYPE_UPDATED_INFO,
+       CAL_RECORD_TYPE_SEARCH,
+       CAL_RECORD_TYPE_EXTENDED,
+} cal_record_type_e;
+
+typedef int (*cal_record_create_cb)( calendar_record_h* out_record );
+typedef int (*cal_record_destroy_cb)( calendar_record_h record, bool delete_child );
+typedef int (*cal_record_clone_cb)( calendar_record_h record, calendar_record_h* out_record );
+typedef int (*cal_record_get_str_cb)( calendar_record_h record, unsigned int property_id, char** out_str );
+typedef int (*cal_record_get_str_p_cb)( calendar_record_h record, unsigned int property_id, char** out_str );
+typedef int (*cal_record_get_int_cb)( calendar_record_h record, unsigned int property_id, int* out_value );
+typedef int (*cal_record_get_double_cb)( calendar_record_h record, unsigned int property_id, double* out_value );
+typedef int (*cal_record_get_lli_cb)( calendar_record_h record, unsigned int property_id, long long int* out_value );
+typedef int (*cal_record_get_caltime_cb)( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value );
+typedef int (*cal_record_set_str_cb)( calendar_record_h record, unsigned int property_id, const char* value );
+typedef int (*cal_record_set_int_cb)( calendar_record_h record, unsigned int property_id, int value );
+typedef int (*cal_record_set_double_cb)( calendar_record_h record, unsigned int property_id, double value );
+typedef int (*cal_record_set_lli_cb)( calendar_record_h record, unsigned int property_id, long long int value );
+typedef int (*cal_record_set_caltime_cb)( calendar_record_h record, unsigned int property_id, calendar_time_s value );
+typedef int (*cal_record_add_child_record_cb)( calendar_record_h record, unsigned int property_id, calendar_record_h child_record );
+typedef int (*cal_record_remove_child_record_cb)( calendar_record_h record, unsigned int property_id, calendar_record_h child_record );
+typedef int (*cal_record_get_child_record_count_cb)( calendar_record_h record, unsigned int property_id, unsigned int* count );
+typedef int (*cal_record_get_child_record_at_p_cb)( calendar_record_h record, unsigned int property_id, int index, calendar_record_h* child_record );
+typedef int (*cal_record_clone_child_record_list_cb)( calendar_record_h record, unsigned int property_id, calendar_list_h* out_list );
+
+typedef enum {
+       CAL_PROPERTY_FLAG_PROJECTION = 0x00000001,
+       CAL_PROPERTY_FLAG_DIRTY = 0x00000002,
+} cal_properties_flag_e;
+
+typedef struct {
+       cal_record_create_cb create;
+       cal_record_destroy_cb destroy;
+       cal_record_clone_cb clone;
+       cal_record_get_str_cb get_str;
+       cal_record_get_str_p_cb get_str_p;
+       cal_record_get_int_cb get_int;
+       cal_record_get_double_cb get_double;
+       cal_record_get_lli_cb get_lli;
+       cal_record_get_caltime_cb get_caltime;
+       cal_record_set_str_cb set_str;
+       cal_record_set_int_cb set_int;
+       cal_record_set_double_cb set_double;
+       cal_record_set_lli_cb set_lli;
+       cal_record_set_caltime_cb set_caltime;
+       cal_record_add_child_record_cb add_child_record;
+       cal_record_remove_child_record_cb remove_child_record;
+       cal_record_get_child_record_count_cb get_child_record_count;
+       cal_record_get_child_record_at_p_cb get_child_record_at_p;
+       cal_record_clone_child_record_list_cb clone_child_record_list;
+} cal_record_plugin_cb_s;
+
+typedef struct {
+       cal_record_type_e type;
+       cal_record_plugin_cb_s *plugin_cb;
+       const char* view_uri;
+       unsigned int properties_max_count;
+       unsigned char *properties_flags;
+       unsigned char property_flag;
+} cal_record_s;
+
+#define CAL_RECORD_INIT_COMMON(common, intype, cb, uri) do {\
+       (common)->type = (intype);\
+       (common)->plugin_cb = (cb);\
+       (common)->view_uri = (uri);\
+       (common)->properties_max_count = 0;\
+       (common)->properties_flags = NULL;\
+       (common)->property_flag = 0;\
+} while (0)
+
+#define CAL_RECORD_COPY_COMMON(dst, src) do {\
+       (dst)->type = (src)->type;\
+       (dst)->plugin_cb = (src)->plugin_cb;\
+       (dst)->view_uri = (src)->view_uri;\
+       (dst)->properties_max_count = (src)->properties_max_count;\
+       if ((src)->properties_flags) \
+       {\
+               (dst)->properties_flags  = calloc((dst)->properties_max_count, sizeof(char));\
+               if ((dst)->properties_flags)\
+               memcpy((dst)->properties_flags,(src)->properties_flags,sizeof(char)*(dst)->properties_max_count);\
+       }\
+       (dst)->property_flag = (src)->property_flag;\
+} while (0)
+
+#define CAL_RECORD_RESET_COMMON(src) do {\
+       if ((src)->properties_flags) \
+       {\
+               free((src)->properties_flags); \
+               (src)->properties_max_count = 0;\
+               (src)->properties_flags = NULL;\
+               (src)->property_flag = 0;\
+       }\
+} while (0)
+
+cal_record_plugin_cb_s* _cal_record_get_plugin_cb(cal_record_type_e type);
+
+bool _cal_record_check_property_flag(calendar_record_h record, unsigned int property_id, cal_properties_flag_e flag);
+int _cal_record_set_projection(calendar_record_h record, const unsigned int *projection, const int projection_count, int properties_max_count);
+
+int _cal_record_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+int _cal_record_set_int( calendar_record_h record, unsigned int property_id, int value );
+int _cal_record_set_double( calendar_record_h record, unsigned int property_id, double value );
+int _cal_record_set_lli( calendar_record_h record, unsigned int property_id, long long int value );
+int _cal_record_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CALENDAR_SVC_RECORD_H__ */
+
diff --git a/common/cal_record_alarm.c b/common/cal_record_alarm.c
new file mode 100644 (file)
index 0000000..567e725
--- /dev/null
@@ -0,0 +1,299 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdlib.h>            //calloc
+#include <stdbool.h>           //bool
+#include <string.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+#include "cal_record.h"
+
+static int __cal_record_alarm_create( calendar_record_h* out_record );
+static int __cal_record_alarm_destroy( calendar_record_h record, bool delete_child );
+static int __cal_record_alarm_clone( calendar_record_h record, calendar_record_h* out_record );
+static int __cal_record_alarm_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_alarm_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_alarm_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+static int __cal_record_alarm_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value );
+static int __cal_record_alarm_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+static int __cal_record_alarm_set_int( calendar_record_h record, unsigned int property_id, int value );
+static int __cal_record_alarm_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value );
+
+cal_record_plugin_cb_s _cal_record_alarm_plugin_cb = {
+       .create = __cal_record_alarm_create,
+       .destroy = __cal_record_alarm_destroy,
+       .clone = __cal_record_alarm_clone,
+       .get_str = __cal_record_alarm_get_str,
+       .get_str_p = __cal_record_alarm_get_str_p,
+       .get_int = __cal_record_alarm_get_int,
+       .get_double = NULL,
+       .get_lli = NULL,
+       .get_caltime = __cal_record_alarm_get_caltime,
+       .set_str = __cal_record_alarm_set_str,
+       .set_int = __cal_record_alarm_set_int,
+       .set_double = NULL,
+       .set_lli = NULL,
+       .set_caltime = __cal_record_alarm_set_caltime,
+       .add_child_record = NULL,
+       .remove_child_record = NULL,
+       .get_child_record_count = NULL,
+       .get_child_record_at_p = NULL,
+       .clone_child_record_list = NULL
+};
+
+static void __cal_record_alarm_struct_init(cal_alarm_s *record)
+{
+       memset(record,0,sizeof(cal_alarm_s));
+}
+
+static int __cal_record_alarm_create(calendar_record_h* out_record )
+{
+       cal_alarm_s *temp = NULL;
+       int ret= CALENDAR_ERROR_NONE;
+
+       temp = (cal_alarm_s*)calloc(1,sizeof(cal_alarm_s));
+       retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_alarm_s:sch) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       __cal_record_alarm_struct_init(temp);
+
+       *out_record = (calendar_record_h)temp;
+
+       return ret;
+}
+
+static void __cal_record_alarm_struct_free(cal_alarm_s *record)
+{
+       CAL_FREE(record->alarm_description);
+       CAL_FREE(record->alarm_summary);
+       CAL_FREE(record->alarm_attach);
+       CAL_FREE(record);
+}
+
+static int __cal_record_alarm_destroy( calendar_record_h record, bool delete_child )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_alarm_s *temp = (cal_alarm_s*)(record);
+
+       __cal_record_alarm_struct_free(temp);
+
+       return ret;
+}
+
+static int __cal_record_alarm_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       cal_alarm_s *out_data = NULL;
+       cal_alarm_s *src_data = NULL;
+
+       src_data = (cal_alarm_s*)(record);
+
+       out_data = calloc(1, sizeof(cal_alarm_s));
+       retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_alarm_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
+
+       out_data->parent_id = src_data->parent_id;
+       out_data->is_deleted = src_data->is_deleted;
+       out_data->remind_tick = src_data->remind_tick;
+       out_data->remind_tick_unit = src_data->remind_tick_unit;
+       out_data->alarm_description = SAFE_STRDUP(src_data->alarm_description);
+       out_data->alarm_summary = SAFE_STRDUP(src_data->alarm_summary);
+       out_data->alarm_action = src_data->alarm_action;
+       out_data->alarm_attach = SAFE_STRDUP(src_data->alarm_attach);
+       out_data->alarm = src_data->alarm;
+
+       *out_record = (calendar_record_h)out_data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_alarm_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_alarm_s *rec = (cal_alarm_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_ALARM_DESCRIPTION:
+               *out_str = SAFE_STRDUP(rec->alarm_description);
+               break;
+       case CAL_PROPERTY_ALARM_SUMMARY:
+               *out_str = SAFE_STRDUP(rec->alarm_summary);
+               break;
+       case CAL_PROPERTY_ALARM_ATTACH:
+               *out_str = SAFE_STRDUP(rec->alarm_attach);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_alarm_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_alarm_s *rec = (cal_alarm_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_ALARM_DESCRIPTION:
+               *out_str = (rec->alarm_description);
+               break;
+       case CAL_PROPERTY_ALARM_SUMMARY:
+               *out_str = (rec->alarm_summary);
+               break;
+       case CAL_PROPERTY_ALARM_ATTACH:
+               *out_str = (rec->alarm_attach);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_alarm_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       cal_alarm_s *rec = (cal_alarm_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_ALARM_TICK:
+               *out_value = (rec->remind_tick);
+               break;
+       case CAL_PROPERTY_ALARM_TICK_UNIT:
+               *out_value = (rec->remind_tick_unit);
+               break;
+       case CAL_PROPERTY_ALARM_PARENT_ID:
+               *out_value = (rec->parent_id);
+               break;
+       case CAL_PROPERTY_ALARM_ACTION:
+               *out_value = (rec->alarm_action);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_alarm_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value )
+{
+       cal_alarm_s *rec = (cal_alarm_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_ALARM_ALARM:
+               *out_value = rec->alarm;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_alarm_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       cal_alarm_s *rec = (cal_alarm_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_ALARM_DESCRIPTION:
+               CAL_FREE(rec->alarm_description);
+               rec->alarm_description = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_ALARM_SUMMARY:
+               CAL_FREE(rec->alarm_summary);
+               rec->alarm_summary = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_ALARM_ATTACH:
+               CAL_FREE(rec->alarm_attach);
+               rec->alarm_attach = SAFE_STRDUP(value);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_alarm_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       cal_alarm_s *rec = (cal_alarm_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_ALARM_TICK:
+               (rec->remind_tick)=value;
+               break;
+       case CAL_PROPERTY_ALARM_TICK_UNIT:
+               switch (value)
+               {
+               case CALENDAR_ALARM_NONE:
+               case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
+               case CALENDAR_ALARM_TIME_UNIT_MINUTE:
+               case CALENDAR_ALARM_TIME_UNIT_HOUR:
+               case CALENDAR_ALARM_TIME_UNIT_DAY:
+               case CALENDAR_ALARM_TIME_UNIT_WEEK:
+                       (rec->remind_tick_unit)=value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_ALARM_PARENT_ID:
+               (rec->parent_id) = value;
+               break;
+       case CAL_PROPERTY_ALARM_ACTION:
+               switch (value)
+               {
+               case CALENDAR_ALARM_ACTION_AUDIO:
+               case CALENDAR_ALARM_ACTION_DISPLAY:
+               case CALENDAR_ALARM_ACTION_EMAIL:
+                       (rec->alarm_action) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_alarm_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value )
+{
+       cal_alarm_s *rec = (cal_alarm_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_ALARM_ALARM:
+               rec->alarm = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return CALENDAR_ERROR_NONE;
+
+}
diff --git a/common/cal_record_attendee.c b/common/cal_record_attendee.c
new file mode 100644 (file)
index 0000000..efd6c22
--- /dev/null
@@ -0,0 +1,315 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdlib.h>            //calloc
+#include <stdbool.h>           //bool
+#include <string.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+#include "cal_record.h"
+
+static int __cal_record_attendee_create( calendar_record_h* out_record );
+static int __cal_record_attendee_destroy( calendar_record_h record, bool delete_child );
+static int __cal_record_attendee_clone( calendar_record_h record, calendar_record_h* out_record );
+static int __cal_record_attendee_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_attendee_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_attendee_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+static int __cal_record_attendee_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+static int __cal_record_attendee_set_int( calendar_record_h record, unsigned int property_id, int value );
+
+cal_record_plugin_cb_s _cal_record_attendee_plugin_cb = {
+       .create = __cal_record_attendee_create,
+       .destroy = __cal_record_attendee_destroy,
+       .clone = __cal_record_attendee_clone,
+       .get_str = __cal_record_attendee_get_str,
+       .get_str_p = __cal_record_attendee_get_str_p,
+       .get_int = __cal_record_attendee_get_int,
+       .get_double = NULL,
+       .get_lli = NULL,
+       .get_caltime = NULL,
+       .set_str = __cal_record_attendee_set_str,
+       .set_int = __cal_record_attendee_set_int,
+       .set_double = NULL,
+       .set_lli = NULL,
+       .set_caltime = NULL,
+       .add_child_record = NULL,
+       .remove_child_record = NULL,
+       .get_child_record_count = NULL,
+       .get_child_record_at_p = NULL,
+       .clone_child_record_list = NULL
+};
+
+static void __cal_record_attendee_struct_init(cal_attendee_s *record)
+{
+       memset(record,0,sizeof(cal_attendee_s));
+}
+
+static int __cal_record_attendee_create(calendar_record_h* out_record )
+{
+       cal_attendee_s *temp = NULL;
+       int ret= CALENDAR_ERROR_NONE;
+
+       temp = (cal_attendee_s*)calloc(1,sizeof(cal_attendee_s));
+       retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_attendee_s:sch) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       __cal_record_attendee_struct_init(temp);
+
+       *out_record = (calendar_record_h)temp;
+
+       return ret;
+}
+
+static void __cal_record_attendee_struct_free(cal_attendee_s *record)
+{
+       CAL_FREE(record->attendee_number);
+       CAL_FREE(record->attendee_uid);
+       CAL_FREE(record->attendee_group);
+       CAL_FREE(record->attendee_email);
+       CAL_FREE(record->attendee_delegatee_uri);
+       CAL_FREE(record->attendee_delegator_uri);
+       CAL_FREE(record->attendee_name);
+       CAL_FREE(record->attendee_member);
+       CAL_FREE(record);
+}
+
+static int __cal_record_attendee_destroy( calendar_record_h record, bool delete_child )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_attendee_s *temp = (cal_attendee_s*)(record);
+
+       __cal_record_attendee_struct_free(temp);
+
+       return ret;
+}
+
+static int __cal_record_attendee_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       cal_attendee_s *out_data = NULL;
+       cal_attendee_s *src_data = NULL;
+
+       src_data = (cal_attendee_s*)(record);
+
+       out_data = calloc(1, sizeof(cal_attendee_s));
+       retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_attendee_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
+
+       out_data->parent_id = src_data->parent_id;
+       out_data->attendee_cutype = src_data->attendee_cutype;
+       out_data->attendee_ct_index = src_data->attendee_ct_index;
+       out_data->attendee_role = src_data->attendee_role;
+       out_data->attendee_status = src_data->attendee_status;
+       out_data->attendee_rsvp = src_data->attendee_rsvp;
+       out_data->attendee_number = SAFE_STRDUP(src_data->attendee_number);
+       out_data->attendee_uid = SAFE_STRDUP(src_data->attendee_uid);
+       out_data->attendee_group = SAFE_STRDUP(src_data->attendee_group);
+       out_data->attendee_email = SAFE_STRDUP(src_data->attendee_email);
+       out_data->attendee_delegatee_uri = SAFE_STRDUP(src_data->attendee_delegatee_uri);
+       out_data->attendee_delegator_uri = SAFE_STRDUP(src_data->attendee_delegator_uri);
+       out_data->attendee_name = SAFE_STRDUP(src_data->attendee_name);
+       out_data->attendee_member = SAFE_STRDUP(src_data->attendee_member);
+
+       *out_record = (calendar_record_h)out_data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_attendee_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_attendee_s *rec = (cal_attendee_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_ATTENDEE_NUMBER:
+               *out_str = SAFE_STRDUP(rec->attendee_number);
+               break;
+       case CAL_PROPERTY_ATTENDEE_UID:
+               *out_str = SAFE_STRDUP(rec->attendee_uid);
+               break;
+       case CAL_PROPERTY_ATTENDEE_GROUP:
+               *out_str = SAFE_STRDUP(rec->attendee_group);
+               break;
+       case CAL_PROPERTY_ATTENDEE_EMAIL:
+               *out_str = SAFE_STRDUP(rec->attendee_email);
+               break;
+       case CAL_PROPERTY_ATTENDEE_DELEGATEE_URI:
+               *out_str = SAFE_STRDUP(rec->attendee_delegatee_uri);
+               break;
+       case CAL_PROPERTY_ATTENDEE_DELEGATOR_URI:
+               *out_str = SAFE_STRDUP(rec->attendee_delegator_uri);
+               break;
+       case CAL_PROPERTY_ATTENDEE_NAME:
+               *out_str = SAFE_STRDUP(rec->attendee_name);
+               break;
+       case CAL_PROPERTY_ATTENDEE_MEMBER:
+               *out_str = SAFE_STRDUP(rec->attendee_member);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_attendee_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_attendee_s *rec = (cal_attendee_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_ATTENDEE_NUMBER:
+               *out_str = (rec->attendee_number);
+               break;
+       case CAL_PROPERTY_ATTENDEE_UID:
+               *out_str = (rec->attendee_uid);
+               break;
+       case CAL_PROPERTY_ATTENDEE_GROUP:
+               *out_str = (rec->attendee_group);
+               break;
+       case CAL_PROPERTY_ATTENDEE_EMAIL:
+               *out_str = (rec->attendee_email);
+               break;
+       case CAL_PROPERTY_ATTENDEE_DELEGATEE_URI:
+               *out_str = (rec->attendee_delegatee_uri);
+               break;
+       case CAL_PROPERTY_ATTENDEE_DELEGATOR_URI:
+               *out_str = (rec->attendee_delegator_uri);
+               break;
+       case CAL_PROPERTY_ATTENDEE_NAME:
+               *out_str = (rec->attendee_name);
+               break;
+       case CAL_PROPERTY_ATTENDEE_MEMBER:
+               *out_str = (rec->attendee_member);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_attendee_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       cal_attendee_s *rec = (cal_attendee_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_ATTENDEE_CUTYPE:
+               *out_value = (rec->attendee_cutype);
+               break;
+       case CAL_PROPERTY_ATTENDEE_CT_INDEX:
+               *out_value = (rec->attendee_ct_index);
+               break;
+       case CAL_PROPERTY_ATTENDEE_ROLE:
+               *out_value = (rec->attendee_role);
+               break;
+       case CAL_PROPERTY_ATTENDEE_STATUS:
+               *out_value = (rec->attendee_status);
+               break;
+       case CAL_PROPERTY_ATTENDEE_RSVP:
+               *out_value = (rec->attendee_rsvp);
+               break;
+       case CAL_PROPERTY_ATTENDEE_PARENT_ID:
+               *out_value = (rec->parent_id);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_attendee_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       cal_attendee_s *rec = (cal_attendee_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_ATTENDEE_NUMBER:
+               CAL_FREE(rec->attendee_number);
+               rec->attendee_number = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_ATTENDEE_UID:
+               CAL_FREE(rec->attendee_uid);
+               rec->attendee_uid = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_ATTENDEE_GROUP:
+               CAL_FREE(rec->attendee_group);
+               rec->attendee_group = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_ATTENDEE_EMAIL:
+               CAL_FREE(rec->attendee_email);
+               rec->attendee_email = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_ATTENDEE_DELEGATEE_URI:
+               CAL_FREE(rec->attendee_delegatee_uri);
+               rec->attendee_delegatee_uri = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_ATTENDEE_DELEGATOR_URI:
+               CAL_FREE(rec->attendee_delegator_uri);
+               rec->attendee_delegator_uri = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_ATTENDEE_NAME:
+               CAL_FREE(rec->attendee_name);
+               rec->attendee_name = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_ATTENDEE_MEMBER:
+               CAL_FREE(rec->attendee_member);
+               rec->attendee_member = SAFE_STRDUP(value);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_attendee_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       cal_attendee_s *rec = (cal_attendee_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_ATTENDEE_CUTYPE:
+               (rec->attendee_cutype) = value;
+               break;
+       case CAL_PROPERTY_ATTENDEE_CT_INDEX:
+               (rec->attendee_ct_index) = value;
+               break;
+       case CAL_PROPERTY_ATTENDEE_ROLE:
+               (rec->attendee_role) = value;
+               break;
+       case CAL_PROPERTY_ATTENDEE_STATUS:
+               (rec->attendee_status) = value;
+               break;
+       case CAL_PROPERTY_ATTENDEE_RSVP:
+               (rec->attendee_rsvp) = value;
+               break;
+       case CAL_PROPERTY_ATTENDEE_PARENT_ID:
+               (rec->parent_id) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/cal_record_calendar.c b/common/cal_record_calendar.c
new file mode 100644 (file)
index 0000000..143880b
--- /dev/null
@@ -0,0 +1,354 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdlib.h>            //calloc
+#include <stdbool.h>           //bool
+#include <string.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+#include "cal_record.h"
+
+static int __cal_record_calendar_create( calendar_record_h* out_record );
+static int __cal_record_calendar_destroy( calendar_record_h record, bool delete_child );
+static int __cal_record_calendar_clone( calendar_record_h record, calendar_record_h* out_record );
+static int __cal_record_calendar_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_calendar_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_calendar_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+static int __cal_record_calendar_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+static int __cal_record_calendar_set_int( calendar_record_h record, unsigned int property_id, int value );
+
+cal_record_plugin_cb_s _cal_record_calendar_plugin_cb = {
+       .create = __cal_record_calendar_create,
+       .destroy = __cal_record_calendar_destroy,
+       .clone = __cal_record_calendar_clone,
+       .get_str = __cal_record_calendar_get_str,
+       .get_str_p = __cal_record_calendar_get_str_p,
+       .get_int = __cal_record_calendar_get_int,
+       .get_double = NULL,
+       .get_lli = NULL,
+       .get_caltime = NULL,
+       .set_str = __cal_record_calendar_set_str,
+       .set_int = __cal_record_calendar_set_int,
+       .set_double = NULL,
+       .set_lli = NULL,
+       .set_caltime = NULL,
+       .add_child_record = NULL,
+       .remove_child_record = NULL,
+       .get_child_record_count = NULL,
+       .get_child_record_at_p = NULL,
+       .clone_child_record_list = NULL
+};
+
+static void __cal_record_calendar_struct_init(cal_calendar_s *record)
+{
+       memset(record,0,sizeof(cal_calendar_s));
+       record->index = -1;
+       record->visibility = true;
+       record->account_id = LOCAL_ACCOUNT_ID;
+       record->sync_event = 1;
+}
+
+static int __cal_record_calendar_create( calendar_record_h* out_record )
+{
+       cal_calendar_s *temp = NULL;
+       int ret= CALENDAR_ERROR_NONE;
+
+       temp = (cal_calendar_s*)calloc(1,sizeof(cal_calendar_s));
+       retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_calendar_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       __cal_record_calendar_struct_init(temp);
+
+       *out_record = (calendar_record_h)temp;
+
+       return ret;
+}
+
+static void __cal_record_calendar_struct_free(cal_calendar_s *record)
+{
+       CAL_FREE(record->uid);
+       CAL_FREE(record->name);
+       CAL_FREE(record->description);
+       CAL_FREE(record->color);
+       CAL_FREE(record->location);
+       CAL_FREE(record->sync_data1);
+       CAL_FREE(record->sync_data2);
+       CAL_FREE(record->sync_data3);
+       CAL_FREE(record->sync_data4);
+       CAL_FREE(record);
+}
+
+static int __cal_record_calendar_destroy( calendar_record_h record, bool delete_child )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_calendar_s *temp = (cal_calendar_s*)(record);
+
+       __cal_record_calendar_struct_free(temp);
+
+       return ret;
+}
+
+static int __cal_record_calendar_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       cal_calendar_s *out_data = NULL;
+       cal_calendar_s *src_data = NULL;
+
+       src_data = (cal_calendar_s*)(record);
+
+       out_data = calloc(1, sizeof(cal_calendar_s));
+       retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_calendar_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+
+       CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
+
+       out_data->index = src_data->index;
+       out_data->store_type = src_data->store_type;
+       out_data->uid = SAFE_STRDUP(src_data->uid);
+       out_data->updated = src_data->updated;
+       out_data->name = SAFE_STRDUP(src_data->name);
+       out_data->description = SAFE_STRDUP(src_data->description);
+       out_data->color = SAFE_STRDUP(src_data->color);
+       out_data->location = SAFE_STRDUP(src_data->location);
+       out_data->visibility = src_data->visibility;
+       out_data->sync_event = src_data->sync_event;
+       out_data->is_deleted = src_data->is_deleted;
+       out_data->account_id = src_data->account_id;
+       out_data->sync_data1 = SAFE_STRDUP(src_data->sync_data1);
+       out_data->sync_data2 = SAFE_STRDUP(src_data->sync_data2);
+       out_data->sync_data3 = SAFE_STRDUP(src_data->sync_data3);
+       out_data->sync_data4 = SAFE_STRDUP(src_data->sync_data4);
+       out_data->mode = src_data->mode;
+
+       *out_record = (calendar_record_h)out_data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_calendar_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_calendar_s *cal_rec = (cal_calendar_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_CALENDAR_UID:
+               *out_str = SAFE_STRDUP(cal_rec->uid);
+               break;
+       case CAL_PROPERTY_CALENDAR_NAME:
+               *out_str = SAFE_STRDUP(cal_rec->name);
+               break;
+       case CAL_PROPERTY_CALENDAR_DESCRIPTION:
+               *out_str = SAFE_STRDUP(cal_rec->description);
+               break;
+       case CAL_PROPERTY_CALENDAR_COLOR:
+               *out_str = SAFE_STRDUP(cal_rec->color);
+               break;
+       case CAL_PROPERTY_CALENDAR_LOCATION:
+               *out_str = SAFE_STRDUP(cal_rec->location);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA1:
+               *out_str = SAFE_STRDUP(cal_rec->sync_data1);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA2:
+               *out_str = SAFE_STRDUP(cal_rec->sync_data2);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA3:
+               *out_str = SAFE_STRDUP(cal_rec->sync_data3);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA4:
+               *out_str = SAFE_STRDUP(cal_rec->sync_data4);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_calendar_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_calendar_s *cal_rec = (cal_calendar_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_CALENDAR_UID:
+               *out_str = (cal_rec->uid);
+               break;
+       case CAL_PROPERTY_CALENDAR_NAME:
+               *out_str = (cal_rec->name);
+               break;
+       case CAL_PROPERTY_CALENDAR_DESCRIPTION:
+               *out_str = (cal_rec->description);
+               break;
+       case CAL_PROPERTY_CALENDAR_COLOR:
+               *out_str = (cal_rec->color);
+               break;
+       case CAL_PROPERTY_CALENDAR_LOCATION:
+               *out_str = (cal_rec->location);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA1:
+               *out_str = (cal_rec->sync_data1);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA2:
+               *out_str = (cal_rec->sync_data2);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA3:
+               *out_str = (cal_rec->sync_data3);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA4:
+               *out_str = (cal_rec->sync_data4);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_calendar_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       cal_calendar_s *cal_rec = (cal_calendar_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_CALENDAR_ID:
+               *out_value = (cal_rec->index);
+               break;
+       case CAL_PROPERTY_CALENDAR_VISIBILITY:
+               *out_value = (cal_rec->visibility);
+               break;
+       case CAL_PROPERTY_CALENDAR_ACCOUNT_ID:
+               *out_value = (cal_rec->account_id);
+               break;
+       case CAL_PROPERTY_CALENDAR_STORE_TYPE:
+               *out_value = (cal_rec->store_type);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_EVENT:
+               *out_value = (cal_rec->sync_event);
+               break;
+       case CAL_PROPERTY_CALENDAR_MODE:
+               *out_value = (cal_rec->mode);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_calendar_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       cal_calendar_s *cal_rec = (cal_calendar_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_CALENDAR_UID:
+               CAL_FREE(cal_rec->uid);
+               cal_rec->uid = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_CALENDAR_NAME:
+               CAL_FREE(cal_rec->name);
+               cal_rec->name = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_CALENDAR_DESCRIPTION:
+               CAL_FREE(cal_rec->description);
+               cal_rec->description = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_CALENDAR_COLOR:
+               CAL_FREE(cal_rec->color);
+               cal_rec->color = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_CALENDAR_LOCATION:
+               CAL_FREE(cal_rec->location);
+               cal_rec->location = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA1:
+               CAL_FREE(cal_rec->sync_data1);
+               cal_rec->sync_data1 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA2:
+               CAL_FREE(cal_rec->sync_data2);
+               cal_rec->sync_data2 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA3:
+               CAL_FREE(cal_rec->sync_data3);
+               cal_rec->sync_data3 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA4:
+               CAL_FREE(cal_rec->sync_data4);
+               cal_rec->sync_data4 = SAFE_STRDUP(value);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_calendar_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       cal_calendar_s *cal_rec = (cal_calendar_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_CALENDAR_ID:
+               (cal_rec->index) = value;
+               break;
+       case CAL_PROPERTY_CALENDAR_VISIBILITY:
+               (cal_rec->visibility) = value;
+               break;
+       case CAL_PROPERTY_CALENDAR_ACCOUNT_ID:
+               retvm_if(cal_rec->index > 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter : property_id(%d) is a write-once value (calendar)", property_id);
+               (cal_rec->account_id) = value;
+               break;
+       case CAL_PROPERTY_CALENDAR_STORE_TYPE:
+               switch (value) {
+               case CALENDAR_BOOK_TYPE_NONE:
+               case CALENDAR_BOOK_TYPE_EVENT:
+               case CALENDAR_BOOK_TYPE_TODO:
+                       (cal_rec->store_type) = value;
+                       break;
+               default:
+                       ERR("Invalid parameter : store type is invalid value (%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_EVENT:
+               switch (value) {
+               case CALENDAR_BOOK_SYNC_EVENT_FOR_ME:
+               case CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_REMAIN:
+               case CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_DELETE:
+                       (cal_rec->sync_event) = value;
+                       break;
+               default:
+                       ERR("Invalid parameter : sync event is invalid value (%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_CALENDAR_MODE:
+               retvm_if (value != CALENDAR_BOOK_MODE_NONE && value != CALENDAR_BOOK_MODE_RECORD_READONLY,
+                               CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter : mode type is invalid value (%d)", value);
+               (cal_rec->mode) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/cal_record_event.c b/common/cal_record_event.c
new file mode 100644 (file)
index 0000000..e0ca148
--- /dev/null
@@ -0,0 +1,1066 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdlib.h>            //calloc
+#include <stdbool.h>           //bool
+#include <string.h>
+
+#include "calendar_list.h"
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_list.h"
+#include "cal_record.h"
+
+static int __cal_record_event_create( calendar_record_h* out_record );
+static int __cal_record_event_destroy( calendar_record_h record, bool delete_child );
+static int __cal_record_event_clone( calendar_record_h record, calendar_record_h* out_record );
+static int __cal_record_event_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_event_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_event_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+static int __cal_record_event_get_double( calendar_record_h record, unsigned int property_id, double* out_value );
+static int __cal_record_event_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value );
+static int __cal_record_event_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value );
+static int __cal_record_event_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+static int __cal_record_event_set_int( calendar_record_h record, unsigned int property_id, int value );
+static int __cal_record_event_set_double( calendar_record_h record, unsigned int property_id, double value );
+static int __cal_record_event_set_lli( calendar_record_h record, unsigned int property_id, long long int value );
+static int __cal_record_event_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value );
+static int __cal_record_event_add_child_record( calendar_record_h record, unsigned int property_id, calendar_record_h child_record );
+static int __cal_record_event_remove_child_record( calendar_record_h record, unsigned int property_id, calendar_record_h child_record );
+static int __cal_record_event_get_child_record_count( calendar_record_h record, unsigned int property_id, unsigned int* count  );
+static int __cal_record_event_get_child_record_at_p( calendar_record_h record, unsigned int property_id, int index, calendar_record_h* child_record );
+static int __cal_record_event_clone_child_record_list( calendar_record_h record, unsigned int property_id, calendar_list_h* out_list );
+
+cal_record_plugin_cb_s _cal_record_event_plugin_cb = {
+       .create = __cal_record_event_create,
+       .destroy = __cal_record_event_destroy,
+       .clone = __cal_record_event_clone,
+       .get_str = __cal_record_event_get_str,
+       .get_str_p = __cal_record_event_get_str_p,
+       .get_int = __cal_record_event_get_int,
+       .get_double = __cal_record_event_get_double,
+       .get_lli = __cal_record_event_get_lli,
+       .get_caltime = __cal_record_event_get_caltime,
+       .set_str = __cal_record_event_set_str,
+       .set_int = __cal_record_event_set_int,
+       .set_double = __cal_record_event_set_double,
+       .set_lli = __cal_record_event_set_lli,
+       .set_caltime = __cal_record_event_set_caltime,
+       .add_child_record = __cal_record_event_add_child_record,
+       .remove_child_record = __cal_record_event_remove_child_record,
+       .get_child_record_count = __cal_record_event_get_child_record_count,
+       .get_child_record_at_p = __cal_record_event_get_child_record_at_p,
+       .clone_child_record_list = __cal_record_event_clone_child_record_list
+};
+
+static void __cal_record_event_struct_init(cal_event_s *record)
+{
+       memset(record,0,sizeof(cal_event_s));
+
+       record->meeting_status = CALENDAR_MEETING_STATUS_NOTMEETING;
+       record->calendar_id = DEFAULT_EVENT_CALENDAR_BOOK_ID;
+
+       record->index = CAL_INVALID_ID;
+       record->timezone = 0;
+       record->contact_id = CAL_INVALID_ID;
+       record->busy_status = 2;
+       record->summary = NULL;
+       record->description = NULL;
+       record->location= NULL;
+       record->categories = NULL;
+       record->exdate = NULL;
+       record->organizer_email = NULL;
+       record->organizer_name = NULL;
+       record->uid= NULL;
+       record->original_event_id = CAL_INVALID_ID;
+       record->event_status = CALENDAR_EVENT_STATUS_NONE;
+
+       record->is_deleted = 0;
+       record->priority = CALENDAR_EVENT_PRIORITY_NONE;
+       record->latitude = CALENDAR_RECORD_NO_COORDINATE; // set default 1000 out of range(-180 ~ 180)
+       record->longitude = CALENDAR_RECORD_NO_COORDINATE; // set default 1000 out of range(-180 ~ 180)
+       record->freq = CALENDAR_RECURRENCE_NONE;
+       record->wkst = CALENDAR_SUNDAY;
+       record->until.time.utime = CALENDAR_RECORD_NO_UNTIL;
+
+       record->alarm_list = calloc(1, sizeof(cal_list_s));
+       record->attendee_list = calloc(1, sizeof(cal_list_s));
+       record->exception_list = calloc(1, sizeof(cal_list_s));
+       record->extended_list = calloc(1, sizeof(cal_list_s));
+
+       return ;
+}
+
+static int __cal_record_event_create( calendar_record_h* out_record )
+{
+       cal_event_s *temp = NULL;
+       int ret= CALENDAR_ERROR_NONE;
+
+       temp = (cal_event_s*)calloc(1, sizeof(cal_event_s));
+       retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_event_s:sch) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       __cal_record_event_struct_init(temp);
+
+       *out_record = (calendar_record_h)temp;
+
+       return ret;
+}
+
+static void __cal_record_event_struct_free(cal_event_s *record, bool delete_child)
+{
+       CAL_FREE(record->summary);
+       CAL_FREE(record->description);
+       CAL_FREE(record->location);
+       CAL_FREE(record->categories);
+       CAL_FREE(record->exdate);
+       CAL_FREE(record->uid);
+       CAL_FREE(record->organizer_name);
+       CAL_FREE(record->organizer_email);
+       CAL_FREE(record->start_tzid);
+       CAL_FREE(record->end_tzid);
+
+       CAL_FREE(record->bysecond);
+       CAL_FREE(record->byminute);
+       CAL_FREE(record->byhour);
+       CAL_FREE(record->byday);
+       CAL_FREE(record->bymonthday);
+       CAL_FREE(record->byyearday);
+       CAL_FREE(record->byweekno);
+       CAL_FREE(record->bymonth);
+       CAL_FREE(record->bysetpos);
+
+       CAL_FREE(record->recurrence_id);
+       CAL_FREE(record->rdate);
+       CAL_FREE(record->sync_data1);
+       CAL_FREE(record->sync_data2);
+       CAL_FREE(record->sync_data3);
+       CAL_FREE(record->sync_data4);
+
+       calendar_list_destroy((calendar_list_h)record->alarm_list, delete_child);
+       calendar_list_destroy((calendar_list_h)record->attendee_list, delete_child);
+       calendar_list_destroy((calendar_list_h)record->exception_list, delete_child);
+       calendar_list_destroy((calendar_list_h)record->extended_list, delete_child);
+
+       CAL_FREE(record);
+}
+
+static int __cal_record_event_destroy( calendar_record_h record, bool delete_child )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_event_s *temp = (cal_event_s*)(record);
+
+       __cal_record_event_struct_free(temp, delete_child);
+
+       return ret;
+}
+
+static int __cal_record_event_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       cal_event_s *out_data = NULL;
+       cal_event_s *src_data = NULL;
+
+       src_data = (cal_event_s*)(record);
+
+       out_data = calloc(1, sizeof(cal_event_s));
+       retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_event_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
+
+       out_data->index = src_data->index;
+       out_data->calendar_id = src_data->calendar_id;
+
+       out_data->summary = SAFE_STRDUP(src_data->summary);
+       out_data->description = SAFE_STRDUP(src_data->description);
+       out_data->location = SAFE_STRDUP(src_data->location);
+       out_data->categories = SAFE_STRDUP(src_data->categories);
+       out_data->exdate = SAFE_STRDUP(src_data->exdate);
+
+       out_data->event_status = src_data->event_status;
+       out_data->priority = src_data->priority;
+       out_data->timezone = src_data->timezone;
+       out_data->contact_id = src_data->contact_id;
+       out_data->busy_status = src_data->busy_status;
+       out_data->sensitivity = src_data->sensitivity;
+       out_data->meeting_status = src_data->meeting_status;
+
+       out_data->uid = SAFE_STRDUP(src_data->uid);
+       out_data->organizer_name = SAFE_STRDUP(src_data->organizer_name);
+       out_data->organizer_email = SAFE_STRDUP(src_data->organizer_email);
+
+       out_data->original_event_id = src_data->original_event_id;
+       out_data->latitude = src_data->latitude;
+       out_data->longitude = src_data->longitude;
+       out_data->email_id = src_data->email_id;
+       out_data->created_time = src_data->created_time;
+       out_data->is_deleted = src_data->is_deleted;
+       out_data->last_mod = src_data->last_mod;
+       out_data->freq = src_data->freq;
+       out_data->range_type = src_data->range_type;
+       out_data->until = src_data->until;
+
+       out_data->count = src_data->count;
+       out_data->interval = src_data->interval;
+       out_data->bysecond = SAFE_STRDUP(src_data->bysecond);
+       out_data->byminute = SAFE_STRDUP(src_data->byminute);
+       out_data->byhour = SAFE_STRDUP(src_data->byhour);
+       out_data->byday = SAFE_STRDUP(src_data->byday);
+       out_data->bymonthday = SAFE_STRDUP(src_data->bymonthday);
+       out_data->byyearday = SAFE_STRDUP(src_data->byyearday);
+       out_data->byweekno = SAFE_STRDUP(src_data->byweekno);
+       out_data->bymonth = SAFE_STRDUP(src_data->bymonth);
+       out_data->bysetpos = SAFE_STRDUP(src_data->bysetpos);
+       out_data->wkst = src_data->wkst;
+       out_data->recurrence_id = SAFE_STRDUP(src_data->recurrence_id);
+       out_data->rdate = SAFE_STRDUP(src_data->rdate);
+       out_data->has_attendee = src_data->has_attendee;
+       out_data->has_alarm = src_data->has_alarm;
+       out_data->system_type = src_data->system_type;
+       out_data->updated = src_data->updated;
+
+       out_data->sync_data1 = SAFE_STRDUP(src_data->sync_data1);
+       out_data->sync_data2 = SAFE_STRDUP(src_data->sync_data2);
+       out_data->sync_data3 = SAFE_STRDUP(src_data->sync_data3);
+       out_data->sync_data4 = SAFE_STRDUP(src_data->sync_data4);
+
+       out_data->start = src_data->start;
+       out_data->start_tzid = SAFE_STRDUP(src_data->start_tzid);
+       out_data->end = src_data->end;
+       out_data->end_tzid = SAFE_STRDUP(src_data->end_tzid);
+
+       _cal_list_clone((calendar_list_h)src_data->alarm_list, (calendar_list_h *)&out_data->alarm_list);
+       _cal_list_clone((calendar_list_h)src_data->attendee_list, (calendar_list_h *)&out_data->attendee_list);
+       _cal_list_clone((calendar_list_h)src_data->exception_list, (calendar_list_h *)&out_data->exception_list);
+       _cal_list_clone((calendar_list_h)src_data->extended_list, (calendar_list_h *)&out_data->extended_list);
+
+       *out_record = (calendar_record_h)out_data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_event_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_event_s *rec = (cal_event_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_EVENT_SUMMARY:
+               *out_str = SAFE_STRDUP(rec->summary);
+               break;
+       case CAL_PROPERTY_EVENT_DESCRIPTION:
+               *out_str = SAFE_STRDUP(rec->description);
+               break;
+       case CAL_PROPERTY_EVENT_LOCATION:
+               *out_str = SAFE_STRDUP(rec->location);
+               break;
+       case CAL_PROPERTY_EVENT_CATEGORIES:
+               *out_str = SAFE_STRDUP(rec->categories);
+               break;
+       case CAL_PROPERTY_EVENT_EXDATE:
+               *out_str = SAFE_STRDUP(rec->exdate);
+               break;
+       case CAL_PROPERTY_EVENT_UID:
+               *out_str = SAFE_STRDUP(rec->uid);
+               break;
+       case CAL_PROPERTY_EVENT_ORGANIZER_NAME:
+               *out_str = SAFE_STRDUP(rec->organizer_name);
+               break;
+       case CAL_PROPERTY_EVENT_ORGANIZER_EMAIL:
+               *out_str = SAFE_STRDUP(rec->organizer_email);
+               break;
+       case CAL_PROPERTY_EVENT_BYSECOND:
+               *out_str = SAFE_STRDUP(rec->bysecond);
+               break;
+       case CAL_PROPERTY_EVENT_BYMINUTE:
+               *out_str = SAFE_STRDUP(rec->byminute);
+               break;
+       case CAL_PROPERTY_EVENT_BYHOUR:
+               *out_str = SAFE_STRDUP(rec->byhour);
+               break;
+       case CAL_PROPERTY_EVENT_BYDAY:
+               *out_str = SAFE_STRDUP(rec->byday);
+               break;
+       case CAL_PROPERTY_EVENT_BYMONTHDAY:
+               *out_str = SAFE_STRDUP(rec->bymonthday);
+               break;
+       case CAL_PROPERTY_EVENT_BYYEARDAY:
+               *out_str = SAFE_STRDUP(rec->byyearday);
+               break;
+       case CAL_PROPERTY_EVENT_BYWEEKNO:
+               *out_str = SAFE_STRDUP(rec->byweekno);
+               break;
+       case CAL_PROPERTY_EVENT_BYMONTH:
+               *out_str = SAFE_STRDUP(rec->bymonth);
+               break;
+       case CAL_PROPERTY_EVENT_BYSETPOS:
+               *out_str = SAFE_STRDUP(rec->bysetpos);
+               break;
+       case CAL_PROPERTY_EVENT_RECURRENCE_ID:
+               *out_str = SAFE_STRDUP(rec->recurrence_id);
+               break;
+       case CAL_PROPERTY_EVENT_RDATE:
+               *out_str = SAFE_STRDUP(rec->rdate);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA1:
+               *out_str = SAFE_STRDUP(rec->sync_data1);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA2:
+               *out_str = SAFE_STRDUP(rec->sync_data2);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA3:
+               *out_str = SAFE_STRDUP(rec->sync_data3);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA4:
+               *out_str = SAFE_STRDUP(rec->sync_data4);
+               break;
+       case CAL_PROPERTY_EVENT_START_TZID:
+               *out_str = SAFE_STRDUP(rec->start_tzid);
+               break;
+       case CAL_PROPERTY_EVENT_END_TZID:
+               *out_str = SAFE_STRDUP(rec->end_tzid);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_event_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_event_s *rec = (cal_event_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_EVENT_SUMMARY:
+               *out_str = (rec->summary);
+               break;
+       case CAL_PROPERTY_EVENT_DESCRIPTION:
+               *out_str = (rec->description);
+               break;
+       case CAL_PROPERTY_EVENT_LOCATION:
+               *out_str = (rec->location);
+               break;
+       case CAL_PROPERTY_EVENT_CATEGORIES:
+               *out_str = (rec->categories);
+               break;
+       case CAL_PROPERTY_EVENT_EXDATE:
+               *out_str = (rec->exdate);
+               break;
+       case CAL_PROPERTY_EVENT_UID:
+               *out_str = (rec->uid);
+               break;
+       case CAL_PROPERTY_EVENT_ORGANIZER_NAME:
+               *out_str = (rec->organizer_name);
+               break;
+       case CAL_PROPERTY_EVENT_ORGANIZER_EMAIL:
+               *out_str = (rec->organizer_email);
+               break;
+       case CAL_PROPERTY_EVENT_BYSECOND:
+               *out_str = (rec->bysecond);
+               break;
+       case CAL_PROPERTY_EVENT_BYMINUTE:
+               *out_str = (rec->byminute);
+               break;
+       case CAL_PROPERTY_EVENT_BYHOUR:
+               *out_str = (rec->byhour);
+               break;
+       case CAL_PROPERTY_EVENT_BYDAY:
+               *out_str = (rec->byday);
+               break;
+       case CAL_PROPERTY_EVENT_BYMONTHDAY:
+               *out_str = (rec->bymonthday);
+               break;
+       case CAL_PROPERTY_EVENT_BYYEARDAY:
+               *out_str = (rec->byyearday);
+               break;
+       case CAL_PROPERTY_EVENT_BYWEEKNO:
+               *out_str = (rec->byweekno);
+               break;
+       case CAL_PROPERTY_EVENT_BYMONTH:
+               *out_str = (rec->bymonth);
+               break;
+       case CAL_PROPERTY_EVENT_BYSETPOS:
+               *out_str = (rec->bysetpos);
+               break;
+       case CAL_PROPERTY_EVENT_RECURRENCE_ID:
+               *out_str = (rec->recurrence_id);
+               break;
+       case CAL_PROPERTY_EVENT_RDATE:
+               *out_str = (rec->rdate);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA1:
+               *out_str = (rec->sync_data1);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA2:
+               *out_str = (rec->sync_data2);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA3:
+               *out_str = (rec->sync_data3);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA4:
+               *out_str = (rec->sync_data4);
+               break;
+       case CAL_PROPERTY_EVENT_START_TZID:
+               *out_str = (rec->start_tzid);
+               break;
+       case CAL_PROPERTY_EVENT_END_TZID:
+               *out_str = (rec->end_tzid);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_event_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       cal_event_s *rec = (cal_event_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_EVENT_ID:
+               *out_value = (rec->index);
+               break;
+       case CAL_PROPERTY_EVENT_CALENDAR_ID:
+               *out_value = (rec->calendar_id);
+               break;
+       case CAL_PROPERTY_EVENT_EVENT_STATUS:
+               *out_value = (rec->event_status);
+               break;
+       case CAL_PROPERTY_EVENT_PRIORITY:
+               *out_value = (rec->priority);
+               break;
+       case CAL_PROPERTY_EVENT_TIMEZONE:
+               *out_value = (rec->timezone);
+               break;
+       case CAL_PROPERTY_EVENT_CONTACT_ID:
+               *out_value = (rec->contact_id);
+               break;
+       case CAL_PROPERTY_EVENT_BUSY_STATUS:
+               *out_value = (rec->busy_status);
+               break;
+       case CAL_PROPERTY_EVENT_SENSITIVITY:
+               *out_value = (rec->sensitivity);
+               break;
+       case CAL_PROPERTY_EVENT_MEETING_STATUS:
+               *out_value = (rec->meeting_status);
+               break;
+       case CAL_PROPERTY_EVENT_ORIGINAL_EVENT_ID:
+               *out_value = (rec->original_event_id);
+               break;
+       case CAL_PROPERTY_EVENT_EMAIL_ID:
+               *out_value = (rec->email_id);
+               break;
+       case CAL_PROPERTY_EVENT_IS_DELETED:
+               *out_value = (rec->is_deleted);
+               break;
+       case CAL_PROPERTY_EVENT_FREQ:
+               *out_value = (rec->freq);
+               break;
+       case CAL_PROPERTY_EVENT_RANGE_TYPE:
+               *out_value = (rec->range_type);
+               break;
+       case CAL_PROPERTY_EVENT_COUNT:
+               *out_value = (rec->count);
+               break;
+       case CAL_PROPERTY_EVENT_INTERVAL:
+               *out_value = (rec->interval);
+               break;
+       case CAL_PROPERTY_EVENT_WKST:
+               *out_value = (rec->wkst);
+               break;
+       case CAL_PROPERTY_EVENT_HAS_ATTENDEE:
+               *out_value = (rec->has_attendee);
+               break;
+       case CAL_PROPERTY_EVENT_HAS_ALARM:
+               *out_value = (rec->has_alarm);
+               break;
+       case CAL_PROPERTY_EVENT_CALENDAR_SYSTEM_TYPE:
+               *out_value = (rec->system_type);
+               break;
+       case CAL_PROPERTY_EVENT_IS_ALLDAY:
+               *out_value = (rec->is_allday);
+               break;
+       default:
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_event_get_double( calendar_record_h record, unsigned int property_id, double* out_value )
+{
+       cal_event_s *rec = (cal_event_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_EVENT_LATITUDE:
+               *out_value = (rec->latitude);
+               break;
+       case CAL_PROPERTY_EVENT_LONGITUDE:
+               *out_value = (rec->longitude);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_event_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value )
+{
+       cal_event_s *rec = (cal_event_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_EVENT_CREATED_TIME:
+               *out_value = (rec->created_time);
+               break;
+       case CAL_PROPERTY_EVENT_LAST_MODIFIED_TIME:
+               *out_value = (rec->last_mod);
+               break;
+       default:
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_event_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value )
+{
+       cal_event_s *rec = (cal_event_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_EVENT_START:
+               *out_value = rec->start;
+               break;
+       case CAL_PROPERTY_EVENT_END:
+               *out_value = rec->end;
+               break;
+       case CAL_PROPERTY_EVENT_UNTIL:
+               *out_value = rec->until;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_event_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       cal_event_s *rec = (cal_event_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_EVENT_SUMMARY:
+               CAL_FREE(rec->summary);
+               rec->summary = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_DESCRIPTION:
+               CAL_FREE(rec->description);
+               rec->description = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_LOCATION:
+               CAL_FREE(rec->location);
+               rec->location = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_CATEGORIES:
+               CAL_FREE(rec->categories);
+               rec->categories = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_EXDATE:
+               CAL_FREE(rec->exdate);
+               rec->exdate = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_UID:
+               CAL_FREE(rec->uid);
+               rec->uid = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_ORGANIZER_NAME:
+               CAL_FREE(rec->organizer_name);
+               rec->organizer_name = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_ORGANIZER_EMAIL:
+               CAL_FREE(rec->organizer_email);
+               rec->organizer_email = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_BYSECOND:
+               CAL_FREE(rec->bysecond);
+               rec->bysecond = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_BYMINUTE:
+               CAL_FREE(rec->byminute);
+               rec->byminute = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_BYHOUR:
+               CAL_FREE(rec->byhour);
+               rec->byhour = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_BYDAY:
+               CAL_FREE(rec->byday);
+               rec->byday = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_BYMONTHDAY:
+               CAL_FREE(rec->bymonthday);
+               rec->bymonthday = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_BYYEARDAY:
+               CAL_FREE(rec->byyearday);
+               rec->byyearday = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_BYWEEKNO:
+               CAL_FREE(rec->byweekno);
+               rec->byweekno = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_BYMONTH:
+               CAL_FREE(rec->bymonth);
+               rec->bymonth = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_BYSETPOS:
+               CAL_FREE(rec->bysetpos);
+               rec->bysetpos = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_RECURRENCE_ID:
+               CAL_FREE(rec->recurrence_id);
+               rec->recurrence_id = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_RDATE:
+               CAL_FREE(rec->rdate);
+               rec->rdate = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA1:
+               CAL_FREE(rec->sync_data1);
+               rec->sync_data1 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA2:
+               CAL_FREE(rec->sync_data2);
+               rec->sync_data2 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA3:
+               CAL_FREE(rec->sync_data3);
+               rec->sync_data3 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA4:
+               CAL_FREE(rec->sync_data4);
+               rec->sync_data4 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_START_TZID:
+               CAL_FREE(rec->start_tzid);
+               rec->start_tzid = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EVENT_END_TZID:
+               CAL_FREE(rec->end_tzid);
+               rec->end_tzid = SAFE_STRDUP(value);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_event_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       cal_event_s *rec = (cal_event_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_EVENT_ID:
+               (rec->index) = value;
+               break;
+       case CAL_PROPERTY_EVENT_CALENDAR_ID:
+               (rec->calendar_id) = value;
+               break;
+       case CAL_PROPERTY_EVENT_EVENT_STATUS:
+               switch (value) {
+               case CALENDAR_EVENT_STATUS_NONE:
+               case CALENDAR_EVENT_STATUS_TENTATIVE:
+               case CALENDAR_EVENT_STATUS_CONFIRMED:
+               case CALENDAR_EVENT_STATUS_CANCELLED:
+                       (rec->event_status) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_EVENT_PRIORITY:
+               switch (value) {
+               case CALENDAR_EVENT_PRIORITY_NONE:
+               case CALENDAR_EVENT_PRIORITY_LOW:
+               case CALENDAR_EVENT_PRIORITY_NORMAL:
+               case CALENDAR_EVENT_PRIORITY_HIGH:
+                       (rec->priority) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_EVENT_TIMEZONE:
+               (rec->timezone) = value;
+               break;
+       case CAL_PROPERTY_EVENT_CONTACT_ID:
+               (rec->contact_id) = value;
+               break;
+       case CAL_PROPERTY_EVENT_BUSY_STATUS:
+               switch (value) {
+               case CALENDAR_EVENT_BUSY_STATUS_FREE:
+               case CALENDAR_EVENT_BUSY_STATUS_BUSY:
+               case CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE:
+               case CALENDAR_EVENT_BUSY_STATUS_TENTATIVE:
+                       (rec->busy_status) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_EVENT_SENSITIVITY:
+               switch (value) {
+               case CALENDAR_SENSITIVITY_PUBLIC:
+               case CALENDAR_SENSITIVITY_PRIVATE:
+               case CALENDAR_SENSITIVITY_CONFIDENTIAL:
+                       (rec->sensitivity) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_EVENT_MEETING_STATUS:
+               switch (value) {
+               case CALENDAR_MEETING_STATUS_NOTMEETING:
+               case CALENDAR_MEETING_STATUS_MEETING:
+               case CALENDAR_MEETING_STATUS_RECEIVED:
+               case CALENDAR_MEETING_STATUS_CANCELED:
+                       (rec->meeting_status) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_EVENT_ORIGINAL_EVENT_ID:
+               (rec->original_event_id) = value;
+               break;
+       case CAL_PROPERTY_EVENT_EMAIL_ID:
+               (rec->email_id) = value;
+               break;
+       case CAL_PROPERTY_EVENT_IS_DELETED:
+               (rec->is_deleted) = value;
+               break;
+       case CAL_PROPERTY_EVENT_FREQ:
+               switch (value) {
+               case CALENDAR_RECURRENCE_NONE:
+               case CALENDAR_RECURRENCE_DAILY:
+               case CALENDAR_RECURRENCE_WEEKLY:
+               case CALENDAR_RECURRENCE_MONTHLY:
+               case CALENDAR_RECURRENCE_YEARLY:
+                       (rec->freq) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_EVENT_RANGE_TYPE:
+               switch (value) {
+               case CALENDAR_RANGE_UNTIL:
+               case CALENDAR_RANGE_COUNT:
+               case CALENDAR_RANGE_NONE:
+                       (rec->range_type) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_EVENT_COUNT:
+               (rec->count) = value;
+               break;
+       case CAL_PROPERTY_EVENT_INTERVAL:
+               (rec->interval) = value;
+               break;
+       case CAL_PROPERTY_EVENT_WKST:
+               switch (value) {
+               case CALENDAR_SUNDAY:
+               case CALENDAR_MONDAY:
+               case CALENDAR_TUESDAY:
+               case CALENDAR_WEDNESDAY:
+               case CALENDAR_THURSDAY:
+               case CALENDAR_FRIDAY:
+               case CALENDAR_SATURDAY:
+                       (rec->wkst) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_EVENT_HAS_ATTENDEE:
+               (rec->has_attendee) = value;
+               break;
+       case CAL_PROPERTY_EVENT_HAS_ALARM:
+               (rec->has_alarm) = value;
+               break;
+       case CAL_PROPERTY_EVENT_CALENDAR_SYSTEM_TYPE:
+               switch (value) {
+               case CALENDAR_SYSTEM_NONE:
+               case CALENDAR_SYSTEM_GREGORIAN:
+               case CALENDAR_SYSTEM_EAST_ASIAN_LUNISOLAR:
+                       (rec->system_type) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_EVENT_IS_ALLDAY:
+               (rec->is_allday) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_event_set_double( calendar_record_h record, unsigned int property_id, double value )
+{
+       cal_event_s *rec = (cal_event_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_EVENT_LATITUDE:
+               (rec->latitude) = value;
+               break;
+       case CAL_PROPERTY_EVENT_LONGITUDE:
+               (rec->longitude) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_event_set_lli( calendar_record_h record, unsigned int property_id, long long int value )
+{
+       cal_event_s *rec = (cal_event_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_EVENT_CREATED_TIME:
+               (rec->created_time) = value;
+               break;
+       case CAL_PROPERTY_EVENT_LAST_MODIFIED_TIME:
+               (rec->last_mod) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_event_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value )
+{
+       cal_event_s *rec = (cal_event_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_EVENT_START:
+               rec->start = value;
+               break;
+
+       case CAL_PROPERTY_EVENT_END:
+               rec->end = value;
+               break;
+
+       case CAL_PROPERTY_EVENT_UNTIL:
+               rec->until = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_event_reset_child_record_id(calendar_record_h child_record)
+{
+       cal_record_s *record = (cal_record_s*)child_record;
+       retv_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       switch (record->type) {
+       case CAL_RECORD_TYPE_ALARM:
+               ((cal_alarm_s *)record)->id = 0;
+               break;
+       case CAL_RECORD_TYPE_ATTENDEE:
+               ((cal_attendee_s *)record)->id = 0;
+               break;
+       case CAL_RECORD_TYPE_EXTENDED:
+               ((cal_extended_s *)record)->id = 0;
+               break;
+       case CAL_RECORD_TYPE_EVENT:
+               ((cal_event_s *)record)->index = 0;
+               break;
+       default:
+               ERR("Invalid child record type (%d)", record->type);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_event_add_child_record( calendar_record_h record, unsigned int property_id, calendar_record_h child_record )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_event_s *rec = (cal_event_s*)(record);
+       __cal_record_event_reset_child_record_id(child_record);
+
+       switch( property_id ) {
+       case CAL_PROPERTY_EVENT_CALENDAR_ALARM:
+               ret = calendar_list_add((calendar_list_h)rec->alarm_list, child_record);
+               rec->has_alarm = 1;
+               break;
+       case CAL_PROPERTY_EVENT_CALENDAR_ATTENDEE:
+               ret = calendar_list_add((calendar_list_h)rec->attendee_list, child_record);
+               rec->has_attendee = 1;
+               break;
+       case CAL_PROPERTY_EVENT_EXCEPTION:
+               calendar_list_destroy((calendar_list_h)((cal_event_s *)child_record)->exception_list, true);
+               ((cal_event_s *)child_record)->exception_list = calloc(1, sizeof(cal_list_s));
+               ret = calendar_list_add((calendar_list_h)rec->exception_list, child_record);
+               break;
+       case CAL_PROPERTY_EVENT_EXTENDED:
+               ret = calendar_list_add((calendar_list_h)rec->extended_list, child_record);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return ret;
+}
+
+static int __cal_record_event_remove_child_record( calendar_record_h record, unsigned int property_id, calendar_record_h child_record )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_event_s *rec = (cal_event_s *)record;
+       switch (property_id) {
+       case CAL_PROPERTY_EVENT_CALENDAR_ALARM:
+               ret = calendar_list_remove((calendar_list_h)rec->alarm_list, child_record);
+               if (rec->alarm_list->count == 0)
+                       rec->has_alarm = 0;
+               break;
+       case CAL_PROPERTY_EVENT_CALENDAR_ATTENDEE:
+               ret = calendar_list_remove((calendar_list_h)rec->attendee_list, child_record);
+               if (rec->attendee_list->count == 0)
+                       rec->has_attendee = 0;
+               break;
+       case CAL_PROPERTY_EVENT_EXCEPTION:
+               ret = calendar_list_remove((calendar_list_h)rec->exception_list, child_record);
+               break;
+       case CAL_PROPERTY_EVENT_EXTENDED:
+               ret = calendar_list_remove((calendar_list_h)rec->extended_list, child_record);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return ret;
+}
+
+static int __cal_record_event_get_child_record_count( calendar_record_h record, unsigned int property_id, unsigned int* count  )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_event_s *rec = (cal_event_s *)record;
+
+       retv_if(NULL == count, CALENDAR_ERROR_INVALID_PARAMETER);
+       *count = 0;
+
+       switch (property_id) {
+       case CAL_PROPERTY_EVENT_CALENDAR_ALARM:
+               ret = calendar_list_get_count((calendar_list_h)rec->alarm_list, (int *)count);
+               break;
+       case CAL_PROPERTY_EVENT_CALENDAR_ATTENDEE:
+               ret = calendar_list_get_count((calendar_list_h)rec->attendee_list, (int *)count);
+               break;
+       case CAL_PROPERTY_EVENT_EXCEPTION:
+               ret = calendar_list_get_count((calendar_list_h)rec->exception_list, (int *)count);
+               break;
+       case CAL_PROPERTY_EVENT_EXTENDED:
+               ret = calendar_list_get_count((calendar_list_h)rec->extended_list, (int *)count);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return ret;
+}
+
+static int __cal_record_event_get_child_record_at_p( calendar_record_h record, unsigned int property_id, int index, calendar_record_h* child_record)
+{
+       int ret;
+       cal_event_s *rec = (cal_event_s*)(record);
+
+       retv_if(NULL == child_record, CALENDAR_ERROR_INVALID_PARAMETER);
+       *child_record = NULL;
+
+       switch (property_id) {
+       case CAL_PROPERTY_EVENT_CALENDAR_ALARM:
+               ret = _cal_list_get_nth_record_p(rec->alarm_list, index, child_record);
+               break;
+       case CAL_PROPERTY_EVENT_CALENDAR_ATTENDEE:
+               ret = _cal_list_get_nth_record_p(rec->attendee_list, index, child_record);
+               break;
+       case CAL_PROPERTY_EVENT_EXCEPTION:
+               ret = _cal_list_get_nth_record_p(rec->exception_list, index, child_record);
+               break;
+       case CAL_PROPERTY_EVENT_EXTENDED:
+               ret = _cal_list_get_nth_record_p(rec->extended_list, index, child_record);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return ret;
+}
+
+static int __cal_record_event_clone_child_record_list( calendar_record_h record, unsigned int property_id, calendar_list_h* out_list )
+{
+       int ret;
+       cal_event_s *rec = (cal_event_s*)(record);
+
+       retv_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER);
+       *out_list = NULL;
+
+       switch (property_id) {
+       case CAL_PROPERTY_EVENT_CALENDAR_ALARM:
+               ret = _cal_list_clone((calendar_list_h)rec->alarm_list, out_list);
+               break;
+       case CAL_PROPERTY_EVENT_CALENDAR_ATTENDEE:
+               ret = _cal_list_clone((calendar_list_h)rec->attendee_list, out_list);
+               break;
+       case CAL_PROPERTY_EVENT_EXCEPTION:
+               ret = _cal_list_clone((calendar_list_h)rec->exception_list, out_list);
+               break;
+       case CAL_PROPERTY_EVENT_EXTENDED:
+               ret = _cal_list_clone((calendar_list_h)rec->extended_list, out_list);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)", property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return ret;
+}
+
diff --git a/common/cal_record_extended.c b/common/cal_record_extended.c
new file mode 100644 (file)
index 0000000..8b5b04e
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+#include "cal_record.h"
+
+static int __cal_record_extended_create( calendar_record_h* out_record );
+static int __cal_record_extended_destroy( calendar_record_h record, bool delete_child );
+static int __cal_record_extended_clone( calendar_record_h record, calendar_record_h* out_record );
+static int __cal_record_extended_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_extended_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_extended_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+static int __cal_record_extended_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+static int __cal_record_extended_set_int( calendar_record_h record, unsigned int property_id, int value );
+
+cal_record_plugin_cb_s _cal_record_extended_plugin_cb = {
+       .create = __cal_record_extended_create,
+       .destroy = __cal_record_extended_destroy,
+       .clone = __cal_record_extended_clone,
+       .get_str = __cal_record_extended_get_str,
+       .get_str_p = __cal_record_extended_get_str_p,
+       .get_int = __cal_record_extended_get_int,
+       .get_double = NULL,
+       .get_lli = NULL,
+       .get_caltime = NULL,
+       .set_str = __cal_record_extended_set_str,
+       .set_int = __cal_record_extended_set_int,
+       .set_double = NULL,
+       .set_lli = NULL,
+       .set_caltime = NULL,
+       .add_child_record = NULL,
+       .remove_child_record = NULL,
+       .get_child_record_count = NULL,
+       .get_child_record_at_p = NULL,
+       .clone_child_record_list = NULL
+};
+
+static void __cal_record_extended_struct_init(cal_extended_s *record)
+{
+       memset(record,0,sizeof(cal_extended_s));
+}
+
+static int __cal_record_extended_create( calendar_record_h* out_record )
+{
+       cal_extended_s *temp = NULL;
+       int ret= CALENDAR_ERROR_NONE;
+
+       temp = (cal_extended_s*)calloc(1,sizeof(cal_extended_s));
+       retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_extended_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       __cal_record_extended_struct_init(temp);
+
+       *out_record = (calendar_record_h)temp;
+
+       return ret;
+}
+
+static void __cal_record_extended_struct_free(cal_extended_s *record)
+{
+       CAL_FREE(record->key);
+       CAL_FREE(record->value);
+       CAL_FREE(record);
+
+}
+
+static int __cal_record_extended_destroy( calendar_record_h record, bool delete_child )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_extended_s *temp = (cal_extended_s*)(record);
+
+       __cal_record_extended_struct_free(temp);
+
+       return ret;
+}
+
+static int __cal_record_extended_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       cal_extended_s *out_data = NULL;
+       cal_extended_s *src_data = NULL;
+
+       src_data = (cal_extended_s*)(record);
+
+       out_data = calloc(1, sizeof(cal_extended_s));
+       retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_extended_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
+
+       out_data->id = src_data->id;
+       out_data->record_id = src_data->record_id;
+       out_data->record_type = src_data->record_type;
+       out_data->key = SAFE_STRDUP(src_data->key);
+       out_data->value = SAFE_STRDUP(src_data->value);
+
+       *out_record = (calendar_record_h)out_data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_extended_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_extended_s *rec = (cal_extended_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_EXTENDED_KEY:
+               *out_str = SAFE_STRDUP(rec->key);
+               break;
+       case CAL_PROPERTY_EXTENDED_VALUE:
+               *out_str = SAFE_STRDUP(rec->value);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_extended_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_extended_s *rec = (cal_extended_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_EXTENDED_KEY:
+               *out_str = (rec->key);
+               break;
+       case CAL_PROPERTY_EXTENDED_VALUE:
+               *out_str = (rec->value);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_extended_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       cal_extended_s *rec = (cal_extended_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_EXTENDED_ID:
+               *out_value = (rec->id);
+               break;
+       case CAL_PROPERTY_EXTENDED_RECORD_ID:
+               *out_value = (rec->record_id);
+               break;
+       case CAL_PROPERTY_EXTENDED_RECORD_TYPE:
+               *out_value = (rec->record_type);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_extended_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       cal_extended_s *rec = (cal_extended_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_EXTENDED_KEY:
+               CAL_FREE(rec->key);
+               rec->key = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_EXTENDED_VALUE:
+               CAL_FREE(rec->value);
+               rec->value = SAFE_STRDUP(value);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_extended_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       cal_extended_s *rec = (cal_extended_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_EXTENDED_ID:
+               (rec->id) = value;
+               break;
+       case CAL_PROPERTY_EXTENDED_RECORD_ID:
+               retvm_if(rec->id > 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter : property_id(%d) is a write-once value (calendar)", property_id);
+               (rec->record_id) = value;
+               break;
+       case CAL_PROPERTY_EXTENDED_RECORD_TYPE:
+               (rec->record_type) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/cal_record_instance_allday.c b/common/cal_record_instance_allday.c
new file mode 100644 (file)
index 0000000..11e7e7a
--- /dev/null
@@ -0,0 +1,414 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdlib.h>     //calloc
+#include <stdbool.h>        //bool
+#include <string.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+#include "cal_record.h"
+
+static int __cal_record_instance_allday_create( calendar_record_h* out_record );
+static int __cal_record_instance_allday_destroy( calendar_record_h record, bool delete_child );
+static int __cal_record_instance_allday_clone( calendar_record_h record, calendar_record_h* out_record );
+static int __cal_record_instance_allday_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_instance_allday_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_instance_allday_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+static int __cal_record_instance_allday_get_double( calendar_record_h record, unsigned int property_id, double* out_value );
+static int __cal_record_instance_allday_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value );
+static int __cal_record_instance_allday_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value );
+static int __cal_record_instance_allday_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+static int __cal_record_instance_allday_set_int( calendar_record_h record, unsigned int property_id, int value );
+static int __cal_record_instance_allday_set_double( calendar_record_h record, unsigned int property_id, double value );
+static int __cal_record_instance_allday_set_lli( calendar_record_h record, unsigned int property_id, long long int value );
+static int __cal_record_instance_allday_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value );
+
+cal_record_plugin_cb_s _cal_record_instance_allday_plugin_cb = {
+       .create = __cal_record_instance_allday_create,
+       .destroy = __cal_record_instance_allday_destroy,
+       .clone = __cal_record_instance_allday_clone,
+       .get_str = __cal_record_instance_allday_get_str,
+       .get_str_p = __cal_record_instance_allday_get_str_p,
+       .get_int = __cal_record_instance_allday_get_int,
+       .get_double = __cal_record_instance_allday_get_double,
+       .get_lli = __cal_record_instance_allday_get_lli,
+       .get_caltime = __cal_record_instance_allday_get_caltime,
+       .set_str = __cal_record_instance_allday_set_str,
+       .set_int = __cal_record_instance_allday_set_int,
+       .set_double = __cal_record_instance_allday_set_double,
+       .set_lli = __cal_record_instance_allday_set_lli,
+       .set_caltime = __cal_record_instance_allday_set_caltime,
+       .add_child_record = NULL,
+       .remove_child_record = NULL,
+       .get_child_record_count = NULL,
+       .get_child_record_at_p = NULL,
+       .clone_child_record_list = NULL
+};
+
+static void __cal_record_instance_allday_struct_init(cal_instance_allday_s* record)
+{
+       memset(record,0,sizeof(cal_instance_allday_s));
+
+       record->event_status = CALENDAR_EVENT_STATUS_NONE;
+       record->calendar_id = DEFAULT_EVENT_CALENDAR_BOOK_ID;
+       record->event_id = CAL_INVALID_ID;
+
+       record->busy_status = 2;
+       record->summary = NULL;
+       record->description = NULL;
+       record->location= NULL;
+
+       record->latitude = 1000; // set default 1000 out of range(-180 ~ 180)
+       record->longitude = 1000; // set default 1000 out of range(-180 ~ 180)
+
+       return;
+}
+
+static int __cal_record_instance_allday_create( calendar_record_h* out_record )
+{
+       cal_instance_allday_s *temp = NULL;
+       int ret= CALENDAR_ERROR_NONE;
+
+       temp = (cal_instance_allday_s*)calloc(1,sizeof(cal_instance_allday_s));
+       retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_instance_allday_s:sch) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       __cal_record_instance_allday_struct_init(temp);
+
+       *out_record = (calendar_record_h)temp;
+
+       return ret;
+}
+
+static void __cal_record_instance_allday_struct_free(cal_instance_allday_s *record)
+{
+       CAL_FREE(record->summary);
+       CAL_FREE(record->description);
+       CAL_FREE(record->location);
+       CAL_FREE(record->sync_data1);
+
+       CAL_FREE(record);
+}
+
+static int __cal_record_instance_allday_destroy( calendar_record_h record, bool delete_child )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_instance_allday_s *temp = (cal_instance_allday_s*)(record);
+
+       __cal_record_instance_allday_struct_free(temp);
+
+       return ret;
+}
+
+static int __cal_record_instance_allday_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       cal_instance_allday_s *out_data = NULL;
+       cal_instance_allday_s *src_data = NULL;
+
+       src_data = (cal_instance_allday_s*)(record);
+
+       out_data = calloc(1, sizeof(cal_instance_allday_s));
+       retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_instance_allday_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
+
+       out_data->event_id = src_data->event_id;
+       out_data->calendar_id = src_data->calendar_id;
+       out_data->start = src_data->start;
+       out_data->end = src_data->end;
+       out_data->summary = SAFE_STRDUP(src_data->summary);
+       out_data->description = SAFE_STRDUP(src_data->description);
+       out_data->location = SAFE_STRDUP(src_data->location);
+       out_data->busy_status = src_data->busy_status;
+       out_data->event_status = src_data->event_status;
+       out_data->priority = src_data->priority;
+       out_data->sensitivity = src_data->sensitivity;
+       out_data->has_rrule = src_data->has_rrule;
+       out_data->latitude = src_data->latitude;
+       out_data->longitude = src_data->longitude;
+       out_data->has_alarm = src_data->has_alarm;
+       out_data->original_event_id = src_data->original_event_id;
+       out_data->last_mod = src_data->last_mod;
+       out_data->sync_data1 = SAFE_STRDUP(src_data->sync_data1);
+
+       *out_record = (calendar_record_h)out_data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_instance_allday_s *rec = (cal_instance_allday_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_SUMMARY:
+               *out_str = SAFE_STRDUP(rec->summary);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_DESCRIPTION:
+               *out_str = SAFE_STRDUP(rec->description);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_LOCATION:
+               *out_str = SAFE_STRDUP(rec->location);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_SYNC_DATA1:
+               *out_str = SAFE_STRDUP(rec->sync_data1);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_instance_allday_s *rec = (cal_instance_allday_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_SUMMARY:
+               *out_str = (rec->summary);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_DESCRIPTION:
+               *out_str = (rec->description);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_LOCATION:
+               *out_str = (rec->location);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_SYNC_DATA1:
+               *out_str = (rec->sync_data1);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       cal_instance_allday_s *rec = (cal_instance_allday_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EVENT_ID:
+               *out_value = (rec->event_id);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_CALENDAR_ID:
+               *out_value = (rec->calendar_id);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_BUSY_STATUS:
+               *out_value = (rec->busy_status);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EVENT_STATUS:
+               *out_value = (rec->event_status);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_PRIORITY:
+               *out_value = (rec->priority);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_SENSITIVITY:
+               *out_value = (rec->sensitivity);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_HAS_RRULE:
+               *out_value = (rec->has_rrule);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_HAS_ALARM:
+               *out_value = (rec->has_alarm);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_ORIGINAL_EVENT_ID:
+               *out_value = (rec->original_event_id);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_IS_ALLDAY:
+               *out_value = (rec->is_allday);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_get_double( calendar_record_h record, unsigned int property_id, double* out_value )
+{
+       cal_instance_allday_s *rec = (cal_instance_allday_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_LATITUDE:
+               *out_value = (rec->latitude);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_LONGITUDE:
+               *out_value = (rec->longitude);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value )
+{
+       cal_instance_allday_s *rec = (cal_instance_allday_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_LAST_MODIFIED_TIME:
+               *out_value = (rec->last_mod);
+               break;
+       default:
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value )
+{
+       cal_instance_allday_s *rec = (cal_instance_allday_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_START:
+               *out_value = rec->start;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_END:
+               *out_value = rec->end;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       cal_instance_allday_s *rec = (cal_instance_allday_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_SUMMARY:
+               CAL_FREE(rec->summary);
+               rec->summary = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_DESCRIPTION:
+               CAL_FREE(rec->description);
+               rec->description = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_LOCATION:
+               CAL_FREE(rec->location);
+               rec->location = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_SYNC_DATA1:
+               CAL_FREE(rec->sync_data1);
+               rec->sync_data1 = SAFE_STRDUP(value);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       cal_instance_allday_s *rec = (cal_instance_allday_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EVENT_ID:
+               (rec->event_id) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_CALENDAR_ID:
+               (rec->calendar_id) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_BUSY_STATUS:
+               (rec->busy_status) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EVENT_STATUS:
+               (rec->event_status) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_PRIORITY:
+               (rec->priority) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_SENSITIVITY:
+               (rec->sensitivity) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_HAS_RRULE:
+               (rec->has_rrule) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_HAS_ALARM:
+               (rec->has_alarm) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_ORIGINAL_EVENT_ID:
+               (rec->original_event_id) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_set_double( calendar_record_h record, unsigned int property_id, double value )
+{
+       cal_instance_allday_s *rec = (cal_instance_allday_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_LATITUDE:
+               (rec->latitude) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_LONGITUDE:
+               (rec->longitude) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_set_lli( calendar_record_h record, unsigned int property_id, long long int value )
+{
+       cal_instance_allday_s *rec = (cal_instance_allday_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_LAST_MODIFIED_TIME:
+               (rec->last_mod) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value )
+{
+       cal_instance_allday_s *rec = (cal_instance_allday_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_START:
+               rec->start = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_END:
+               rec->end = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/cal_record_instance_allday_extended.c b/common/cal_record_instance_allday_extended.c
new file mode 100644 (file)
index 0000000..4292e1e
--- /dev/null
@@ -0,0 +1,482 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdlib.h>     //calloc
+#include <stdbool.h>        //bool
+#include <string.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+#include "cal_record.h"
+
+static int __cal_record_instance_allday_extended_create( calendar_record_h* out_record );
+static int __cal_record_instance_allday_extended_destroy( calendar_record_h record, bool delete_child );
+static int __cal_record_instance_allday_extended_clone( calendar_record_h record, calendar_record_h* out_record );
+static int __cal_record_instance_allday_extended_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_instance_allday_extended_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_instance_allday_extended_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+static int __cal_record_instance_allday_extended_get_double( calendar_record_h record, unsigned int property_id, double* out_value );
+static int __cal_record_instance_allday_extended_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value );
+static int __cal_record_instance_allday_extended_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value );
+static int __cal_record_instance_allday_extended_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+static int __cal_record_instance_allday_extended_set_int( calendar_record_h record, unsigned int property_id, int value );
+static int __cal_record_instance_allday_extended_set_double( calendar_record_h record, unsigned int property_id, double value );
+static int __cal_record_instance_allday_extended_set_lli( calendar_record_h record, unsigned int property_id, long long int value );
+static int __cal_record_instance_allday_extended_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value );
+
+cal_record_plugin_cb_s _cal_record_instance_allday_extended_plugin_cb = {
+       .create = __cal_record_instance_allday_extended_create,
+       .destroy = __cal_record_instance_allday_extended_destroy,
+       .clone = __cal_record_instance_allday_extended_clone,
+       .get_str = __cal_record_instance_allday_extended_get_str,
+       .get_str_p = __cal_record_instance_allday_extended_get_str_p,
+       .get_int = __cal_record_instance_allday_extended_get_int,
+       .get_double = __cal_record_instance_allday_extended_get_double,
+       .get_lli = __cal_record_instance_allday_extended_get_lli,
+       .get_caltime = __cal_record_instance_allday_extended_get_caltime,
+       .set_str = __cal_record_instance_allday_extended_set_str,
+       .set_int = __cal_record_instance_allday_extended_set_int,
+       .set_double = __cal_record_instance_allday_extended_set_double,
+       .set_lli = __cal_record_instance_allday_extended_set_lli,
+       .set_caltime = __cal_record_instance_allday_extended_set_caltime,
+       .add_child_record = NULL,
+       .remove_child_record = NULL,
+       .get_child_record_count = NULL,
+       .get_child_record_at_p = NULL,
+       .clone_child_record_list = NULL
+};
+
+static void __cal_record_instance_allday_extended_struct_init(cal_instance_allday_extended_s* record)
+{
+       memset(record,0,sizeof(cal_instance_allday_extended_s));
+
+       record->event_status = CALENDAR_EVENT_STATUS_NONE;
+       record->calendar_id = DEFAULT_EVENT_CALENDAR_BOOK_ID;
+       record->event_id = CAL_INVALID_ID;
+
+       record->busy_status = 2;
+       record->summary = NULL;
+       record->description = NULL;
+       record->location= NULL;
+
+       record->latitude = 1000; // set default 1000 out of range(-180 ~ 180)
+       record->longitude = 1000; // set default 1000 out of range(-180 ~ 180)
+
+       return;
+}
+
+static int __cal_record_instance_allday_extended_create( calendar_record_h* out_record )
+{
+       cal_instance_allday_extended_s *temp = NULL;
+       int ret= CALENDAR_ERROR_NONE;
+
+       temp = (cal_instance_allday_extended_s*)calloc(1,sizeof(cal_instance_allday_extended_s));
+       retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_instance_allday_extended_s:sch) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       __cal_record_instance_allday_extended_struct_init(temp);
+
+       *out_record = (calendar_record_h)temp;
+
+       return ret;
+}
+
+static void __cal_record_instance_allday_extended_struct_free(cal_instance_allday_extended_s *record)
+{
+       CAL_FREE(record->summary);
+       CAL_FREE(record->description);
+       CAL_FREE(record->location);
+       CAL_FREE(record->organizer_name);
+       CAL_FREE(record->categories);
+       CAL_FREE(record->sync_data1);
+       CAL_FREE(record->sync_data2);
+       CAL_FREE(record->sync_data3);
+       CAL_FREE(record->sync_data4);
+
+       CAL_FREE(record);
+}
+
+static int __cal_record_instance_allday_extended_destroy( calendar_record_h record, bool delete_child )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_instance_allday_extended_s *temp = (cal_instance_allday_extended_s*)(record);
+
+       __cal_record_instance_allday_extended_struct_free(temp);
+
+       return ret;
+}
+
+static int __cal_record_instance_allday_extended_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       cal_instance_allday_extended_s *out_data = NULL;
+       cal_instance_allday_extended_s *src_data = NULL;
+
+       src_data = (cal_instance_allday_extended_s*)(record);
+
+       out_data = calloc(1, sizeof(cal_instance_allday_extended_s));
+       retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_instance_allday_extended_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
+
+       out_data->event_id = src_data->event_id;
+       out_data->calendar_id = src_data->calendar_id;
+       out_data->start = src_data->start;
+       out_data->end = src_data->end;
+       out_data->summary = SAFE_STRDUP(src_data->summary);
+       out_data->description = SAFE_STRDUP(src_data->description);
+       out_data->location = SAFE_STRDUP(src_data->location);
+       out_data->busy_status = src_data->busy_status;
+       out_data->event_status = src_data->event_status;
+       out_data->priority = src_data->priority;
+       out_data->sensitivity = src_data->sensitivity;
+       out_data->has_rrule = src_data->has_rrule;
+       out_data->latitude = src_data->latitude;
+       out_data->longitude = src_data->longitude;
+       out_data->has_alarm = src_data->has_alarm;
+       out_data->original_event_id = src_data->original_event_id;
+       out_data->last_mod = src_data->last_mod;
+       out_data->organizer_name = SAFE_STRDUP(src_data->organizer_name);
+       out_data->categories = SAFE_STRDUP(src_data->categories);
+       out_data->sync_data1 = SAFE_STRDUP(src_data->sync_data1);
+       out_data->sync_data2 = SAFE_STRDUP(src_data->sync_data2);
+       out_data->sync_data3 = SAFE_STRDUP(src_data->sync_data3);
+       out_data->sync_data4 = SAFE_STRDUP(src_data->sync_data4);
+
+       *out_record = (calendar_record_h)out_data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_extended_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_instance_allday_extended_s *rec = (cal_instance_allday_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SUMMARY:
+               *out_str = SAFE_STRDUP(rec->summary);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_DESCRIPTION:
+               *out_str = SAFE_STRDUP(rec->description);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LOCATION:
+               *out_str = SAFE_STRDUP(rec->location);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA1:
+               *out_str = SAFE_STRDUP(rec->sync_data1);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_ORGANIZER_NAME:
+               *out_str = SAFE_STRDUP(rec->organizer_name);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_CATEGORIES:
+               *out_str = SAFE_STRDUP(rec->categories);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA2:
+               *out_str = SAFE_STRDUP(rec->sync_data2);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA3:
+               *out_str = SAFE_STRDUP(rec->sync_data3);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA4:
+               *out_str = SAFE_STRDUP(rec->sync_data4);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_extended_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_instance_allday_extended_s *rec = (cal_instance_allday_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SUMMARY:
+               *out_str = (rec->summary);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_DESCRIPTION:
+               *out_str = (rec->description);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LOCATION:
+               *out_str = (rec->location);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA1:
+               *out_str = (rec->sync_data1);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_ORGANIZER_NAME:
+               *out_str = (rec->organizer_name);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_CATEGORIES:
+               *out_str = (rec->categories);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA2:
+               *out_str = (rec->sync_data2);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA3:
+               *out_str = (rec->sync_data3);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA4:
+               *out_str = (rec->sync_data4);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_extended_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       cal_instance_allday_extended_s *rec = (cal_instance_allday_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_EVENT_ID:
+               *out_value = (rec->event_id);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_CALENDAR_ID:
+               *out_value = (rec->calendar_id);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_BUSY_STATUS:
+               *out_value = (rec->busy_status);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_EVENT_STATUS:
+               *out_value = (rec->event_status);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_PRIORITY:
+               *out_value = (rec->priority);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SENSITIVITY:
+               *out_value = (rec->sensitivity);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_RRULE:
+               *out_value = (rec->has_rrule);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_ALARM:
+               *out_value = (rec->has_alarm);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_ORIGINAL_EVENT_ID:
+               *out_value = (rec->original_event_id);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_ATTENDEE:
+               *out_value = (rec->has_attendee);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_IS_ALLDAY:
+               *out_value = (rec->is_allday);
+               break;
+
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_extended_get_double( calendar_record_h record, unsigned int property_id, double* out_value )
+{
+       cal_instance_allday_extended_s *rec = (cal_instance_allday_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LATITUDE:
+               *out_value = (rec->latitude);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LONGITUDE:
+               *out_value = (rec->longitude);
+               break;
+
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_extended_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value )
+{
+       cal_instance_allday_extended_s *rec = (cal_instance_allday_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LAST_MODIFIED_TIME:
+               *out_value = (rec->last_mod);
+               break;
+       default:
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_extended_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value )
+{
+       cal_instance_allday_extended_s *rec = (cal_instance_allday_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_START:
+               *out_value = rec->start;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_END:
+               *out_value = rec->end;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_extended_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       cal_instance_allday_extended_s *rec = (cal_instance_allday_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SUMMARY:
+               CAL_FREE(rec->summary);
+               rec->summary = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_DESCRIPTION:
+               CAL_FREE(rec->description);
+               rec->description = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LOCATION:
+               CAL_FREE(rec->location);
+               rec->location = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA1:
+               CAL_FREE(rec->sync_data1);
+               rec->sync_data1 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_ORGANIZER_NAME:
+               CAL_FREE(rec->organizer_name);
+               rec->organizer_name = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_CATEGORIES:
+               CAL_FREE(rec->categories);
+               rec->categories = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA2:
+               CAL_FREE(rec->sync_data2);
+               rec->sync_data2 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA3:
+               CAL_FREE(rec->sync_data3);
+               rec->sync_data3 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA4:
+               CAL_FREE(rec->sync_data4);
+               rec->sync_data4 = SAFE_STRDUP(value);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_extended_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       cal_instance_allday_extended_s *rec = (cal_instance_allday_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_EVENT_ID:
+               (rec->event_id) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_CALENDAR_ID:
+               (rec->calendar_id) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_BUSY_STATUS:
+               (rec->busy_status) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_EVENT_STATUS:
+               (rec->event_status) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_PRIORITY:
+               (rec->priority) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SENSITIVITY:
+               (rec->sensitivity) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_RRULE:
+               (rec->has_rrule) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_ALARM:
+               (rec->has_alarm) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_ORIGINAL_EVENT_ID:
+               (rec->original_event_id) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_ATTENDEE:
+               (rec->has_attendee) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_extended_set_double( calendar_record_h record, unsigned int property_id, double value )
+{
+       cal_instance_allday_extended_s *rec = (cal_instance_allday_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LATITUDE:
+               (rec->latitude) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LONGITUDE:
+               (rec->longitude) = value;
+               break;
+
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_extended_set_lli( calendar_record_h record, unsigned int property_id, long long int value )
+{
+       cal_instance_allday_extended_s *rec = (cal_instance_allday_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LAST_MODIFIED_TIME:
+               (rec->last_mod) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_allday_extended_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value )
+{
+       cal_instance_allday_extended_s *rec = (cal_instance_allday_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_START:
+               rec->start = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_END:
+               rec->end = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/cal_record_instance_normal.c b/common/cal_record_instance_normal.c
new file mode 100644 (file)
index 0000000..5ef5b3f
--- /dev/null
@@ -0,0 +1,412 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdlib.h>     //calloc
+#include <stdbool.h>        //bool
+#include <string.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+#include "cal_record.h"
+
+static int __cal_record_instance_normal_create( calendar_record_h* out_record );
+static int __cal_record_instance_normal_destroy( calendar_record_h record, bool delete_child );
+static int __cal_record_instance_normal_clone( calendar_record_h record, calendar_record_h* out_record );
+static int __cal_record_instance_normal_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_instance_normal_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_instance_normal_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+static int __cal_record_instance_normal_get_double( calendar_record_h record, unsigned int property_id, double* out_value );
+static int __cal_record_instance_normal_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value );
+static int __cal_record_instance_normal_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value );
+static int __cal_record_instance_normal_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+static int __cal_record_instance_normal_set_int( calendar_record_h record, unsigned int property_id, int value );
+static int __cal_record_instance_normal_set_double( calendar_record_h record, unsigned int property_id, double value );
+static int __cal_record_instance_normal_set_lli( calendar_record_h record, unsigned int property_id, long long int value );
+static int __cal_record_instance_normal_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value );
+
+cal_record_plugin_cb_s _cal_record_instance_normal_plugin_cb = {
+       .create = __cal_record_instance_normal_create,
+       .destroy = __cal_record_instance_normal_destroy,
+       .clone = __cal_record_instance_normal_clone,
+       .get_str = __cal_record_instance_normal_get_str,
+       .get_str_p = __cal_record_instance_normal_get_str_p,
+       .get_int = __cal_record_instance_normal_get_int,
+       .get_double = __cal_record_instance_normal_get_double,
+       .get_lli = __cal_record_instance_normal_get_lli,
+       .get_caltime = __cal_record_instance_normal_get_caltime,
+       .set_str = __cal_record_instance_normal_set_str,
+       .set_int = __cal_record_instance_normal_set_int,
+       .set_double = __cal_record_instance_normal_set_double,
+       .set_lli = __cal_record_instance_normal_set_lli,
+       .set_caltime = __cal_record_instance_normal_set_caltime,
+       .add_child_record = NULL,
+       .remove_child_record = NULL,
+       .get_child_record_count = NULL,
+       .get_child_record_at_p = NULL,
+       .clone_child_record_list = NULL
+};
+
+static void __cal_record_instance_normal_struct_init(cal_instance_normal_s* record)
+{
+       memset(record,0,sizeof(cal_instance_normal_s));
+
+       record->event_status = CALENDAR_EVENT_STATUS_NONE;
+       record->calendar_id = DEFAULT_EVENT_CALENDAR_BOOK_ID;
+       record->event_id = CAL_INVALID_ID;
+
+       record->busy_status = 2;
+       record->summary = NULL;
+       record->description = NULL;
+       record->location= NULL;
+
+       record->latitude = 1000; // set default 1000 out of range(-180 ~ 180)
+       record->longitude = 1000; // set default 1000 out of range(-180 ~ 180)
+
+       return ;
+}
+
+static int __cal_record_instance_normal_create( calendar_record_h* out_record )
+{
+       cal_instance_normal_s *temp = NULL;
+       int ret= CALENDAR_ERROR_NONE;
+
+       temp = (cal_instance_normal_s*)calloc(1,sizeof(cal_instance_normal_s));
+       retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_instance_normal_s:sch) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       __cal_record_instance_normal_struct_init(temp);
+
+       *out_record = (calendar_record_h)temp;
+
+       return ret;
+}
+
+static void __cal_record_instance_normal_struct_free(cal_instance_normal_s *record)
+{
+       CAL_FREE(record->summary);
+       CAL_FREE(record->description);
+       CAL_FREE(record->location);
+       CAL_FREE(record->sync_data1);
+
+       CAL_FREE(record);
+}
+
+static int __cal_record_instance_normal_destroy( calendar_record_h record, bool delete_child )
+{
+       cal_instance_normal_s *temp = (cal_instance_normal_s*)(record);
+
+       __cal_record_instance_normal_struct_free(temp);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       cal_instance_normal_s *out_data = NULL;
+       cal_instance_normal_s *src_data = NULL;
+
+       src_data = (cal_instance_normal_s*)(record);
+
+       out_data = calloc(1, sizeof(cal_instance_normal_s));
+       retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_instance_normal_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
+
+       out_data->event_id = src_data->event_id;
+       out_data->calendar_id = src_data->calendar_id;
+       out_data->start = src_data->start;
+       out_data->end = src_data->end;
+       out_data->summary = SAFE_STRDUP(src_data->summary);
+       out_data->description = SAFE_STRDUP(src_data->description);
+       out_data->location = SAFE_STRDUP(src_data->location);
+       out_data->busy_status = src_data->busy_status;
+       out_data->event_status = src_data->event_status;
+       out_data->priority = src_data->priority;
+       out_data->sensitivity = src_data->sensitivity;
+       out_data->has_rrule = src_data->has_rrule;
+       out_data->latitude = src_data->latitude;
+       out_data->longitude = src_data->longitude;
+       out_data->has_alarm = src_data->has_alarm;
+       out_data->original_event_id = src_data->original_event_id;
+       out_data->last_mod = src_data->last_mod;
+       out_data->sync_data1 = SAFE_STRDUP(src_data->sync_data1);
+
+       *out_record = (calendar_record_h)out_data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_instance_normal_s *rec = (cal_instance_normal_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_SUMMARY:
+               *out_str = SAFE_STRDUP(rec->summary);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_DESCRIPTION:
+               *out_str = SAFE_STRDUP(rec->description);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_LOCATION:
+               *out_str = SAFE_STRDUP(rec->location);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_SYNC_DATA1:
+               *out_str = SAFE_STRDUP(rec->sync_data1);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_instance_normal_s *rec = (cal_instance_normal_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_INSTANCE_NORMAL_SUMMARY:
+               *out_str = (rec->summary);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_DESCRIPTION:
+               *out_str = (rec->description);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_LOCATION:
+               *out_str = (rec->location);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_SYNC_DATA1:
+               *out_str = (rec->sync_data1);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       cal_instance_normal_s *rec = (cal_instance_normal_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EVENT_ID:
+               *out_value = (rec->event_id);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_CALENDAR_ID:
+               *out_value = (rec->calendar_id);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_BUSY_STATUS:
+               *out_value = (rec->busy_status);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EVENT_STATUS:
+               *out_value = (rec->event_status);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_PRIORITY:
+               *out_value = (rec->priority);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_SENSITIVITY:
+               *out_value = (rec->sensitivity);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_HAS_RRULE:
+               *out_value = (rec->has_rrule);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_HAS_ALARM:
+               *out_value = (rec->has_alarm);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_ORIGINAL_EVENT_ID:
+               *out_value = (rec->original_event_id);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_get_double( calendar_record_h record, unsigned int property_id, double* out_value )
+{
+       cal_instance_normal_s *rec = (cal_instance_normal_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_LATITUDE:
+               *out_value = (rec->latitude);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_LONGITUDE:
+               *out_value = (rec->longitude);
+               break;
+
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value )
+{
+       cal_instance_normal_s *rec = (cal_instance_normal_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_INSTANCE_NORMAL_LAST_MODIFIED_TIME:
+               *out_value = (rec->last_mod);
+               break;
+       default:
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value )
+{
+       cal_instance_normal_s *rec = (cal_instance_normal_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_START:
+               *out_value = rec->start;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_END:
+               *out_value = rec->end;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       cal_instance_normal_s *rec = (cal_instance_normal_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_SUMMARY:
+               CAL_FREE(rec->summary);
+               rec->summary = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_DESCRIPTION:
+               CAL_FREE(rec->description);
+               rec->description = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_LOCATION:
+               CAL_FREE(rec->location);
+               rec->location = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_SYNC_DATA1:
+               CAL_FREE(rec->sync_data1);
+               rec->sync_data1 = SAFE_STRDUP(value);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       cal_instance_normal_s *rec = (cal_instance_normal_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EVENT_ID:
+               (rec->event_id) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_CALENDAR_ID:
+               (rec->calendar_id) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_BUSY_STATUS:
+               (rec->busy_status) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EVENT_STATUS:
+               (rec->event_status) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_PRIORITY:
+               (rec->priority) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_SENSITIVITY:
+               (rec->sensitivity) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_HAS_RRULE:
+               (rec->has_rrule) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_HAS_ALARM:
+               (rec->has_alarm) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_ORIGINAL_EVENT_ID:
+               (rec->original_event_id) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_set_double( calendar_record_h record, unsigned int property_id, double value )
+{
+       cal_instance_normal_s *rec = (cal_instance_normal_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_LATITUDE:
+               (rec->latitude) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_LONGITUDE:
+               (rec->longitude) = value;
+               break;
+
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_set_lli( calendar_record_h record, unsigned int property_id, long long int value )
+{
+       cal_instance_normal_s *rec = (cal_instance_normal_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_LAST_MODIFIED_TIME:
+               (rec->last_mod) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value )
+{
+       cal_instance_normal_s *rec = (cal_instance_normal_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_START:
+               rec->start = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_END:
+               rec->end = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/cal_record_instance_normal_extended.c b/common/cal_record_instance_normal_extended.c
new file mode 100644 (file)
index 0000000..e7d5c1a
--- /dev/null
@@ -0,0 +1,476 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdlib.h>     //calloc
+#include <stdbool.h>        //bool
+#include <string.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+#include "cal_record.h"
+
+static int __cal_record_instance_normal_extended_create( calendar_record_h* out_record );
+static int __cal_record_instance_normal_extended_destroy( calendar_record_h record, bool delete_child );
+static int __cal_record_instance_normal_extended_clone( calendar_record_h record, calendar_record_h* out_record );
+static int __cal_record_instance_normal_extended_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_instance_normal_extended_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_instance_normal_extended_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+static int __cal_record_instance_normal_extended_get_double( calendar_record_h record, unsigned int property_id, double* out_value );
+static int __cal_record_instance_normal_extended_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value );
+static int __cal_record_instance_normal_extended_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value );
+static int __cal_record_instance_normal_extended_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+static int __cal_record_instance_normal_extended_set_int( calendar_record_h record, unsigned int property_id, int value );
+static int __cal_record_instance_normal_extended_set_double( calendar_record_h record, unsigned int property_id, double value );
+static int __cal_record_instance_normal_extended_set_lli( calendar_record_h record, unsigned int property_id, long long int value );
+static int __cal_record_instance_normal_extended_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value );
+
+cal_record_plugin_cb_s _cal_record_instance_normal_extended_plugin_cb = {
+       .create = __cal_record_instance_normal_extended_create,
+       .destroy = __cal_record_instance_normal_extended_destroy,
+       .clone = __cal_record_instance_normal_extended_clone,
+       .get_str = __cal_record_instance_normal_extended_get_str,
+       .get_str_p = __cal_record_instance_normal_extended_get_str_p,
+       .get_int = __cal_record_instance_normal_extended_get_int,
+       .get_double = __cal_record_instance_normal_extended_get_double,
+       .get_lli = __cal_record_instance_normal_extended_get_lli,
+       .get_caltime = __cal_record_instance_normal_extended_get_caltime,
+       .set_str = __cal_record_instance_normal_extended_set_str,
+       .set_int = __cal_record_instance_normal_extended_set_int,
+       .set_double = __cal_record_instance_normal_extended_set_double,
+       .set_lli = __cal_record_instance_normal_extended_set_lli,
+       .set_caltime = __cal_record_instance_normal_extended_set_caltime,
+       .add_child_record = NULL,
+       .remove_child_record = NULL,
+       .get_child_record_count = NULL,
+       .get_child_record_at_p = NULL,
+       .clone_child_record_list = NULL
+};
+
+static void __cal_record_instance_normal_extended_struct_init(cal_instance_normal_extended_s* record)
+{
+       memset(record,0,sizeof(cal_instance_normal_extended_s));
+
+       record->event_status = CALENDAR_EVENT_STATUS_NONE;
+       record->calendar_id = DEFAULT_EVENT_CALENDAR_BOOK_ID;
+       record->event_id = CAL_INVALID_ID;
+
+       record->busy_status = 2;
+       record->summary = NULL;
+       record->description = NULL;
+       record->location= NULL;
+
+       record->latitude = 1000; // set default 1000 out of range(-180 ~ 180)
+       record->longitude = 1000; // set default 1000 out of range(-180 ~ 180)
+
+       return ;
+}
+
+static int __cal_record_instance_normal_extended_create( calendar_record_h* out_record )
+{
+       cal_instance_normal_extended_s *temp = NULL;
+       int ret= CALENDAR_ERROR_NONE;
+
+       temp = (cal_instance_normal_extended_s*)calloc(1,sizeof(cal_instance_normal_extended_s));
+       retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_instance_normal_extended_s:sch) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       __cal_record_instance_normal_extended_struct_init(temp);
+
+       *out_record = (calendar_record_h)temp;
+
+       return ret;
+}
+
+static void __cal_record_instance_normal_extended_struct_free(cal_instance_normal_extended_s *record)
+{
+       CAL_FREE(record->summary);
+       CAL_FREE(record->description);
+       CAL_FREE(record->location);
+       CAL_FREE(record->organizer_name);
+       CAL_FREE(record->categories);
+       CAL_FREE(record->sync_data1);
+       CAL_FREE(record->sync_data2);
+       CAL_FREE(record->sync_data3);
+       CAL_FREE(record->sync_data4);
+
+       CAL_FREE(record);
+}
+
+static int __cal_record_instance_normal_extended_destroy( calendar_record_h record, bool delete_child )
+{
+       cal_instance_normal_extended_s *temp = (cal_instance_normal_extended_s*)(record);
+
+       __cal_record_instance_normal_extended_struct_free(temp);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_extended_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       cal_instance_normal_extended_s *out_data = NULL;
+       cal_instance_normal_extended_s *src_data = NULL;
+
+       src_data = (cal_instance_normal_extended_s*)(record);
+
+       out_data = calloc(1, sizeof(cal_instance_normal_extended_s));
+       retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_instance_normal_extended_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
+
+       out_data->event_id = src_data->event_id;
+       out_data->calendar_id = src_data->calendar_id;
+       out_data->start = src_data->start;
+       out_data->end = src_data->end;
+       out_data->summary = SAFE_STRDUP(src_data->summary);
+       out_data->description = SAFE_STRDUP(src_data->description);
+       out_data->location = SAFE_STRDUP(src_data->location);
+       out_data->busy_status = src_data->busy_status;
+       out_data->event_status = src_data->event_status;
+       out_data->priority = src_data->priority;
+       out_data->sensitivity = src_data->sensitivity;
+       out_data->has_rrule = src_data->has_rrule;
+       out_data->latitude = src_data->latitude;
+       out_data->longitude = src_data->longitude;
+       out_data->has_alarm = src_data->has_alarm;
+       out_data->original_event_id = src_data->original_event_id;
+       out_data->last_mod = src_data->last_mod;
+       out_data->organizer_name = SAFE_STRDUP(src_data->organizer_name);
+       out_data->categories = SAFE_STRDUP(src_data->categories);
+       out_data->sync_data1 = SAFE_STRDUP(src_data->sync_data1);
+       out_data->sync_data2 = SAFE_STRDUP(src_data->sync_data2);
+       out_data->sync_data3 = SAFE_STRDUP(src_data->sync_data3);
+       out_data->sync_data4 = SAFE_STRDUP(src_data->sync_data4);
+
+       *out_record = (calendar_record_h)out_data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_extended_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_instance_normal_extended_s *rec = (cal_instance_normal_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SUMMARY:
+               *out_str = SAFE_STRDUP(rec->summary);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_DESCRIPTION:
+               *out_str = SAFE_STRDUP(rec->description);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LOCATION:
+               *out_str = SAFE_STRDUP(rec->location);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA1:
+               *out_str = SAFE_STRDUP(rec->sync_data1);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_ORGANIZER_NAME:
+               *out_str = SAFE_STRDUP(rec->organizer_name);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_CATEGORIES:
+               *out_str = SAFE_STRDUP(rec->categories);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA2:
+               *out_str = SAFE_STRDUP(rec->sync_data2);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA3:
+               *out_str = SAFE_STRDUP(rec->sync_data3);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA4:
+               *out_str = SAFE_STRDUP(rec->sync_data4);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_extended_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_instance_normal_extended_s *rec = (cal_instance_normal_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SUMMARY:
+               *out_str = (rec->summary);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_DESCRIPTION:
+               *out_str = (rec->description);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LOCATION:
+               *out_str = (rec->location);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA1:
+               *out_str = (rec->sync_data1);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_ORGANIZER_NAME:
+               *out_str = (rec->organizer_name);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_CATEGORIES:
+               *out_str = (rec->categories);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA2:
+               *out_str = (rec->sync_data2);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA3:
+               *out_str = (rec->sync_data3);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA4:
+               *out_str = (rec->sync_data4);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_extended_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       cal_instance_normal_extended_s *rec = (cal_instance_normal_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_EVENT_ID:
+               *out_value = (rec->event_id);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_CALENDAR_ID:
+               *out_value = (rec->calendar_id);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_BUSY_STATUS:
+               *out_value = (rec->busy_status);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_EVENT_STATUS:
+               *out_value = (rec->event_status);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_PRIORITY:
+               *out_value = (rec->priority);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SENSITIVITY:
+               *out_value = (rec->sensitivity);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_RRULE:
+               *out_value = (rec->has_rrule);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_ALARM:
+               *out_value = (rec->has_alarm);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_ORIGINAL_EVENT_ID:
+               *out_value = (rec->original_event_id);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_ATTENDEE:
+               *out_value = (rec->has_attendee);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_extended_get_double( calendar_record_h record, unsigned int property_id, double* out_value )
+{
+       cal_instance_normal_extended_s *rec = (cal_instance_normal_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LATITUDE:
+               *out_value = (rec->latitude);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LONGITUDE:
+               *out_value = (rec->longitude);
+               break;
+
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_extended_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value )
+{
+       cal_instance_normal_extended_s *rec = (cal_instance_normal_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LAST_MODIFIED_TIME:
+               *out_value = (rec->last_mod);
+               break;
+       default:
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_extended_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value )
+{
+       cal_instance_normal_extended_s *rec = (cal_instance_normal_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_START:
+               *out_value = rec->start;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_END:
+               *out_value = rec->end;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_extended_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       cal_instance_normal_extended_s *rec = (cal_instance_normal_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SUMMARY:
+               CAL_FREE(rec->summary);
+               rec->summary = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_DESCRIPTION:
+               CAL_FREE(rec->description);
+               rec->description = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LOCATION:
+               CAL_FREE(rec->location);
+               rec->location = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA1:
+               CAL_FREE(rec->sync_data1);
+               rec->sync_data1 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_ORGANIZER_NAME:
+               CAL_FREE(rec->organizer_name);
+               rec->organizer_name = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_CATEGORIES:
+               CAL_FREE(rec->categories);
+               rec->categories = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA2:
+               CAL_FREE(rec->sync_data2);
+               rec->sync_data2 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA3:
+               CAL_FREE(rec->sync_data3);
+               rec->sync_data3 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA4:
+               CAL_FREE(rec->sync_data4);
+               rec->sync_data4 = SAFE_STRDUP(value);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_extended_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       cal_instance_normal_extended_s *rec = (cal_instance_normal_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_EVENT_ID:
+               (rec->event_id) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_CALENDAR_ID:
+               (rec->calendar_id) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_BUSY_STATUS:
+               (rec->busy_status) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_EVENT_STATUS:
+               (rec->event_status) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_PRIORITY:
+               (rec->priority) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SENSITIVITY:
+               (rec->sensitivity) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_RRULE:
+               (rec->has_rrule) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_ALARM:
+               (rec->has_alarm) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_ORIGINAL_EVENT_ID:
+               (rec->original_event_id) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_ATTENDEE:
+               (rec->has_attendee) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_extended_set_double( calendar_record_h record, unsigned int property_id, double value )
+{
+       cal_instance_normal_extended_s *rec = (cal_instance_normal_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LATITUDE:
+               (rec->latitude) = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LONGITUDE:
+               (rec->longitude) = value;
+               break;
+
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_extended_set_lli( calendar_record_h record, unsigned int property_id, long long int value )
+{
+       cal_instance_normal_extended_s *rec = (cal_instance_normal_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LAST_MODIFIED_TIME:
+               (rec->last_mod) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_instance_normal_extended_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value )
+{
+       cal_instance_normal_extended_s *rec = (cal_instance_normal_extended_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_START:
+               rec->start = value;
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_END:
+               rec->end = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/cal_record_search.c b/common/cal_record_search.c
new file mode 100644 (file)
index 0000000..19b59d5
--- /dev/null
@@ -0,0 +1,482 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>     //calloc
+#include <stdbool.h>        //bool
+#include <string.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+#include "cal_record.h"
+
+static int __cal_record_search_create( calendar_record_h* out_record );
+static int __cal_record_search_destroy( calendar_record_h record, bool delete_child );
+static int __cal_record_search_clone( calendar_record_h record, calendar_record_h* out_record );
+static int __cal_record_search_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_search_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_search_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+static int __cal_record_search_get_double( calendar_record_h record, unsigned int property_id, double* out_value );
+static int __cal_record_search_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value );
+static int __cal_record_search_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value );
+static int __cal_record_search_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+static int __cal_record_search_set_int( calendar_record_h record, unsigned int property_id, int value );
+static int __cal_record_search_set_double( calendar_record_h record, unsigned int property_id, double value );
+static int __cal_record_search_set_lli( calendar_record_h record, unsigned int property_id, long long int value );
+static int __cal_record_search_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value );
+
+cal_record_plugin_cb_s _cal_record_search_plugin_cb = {
+       .create = __cal_record_search_create,
+       .destroy = __cal_record_search_destroy,
+       .clone = __cal_record_search_clone,
+       .get_str = __cal_record_search_get_str,
+       .get_str_p = __cal_record_search_get_str_p,
+       .get_int = __cal_record_search_get_int,
+       .get_double = __cal_record_search_get_double,
+       .get_lli = __cal_record_search_get_lli,
+       .get_caltime = __cal_record_search_get_caltime,
+       .set_str = __cal_record_search_set_str,
+       .set_int = __cal_record_search_set_int,
+       .set_double = __cal_record_search_set_double,
+       .set_lli = __cal_record_search_set_lli,
+       .set_caltime = __cal_record_search_set_caltime,
+       .add_child_record = NULL,
+       .remove_child_record = NULL,
+       .get_child_record_count = NULL,
+       .get_child_record_at_p = NULL,
+       .clone_child_record_list = NULL
+};
+
+static int __cal_record_search_create( calendar_record_h* out_record )
+{
+       cal_search_s *temp = NULL;
+       int ret= CALENDAR_ERROR_NONE;
+
+       temp = (cal_search_s*)calloc(1, sizeof(cal_search_s));
+       retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_search_s:sch) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       *out_record = (calendar_record_h)temp;
+
+       return ret;
+}
+
+static int __cal_record_search_destroy( calendar_record_h record, bool delete_child )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       GSList *cursor;
+
+       cal_search_s *temp = (cal_search_s*)(record);
+
+       for(cursor = temp->values;cursor;cursor=cursor->next)
+       {
+               cal_search_value_s *data = cursor->data;
+               if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_STR) == true)
+               {
+                       CAL_FREE(data->value.s);
+               }
+               CAL_FREE(data);
+       }
+
+       g_slist_free(temp->values);
+       CAL_FREE(temp);
+
+       return ret;
+}
+
+static int __cal_record_search_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       cal_search_s *out_data = NULL;
+       cal_search_s *src_data = NULL;
+       GSList *cursor;
+
+       src_data = (cal_search_s*)(record);
+
+       out_data = calloc(1, sizeof(cal_search_s));
+       retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_search_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
+
+       for(cursor = src_data->values;cursor;cursor=cursor->next)
+       {
+               cal_search_value_s *src = cursor->data;
+               cal_search_value_s *dest = calloc(1, sizeof(cal_search_value_s));
+               if (dest == NULL)
+               {
+                       CAL_FREE(out_data);
+                       return CALENDAR_ERROR_OUT_OF_MEMORY;
+               }
+               dest->property_id = src->property_id;
+               if (CAL_PROPERTY_CHECK_DATA_TYPE(src->property_id, CAL_PROPERTY_DATA_TYPE_STR) == true)
+               {
+                       dest->value.s = SAFE_STRDUP(src->value.s);
+               }
+               else if (CAL_PROPERTY_CHECK_DATA_TYPE(src->property_id, CAL_PROPERTY_DATA_TYPE_INT) == true)
+               {
+                       dest->value.i = src->value.i;
+               }
+               else if (CAL_PROPERTY_CHECK_DATA_TYPE(src->property_id, CAL_PROPERTY_DATA_TYPE_DOUBLE) == true)
+               {
+                       dest->value.d = src->value.d;
+               }
+               else if (CAL_PROPERTY_CHECK_DATA_TYPE(src->property_id, CAL_PROPERTY_DATA_TYPE_LLI) == true)
+               {
+                       dest->value.lli = src->value.lli;
+               }
+               else if (CAL_PROPERTY_CHECK_DATA_TYPE(src->property_id, CAL_PROPERTY_DATA_TYPE_CALTIME) == true)
+               {
+                       dest->value.caltime = src->value.caltime;
+               }
+               else
+               {
+//                     ERR("invalid parameter (property:%d)",src->property_id);
+                       CAL_FREE(dest);
+                       continue;
+               }
+
+               out_data->values = g_slist_append(out_data->values, dest);
+       }
+
+       *out_record = (calendar_record_h)out_data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_search_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_search_s *rec = (cal_search_s*)(record);
+       GSList *cursor;
+
+       for(cursor = rec->values;cursor;cursor=cursor->next)
+       {
+               cal_search_value_s *data = cursor->data;
+               if (data->property_id == property_id)
+               {
+                       if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_STR) == true)
+                       {
+                               *out_str = SAFE_STRDUP(data->value.s);
+                               break;
+                       }
+                       else
+                       {
+                               ERR("invalid parameter (property:%d)",data->property_id);
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_search_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_search_s *rec = (cal_search_s*)(record);
+       GSList *cursor;
+
+       for(cursor = rec->values;cursor;cursor=cursor->next)
+       {
+               cal_search_value_s *data = cursor->data;
+               if (data->property_id == property_id)
+               {
+                       if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_STR) == true)
+                       {
+                               *out_str = (data->value.s);
+                               break;
+                       }
+                       else
+                       {
+                               ERR("invalid parameter (property:%d)",data->property_id);
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_search_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       cal_search_s *rec = (cal_search_s*)(record);
+       GSList *cursor;
+
+       for(cursor = rec->values;cursor;cursor=cursor->next)
+       {
+               cal_search_value_s *data = cursor->data;
+               if (data->property_id == property_id)
+               {
+                       if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_INT) == true)
+                       {
+                               *out_value = (data->value.i);
+                               break;
+                       }
+                       else
+                       {
+                               ERR("invalid parameter (property:%d)",data->property_id);
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_search_get_double( calendar_record_h record, unsigned int property_id, double* out_value )
+{
+       cal_search_s *rec = (cal_search_s*)(record);
+       GSList *cursor;
+
+       for(cursor = rec->values;cursor;cursor=cursor->next)
+       {
+               cal_search_value_s *data = cursor->data;
+               if (data->property_id == property_id)
+               {
+                       if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_DOUBLE) == true)
+                       {
+                               *out_value = (data->value.d);
+                               break;
+                       }
+                       else
+                       {
+                               ERR("invalid parameter (property:%d)",data->property_id);
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_search_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value )
+{
+       cal_search_s *rec = (cal_search_s*)(record);
+       GSList *cursor;
+
+       for(cursor = rec->values;cursor;cursor=cursor->next)
+       {
+               cal_search_value_s *data = cursor->data;
+               if (data->property_id == property_id)
+               {
+                       if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_LLI) == true)
+                       {
+                               *out_value = (data->value.lli);
+                               break;
+                       }
+                       else
+                       {
+                               ERR("invalid parameter (property:%d)",data->property_id);
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_search_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value )
+{
+       cal_search_s *rec = (cal_search_s*)(record);
+       GSList *cursor;
+
+       for(cursor = rec->values;cursor;cursor=cursor->next)
+       {
+               cal_search_value_s *data = cursor->data;
+               if (data->property_id == property_id)
+               {
+                       if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_CALTIME) == true)
+                       {
+                               *out_value = (data->value.caltime);
+                               break;
+                       }
+                       else
+                       {
+                               ERR("invalid parameter (property:%d)",data->property_id);
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_search_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       cal_search_s *rec = (cal_search_s*)(record);
+       GSList *cursor;
+       cal_search_value_s *data = NULL;
+
+       for(cursor = rec->values;cursor;cursor=cursor->next)
+       {
+               data = cursor->data;
+               if (data->property_id == property_id)
+               {
+                       if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_STR) == true)
+                       {
+                               CAL_FREE(data->value.s);
+                               (data->value.s) = SAFE_STRDUP(value);
+                               return CALENDAR_ERROR_NONE;
+                       }
+                       else
+                       {
+                               ERR("invalid parameter (property:%d)",data->property_id);
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+               }
+       }
+
+       data = calloc(1, sizeof(cal_search_value_s));
+       retvm_if(NULL == data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_search_s) Failed");
+       data->property_id = property_id;
+       data->value.s = SAFE_STRDUP(value);
+       rec->values = g_slist_append(rec->values, data);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_search_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       cal_search_s *rec = (cal_search_s*)(record);
+       GSList *cursor;
+       cal_search_value_s *data = NULL;
+
+       for(cursor = rec->values;cursor;cursor=cursor->next)
+       {
+               data = cursor->data;
+               if (data->property_id == property_id)
+               {
+                       if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_INT) == true)
+                       {
+                               (data->value.i) = value;
+                               return CALENDAR_ERROR_NONE;
+                       }
+                       else
+                       {
+                               ERR("invalid parameter (property:%d)",data->property_id);
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+               }
+       }
+
+       data = calloc(1, sizeof(cal_search_value_s));
+       retvm_if(NULL == data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_search_s) Failed");
+       data->property_id = property_id;
+       (data->value.i) = value;
+       rec->values = g_slist_append(rec->values, data);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_search_set_double( calendar_record_h record, unsigned int property_id, double value )
+{
+       cal_search_s *rec = (cal_search_s*)(record);
+       GSList *cursor;
+       cal_search_value_s *data = NULL;
+
+       for(cursor = rec->values;cursor;cursor=cursor->next)
+       {
+               data = cursor->data;
+               if (data->property_id == property_id)
+               {
+                       if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_DOUBLE) == true)
+                       {
+                               (data->value.d) = value;
+                               return CALENDAR_ERROR_NONE;
+                       }
+                       else
+                       {
+                               ERR("invalid parameter (property:%d)",data->property_id);
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+               }
+       }
+
+       data = calloc(1, sizeof(cal_search_value_s));
+       retvm_if(NULL == data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_search_s) Failed");
+       data->property_id = property_id;
+       (data->value.d) = value;
+       rec->values = g_slist_append(rec->values, data);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_search_set_lli( calendar_record_h record, unsigned int property_id, long long int value )
+{
+       cal_search_s *rec = (cal_search_s*)(record);
+       GSList *cursor;
+       cal_search_value_s *data = NULL;
+
+       for(cursor = rec->values;cursor;cursor=cursor->next)
+       {
+               data = cursor->data;
+               if (data->property_id == property_id)
+               {
+                       if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_LLI) == true)
+                       {
+                               (data->value.lli) = value;
+                               return CALENDAR_ERROR_NONE;
+                       }
+                       else
+                       {
+                               ERR("invalid parameter (property:%d)",data->property_id);
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+               }
+       }
+
+       data = calloc(1, sizeof(cal_search_value_s));
+       retvm_if(NULL == data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_search_s) Failed");
+       data->property_id = property_id;
+       (data->value.lli) = value;
+       rec->values = g_slist_append(rec->values, data);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_search_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value )
+{
+       cal_search_s *rec = (cal_search_s*)(record);
+       GSList *cursor;
+       cal_search_value_s *data = NULL;
+
+       for(cursor = rec->values;cursor;cursor=cursor->next)
+       {
+               data = cursor->data;
+               if (data->property_id == property_id)
+               {
+                       if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_CALTIME) == true)
+                       {
+                               (data->value.caltime) = value;
+                               return CALENDAR_ERROR_NONE;
+                       }
+                       else
+                       {
+                               ERR("invalid parameter (property:%d)",data->property_id);
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+               }
+       }
+
+       data = calloc(1, sizeof(cal_search_value_s));
+       retvm_if(NULL == data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_search_s) Failed");
+       data->property_id = property_id;
+       (data->value.caltime) = value;
+       rec->values = g_slist_append(rec->values, data);
+
+       return CALENDAR_ERROR_NONE;
+}
+
diff --git a/common/cal_record_timezone.c b/common/cal_record_timezone.c
new file mode 100644 (file)
index 0000000..92edea3
--- /dev/null
@@ -0,0 +1,294 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+#include "cal_record.h"
+
+static int __cal_record_timezone_create( calendar_record_h* out_record );
+static int __cal_record_timezone_destroy( calendar_record_h record, bool delete_child );
+static int __cal_record_timezone_clone( calendar_record_h record, calendar_record_h* out_record );
+static int __cal_record_timezone_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_timezone_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_timezone_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+static int __cal_record_timezone_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+static int __cal_record_timezone_set_int( calendar_record_h record, unsigned int property_id, int value );
+
+cal_record_plugin_cb_s _cal_record_timezone_plugin_cb = {
+       .create = __cal_record_timezone_create,
+       .destroy = __cal_record_timezone_destroy,
+       .clone = __cal_record_timezone_clone,
+       .get_str = __cal_record_timezone_get_str,
+       .get_str_p = __cal_record_timezone_get_str_p,
+       .get_int = __cal_record_timezone_get_int,
+       .get_double = NULL,
+       .get_lli = NULL,
+       .get_caltime = NULL,
+       .set_str = __cal_record_timezone_set_str,
+       .set_int = __cal_record_timezone_set_int,
+       .set_double = NULL,
+       .set_lli = NULL,
+       .set_caltime = NULL,
+       .add_child_record = NULL,
+       .remove_child_record = NULL,
+       .get_child_record_count = NULL,
+       .get_child_record_at_p = NULL,
+       .clone_child_record_list = NULL
+};
+
+static void __cal_record_timezone_struct_init(cal_timezone_s *record)
+{
+       memset(record,0,sizeof(cal_timezone_s));
+       record->calendar_id = DEFAULT_EVENT_CALENDAR_BOOK_ID;
+}
+
+static int __cal_record_timezone_create( calendar_record_h* out_record )
+{
+       cal_timezone_s *temp = NULL;
+       int ret= CALENDAR_ERROR_NONE;
+
+       temp = (cal_timezone_s*)calloc(1,sizeof(cal_timezone_s));
+       retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_timezone_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       __cal_record_timezone_struct_init(temp);
+
+       *out_record = (calendar_record_h)temp;
+
+       return ret;
+}
+
+static void __cal_record_timezone_struct_free(cal_timezone_s *record)
+{
+       CAL_FREE(record->standard_name);
+       CAL_FREE(record->day_light_name);
+       CAL_FREE(record);
+
+}
+
+static int __cal_record_timezone_destroy( calendar_record_h record, bool delete_child )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_timezone_s *temp = (cal_timezone_s*)(record);
+
+       __cal_record_timezone_struct_free(temp);
+
+       return ret;
+}
+
+static int __cal_record_timezone_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       cal_timezone_s *out_data = NULL;
+       cal_timezone_s *src_data = NULL;
+
+       src_data = (cal_timezone_s*)(record);
+
+       out_data = calloc(1, sizeof(cal_timezone_s));
+       retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_timezone_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
+
+       out_data->index = src_data->index;
+       out_data->tz_offset_from_gmt = src_data->tz_offset_from_gmt;
+       out_data->standard_name = SAFE_STRDUP(src_data->standard_name);
+       out_data->std_start_month = src_data->std_start_month;
+       out_data->std_start_position_of_week = src_data->std_start_position_of_week;
+       out_data->std_start_day = src_data->std_start_day;
+       out_data->std_start_hour = src_data->std_start_hour;
+       out_data->standard_bias = src_data->standard_bias;
+       out_data->day_light_name = SAFE_STRDUP(src_data->day_light_name);
+       out_data->day_light_start_month = src_data->day_light_start_month;
+       out_data->day_light_start_position_of_week = src_data->day_light_start_position_of_week;
+       out_data->day_light_start_day = src_data->day_light_start_day;
+       out_data->day_light_start_hour = src_data->day_light_start_hour;
+       out_data->day_light_bias = src_data->day_light_bias;
+       out_data->calendar_id = src_data->calendar_id;
+
+       *out_record = (calendar_record_h)out_data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_timezone_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_timezone_s *rec = (cal_timezone_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_TIMEZONE_STANDARD_NAME:
+               *out_str = SAFE_STRDUP(rec->standard_name);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
+               *out_str = SAFE_STRDUP(rec->day_light_name);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_timezone_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_timezone_s *rec = (cal_timezone_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_TIMEZONE_STANDARD_NAME:
+               *out_str = (rec->standard_name);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
+               *out_str = (rec->day_light_name);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_timezone_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       cal_timezone_s *rec = (cal_timezone_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_TIMEZONE_ID:
+               *out_value = (rec->index);
+               break;
+       case CAL_PROPERTY_TIMEZONE_TZ_OFFSET_FROM_GMT:
+               *out_value = (rec->tz_offset_from_gmt);
+               break;
+       case CAL_PROPERTY_TIMEZONE_STD_START_MONTH:
+               *out_value = (rec->std_start_month);
+               break;
+       case CAL_PROPERTY_TIMEZONE_STD_START_POSITION_OF_WEEK:
+               *out_value = (rec->std_start_position_of_week);
+               break;
+       case CAL_PROPERTY_TIMEZONE_STD_START_DAY:
+               *out_value = (rec->std_start_day);
+               break;
+       case CAL_PROPERTY_TIMEZONE_STD_START_HOUR:
+               *out_value = (rec->std_start_hour);
+               break;
+       case CAL_PROPERTY_TIMEZONE_STANDARD_BIAS:
+               *out_value = (rec->standard_bias);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_MONTH:
+               *out_value = (rec->day_light_start_month);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_POSITION_OF_WEEK:
+               *out_value = (rec->day_light_start_position_of_week);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_DAY:
+               *out_value = (rec->day_light_start_day);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_HOUR:
+               *out_value = (rec->day_light_start_hour);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_BIAS:
+               *out_value = (rec->day_light_bias);
+               break;
+       case CAL_PROPERTY_TIMEZONE_CALENDAR_ID:
+               *out_value = (rec->calendar_id);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_timezone_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       cal_timezone_s *rec = (cal_timezone_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_TIMEZONE_STANDARD_NAME:
+               CAL_FREE(rec->standard_name);
+               rec->standard_name = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
+               CAL_FREE(rec->day_light_name);
+               rec->day_light_name = SAFE_STRDUP(value);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_timezone_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       cal_timezone_s *rec = (cal_timezone_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_TIMEZONE_ID:
+               (rec->index) = value;
+               break;
+       case CAL_PROPERTY_TIMEZONE_TZ_OFFSET_FROM_GMT:
+               (rec->tz_offset_from_gmt) = value;
+               break;
+       case CAL_PROPERTY_TIMEZONE_STD_START_MONTH:
+               (rec->std_start_month) = value;
+               break;
+       case CAL_PROPERTY_TIMEZONE_STD_START_POSITION_OF_WEEK:
+               (rec->std_start_position_of_week) = value;
+               break;
+       case CAL_PROPERTY_TIMEZONE_STD_START_DAY:
+               (rec->std_start_day) = value;
+               break;
+       case CAL_PROPERTY_TIMEZONE_STD_START_HOUR:
+               (rec->std_start_hour) = value;
+               break;
+       case CAL_PROPERTY_TIMEZONE_STANDARD_BIAS:
+               (rec->standard_bias) = value;
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_MONTH:
+               (rec->day_light_start_month) = value;
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_POSITION_OF_WEEK:
+               (rec->day_light_start_position_of_week) = value;
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_DAY:
+               (rec->day_light_start_day) = value;
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_HOUR:
+               (rec->day_light_start_hour) = value;
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_BIAS:
+               (rec->day_light_bias) = value;
+               break;
+       case CAL_PROPERTY_TIMEZONE_CALENDAR_ID:
+               (rec->calendar_id) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/cal_record_todo.c b/common/cal_record_todo.c
new file mode 100644 (file)
index 0000000..205af76
--- /dev/null
@@ -0,0 +1,931 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdlib.h>            //calloc
+#include <stdbool.h>           //bool
+#include <string.h>
+
+#include "calendar_list.h"
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_list.h"
+
+#include "cal_record.h"
+
+static int __cal_record_todo_create( calendar_record_h* out_record );
+static int __cal_record_todo_destroy( calendar_record_h record, bool delete_child );
+static int __cal_record_todo_clone( calendar_record_h record, calendar_record_h* out_record );
+static int __cal_record_todo_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_todo_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
+static int __cal_record_todo_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+static int __cal_record_todo_get_double( calendar_record_h record, unsigned int property_id, double* out_value );
+static int __cal_record_todo_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value );
+static int __cal_record_todo_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value );
+static int __cal_record_todo_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+static int __cal_record_todo_set_int( calendar_record_h record, unsigned int property_id, int value );
+static int __cal_record_todo_set_double( calendar_record_h record, unsigned int property_id, double value );
+static int __cal_record_todo_set_lli( calendar_record_h record, unsigned int property_id, long long int value );
+static int __cal_record_todo_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value );
+static int __cal_record_todo_add_child_record( calendar_record_h record, unsigned int property_id, calendar_record_h child_record );
+static int __cal_record_todo_remove_child_record( calendar_record_h record, unsigned int property_id, calendar_record_h child_record );
+static int __cal_record_todo_get_child_record_count( calendar_record_h record, unsigned int property_id, unsigned int* count  );
+static int __cal_record_todo_get_child_record_at_p( calendar_record_h record, unsigned int property_id, int index, calendar_record_h* child_record );
+static int __cal_record_todo_clone_child_record_list( calendar_record_h record, unsigned int property_id, calendar_list_h* out_list );
+
+cal_record_plugin_cb_s _cal_record_todo_plugin_cb = {
+       .create = __cal_record_todo_create,
+       .destroy = __cal_record_todo_destroy,
+       .clone = __cal_record_todo_clone,
+       .get_str = __cal_record_todo_get_str,
+       .get_str_p = __cal_record_todo_get_str_p,
+       .get_int = __cal_record_todo_get_int,
+       .get_double = __cal_record_todo_get_double,
+       .get_lli = __cal_record_todo_get_lli,
+       .get_caltime = __cal_record_todo_get_caltime,
+       .set_str = __cal_record_todo_set_str,
+       .set_int = __cal_record_todo_set_int,
+       .set_double = __cal_record_todo_set_double,
+       .set_lli = __cal_record_todo_set_lli,
+       .set_caltime = __cal_record_todo_set_caltime,
+       .add_child_record = __cal_record_todo_add_child_record,
+       .remove_child_record = __cal_record_todo_remove_child_record,
+       .get_child_record_count = __cal_record_todo_get_child_record_count,
+       .get_child_record_at_p = __cal_record_todo_get_child_record_at_p,
+       .clone_child_record_list = __cal_record_todo_clone_child_record_list
+};
+
+static void __cal_record_todo_struct_init(cal_todo_s *record)
+{
+       memset(record,0,sizeof(cal_todo_s));
+
+       record->todo_status = CALENDAR_TODO_STATUS_NONE;
+       record->calendar_id = DEFAULT_TODO_CALENDAR_BOOK_ID;
+
+       record->index = CAL_INVALID_ID;
+       record->summary = NULL;
+       record->description = NULL;
+       record->location= NULL;
+       record->categories = NULL;
+       record->uid= NULL;
+       record->is_deleted = 0;
+       record->latitude = CALENDAR_RECORD_NO_COORDINATE; // set default 1000 out of range(-180 ~ 180)
+       record->longitude = CALENDAR_RECORD_NO_COORDINATE; // set default 1000 out of range(-180 ~ 180)
+       record->priority = CALENDAR_TODO_PRIORITY_NONE;
+       record->freq = CALENDAR_RECURRENCE_NONE;
+       record->start.time.utime = CALENDAR_TODO_NO_START_DATE;
+       record->due.time.utime = CALENDAR_TODO_NO_DUE_DATE;
+       record->until.time.utime = CALENDAR_RECORD_NO_UNTIL;
+
+       record->alarm_list = calloc(1, sizeof(cal_list_s));
+       record->attendee_list = calloc(1, sizeof(cal_list_s));
+       record->extended_list = calloc(1, sizeof(cal_list_s));
+
+       return ;
+}
+
+static int __cal_record_todo_create( calendar_record_h* out_record )
+{
+       cal_todo_s *temp = NULL;
+       int ret= CALENDAR_ERROR_NONE;
+
+       temp = (cal_todo_s*)calloc(1,sizeof(cal_todo_s));
+       retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_todo_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       __cal_record_todo_struct_init(temp);
+
+       *out_record = (calendar_record_h)temp;
+
+       return ret;
+}
+
+static void __cal_record_todo_struct_free(cal_todo_s *record, bool delete_child)
+{
+       CAL_FREE(record->summary);
+       CAL_FREE(record->description);
+       CAL_FREE(record->location);
+       CAL_FREE(record->categories);
+       CAL_FREE(record->uid);
+       CAL_FREE(record->start_tzid);
+       CAL_FREE(record->due_tzid);
+
+       CAL_FREE(record->bysecond);
+       CAL_FREE(record->byminute);
+       CAL_FREE(record->byhour);
+       CAL_FREE(record->byday);
+       CAL_FREE(record->bymonthday);
+       CAL_FREE(record->byyearday);
+       CAL_FREE(record->byweekno);
+       CAL_FREE(record->bymonth);
+       CAL_FREE(record->bysetpos);
+
+       CAL_FREE(record->sync_data1);
+       CAL_FREE(record->sync_data2);
+       CAL_FREE(record->sync_data3);
+       CAL_FREE(record->sync_data4);
+
+       CAL_FREE(record->organizer_name);
+       CAL_FREE(record->organizer_email);
+
+       calendar_list_destroy((calendar_list_h)record->alarm_list, delete_child);
+       calendar_list_destroy((calendar_list_h)record->attendee_list, delete_child);
+       calendar_list_destroy((calendar_list_h)record->extended_list, delete_child);
+
+       CAL_FREE(record);
+}
+
+static int __cal_record_todo_destroy( calendar_record_h record, bool delete_child )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_todo_s *temp = (cal_todo_s*)(record);
+
+       __cal_record_todo_struct_free(temp, delete_child);
+
+       return ret;
+}
+
+static int __cal_record_todo_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       cal_todo_s *out_data = NULL;
+       cal_todo_s *src_data = NULL;
+
+       src_data = (cal_todo_s*)(record);
+
+       out_data = calloc(1, sizeof(cal_todo_s));
+       retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_todo_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+
+       CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
+
+       out_data->index = src_data->index;
+       out_data->summary = SAFE_STRDUP(src_data->summary);
+       out_data->description = SAFE_STRDUP(src_data->description);
+       out_data->location = SAFE_STRDUP(src_data->location);
+       out_data->categories = SAFE_STRDUP(src_data->categories);
+
+       out_data->todo_status = src_data->todo_status;
+       out_data->priority = src_data->priority;
+       out_data->sensitivity = src_data->sensitivity;
+
+       out_data->uid = SAFE_STRDUP(src_data->uid);
+
+       out_data->calendar_id = src_data->calendar_id;
+       out_data->latitude = src_data->latitude;
+       out_data->longitude = src_data->longitude;
+
+       out_data->created_time = src_data->created_time;
+       out_data->completed_time = src_data->completed_time;
+       out_data->progress = src_data->progress;
+       out_data->is_deleted = src_data->is_deleted;
+       out_data->last_mod = src_data->last_mod;
+
+       out_data->freq = src_data->freq;
+       out_data->range_type = src_data->range_type;
+       out_data->until = src_data->until;
+       out_data->count = src_data->count;
+       out_data->interval = src_data->interval;
+       out_data->bysecond = SAFE_STRDUP(src_data->bysecond);
+       out_data->byminute = SAFE_STRDUP(src_data->byminute);
+       out_data->byhour = SAFE_STRDUP(src_data->byhour);
+       out_data->byday = SAFE_STRDUP(src_data->byday);
+       out_data->bymonthday = SAFE_STRDUP(src_data->bymonthday);
+       out_data->byyearday = SAFE_STRDUP(src_data->byyearday);
+       out_data->byweekno = SAFE_STRDUP(src_data->byweekno);
+       out_data->bymonth = SAFE_STRDUP(src_data->bymonth);
+       out_data->bysetpos = SAFE_STRDUP(src_data->bysetpos);
+       out_data->wkst = src_data->wkst;
+       out_data->has_alarm = src_data->has_alarm;
+       out_data->updated = src_data->updated;
+
+       out_data->sync_data1 = SAFE_STRDUP(src_data->sync_data1);
+       out_data->sync_data2 = SAFE_STRDUP(src_data->sync_data2);
+       out_data->sync_data3 = SAFE_STRDUP(src_data->sync_data3);
+       out_data->sync_data4 = SAFE_STRDUP(src_data->sync_data4);
+
+       out_data->start = src_data->start;
+       out_data->start_tzid = SAFE_STRDUP(src_data->start_tzid);
+       out_data->due = src_data->due;
+       out_data->due_tzid = SAFE_STRDUP(src_data->due_tzid);
+
+       out_data->organizer_name = SAFE_STRDUP(src_data->organizer_name);
+       out_data->organizer_email = SAFE_STRDUP(src_data->organizer_email);
+       out_data->has_attendee = src_data->has_attendee;
+
+       _cal_list_clone((calendar_list_h)src_data->alarm_list, (calendar_list_h *)&out_data->alarm_list);
+       _cal_list_clone((calendar_list_h)src_data->attendee_list, (calendar_list_h *)&out_data->attendee_list);
+       _cal_list_clone((calendar_list_h)src_data->extended_list, (calendar_list_h *)&out_data->extended_list);
+
+       *out_record = (calendar_record_h)out_data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_todo_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_todo_s *rec = (cal_todo_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_TODO_SUMMARY:
+               *out_str = SAFE_STRDUP(rec->summary);
+               break;
+       case CAL_PROPERTY_TODO_DESCRIPTION:
+               *out_str = SAFE_STRDUP(rec->description);
+               break;
+       case CAL_PROPERTY_TODO_LOCATION:
+               *out_str = SAFE_STRDUP(rec->location);
+               break;
+       case CAL_PROPERTY_TODO_CATEGORIES:
+               *out_str = SAFE_STRDUP(rec->categories);
+               break;
+       case CAL_PROPERTY_TODO_UID:
+               *out_str = SAFE_STRDUP(rec->uid);
+               break;
+       case CAL_PROPERTY_TODO_BYSECOND:
+               *out_str = SAFE_STRDUP(rec->bysecond);
+               break;
+       case CAL_PROPERTY_TODO_BYMINUTE:
+               *out_str = SAFE_STRDUP(rec->byminute);
+               break;
+       case CAL_PROPERTY_TODO_BYHOUR:
+               *out_str = SAFE_STRDUP(rec->byhour);
+               break;
+       case CAL_PROPERTY_TODO_BYDAY:
+               *out_str = SAFE_STRDUP(rec->byday);
+               break;
+       case CAL_PROPERTY_TODO_BYMONTHDAY:
+               *out_str = SAFE_STRDUP(rec->bymonthday);
+               break;
+       case CAL_PROPERTY_TODO_BYYEARDAY:
+               *out_str = SAFE_STRDUP(rec->byyearday);
+               break;
+       case CAL_PROPERTY_TODO_BYWEEKNO:
+               *out_str = SAFE_STRDUP(rec->byweekno);
+               break;
+       case CAL_PROPERTY_TODO_BYMONTH:
+               *out_str = SAFE_STRDUP(rec->bymonth);
+               break;
+       case CAL_PROPERTY_TODO_BYSETPOS:
+               *out_str = SAFE_STRDUP(rec->bysetpos);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA1:
+               *out_str = SAFE_STRDUP(rec->sync_data1);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA2:
+               *out_str = SAFE_STRDUP(rec->sync_data2);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA3:
+               *out_str = SAFE_STRDUP(rec->sync_data3);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA4:
+               *out_str = SAFE_STRDUP(rec->sync_data4);
+               break;
+       case CAL_PROPERTY_TODO_START_TZID:
+               *out_str = SAFE_STRDUP(rec->start_tzid);
+               break;
+       case CAL_PROPERTY_TODO_DUE_TZID:
+               *out_str = SAFE_STRDUP(rec->due_tzid);
+               break;
+       case CAL_PROPERTY_TODO_ORGANIZER_NAME:
+               *out_str = SAFE_STRDUP(rec->organizer_name);
+               break;
+       case CAL_PROPERTY_TODO_ORGANIZER_EMAIL:
+               *out_str = SAFE_STRDUP(rec->organizer_email);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_todo_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str )
+{
+       cal_todo_s *rec = (cal_todo_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_TODO_SUMMARY:
+               *out_str = (rec->summary);
+               break;
+       case CAL_PROPERTY_TODO_DESCRIPTION:
+               *out_str = (rec->description);
+               break;
+       case CAL_PROPERTY_TODO_LOCATION:
+               *out_str = (rec->location);
+               break;
+       case CAL_PROPERTY_TODO_CATEGORIES:
+               *out_str = (rec->categories);
+               break;
+       case CAL_PROPERTY_TODO_UID:
+               *out_str = (rec->uid);
+               break;
+       case CAL_PROPERTY_TODO_BYSECOND:
+               *out_str = (rec->bysecond);
+               break;
+       case CAL_PROPERTY_TODO_BYMINUTE:
+               *out_str = (rec->byminute);
+               break;
+       case CAL_PROPERTY_TODO_BYHOUR:
+               *out_str = (rec->byhour);
+               break;
+       case CAL_PROPERTY_TODO_BYDAY:
+               *out_str = (rec->byday);
+               break;
+       case CAL_PROPERTY_TODO_BYMONTHDAY:
+               *out_str = (rec->bymonthday);
+               break;
+       case CAL_PROPERTY_TODO_BYYEARDAY:
+               *out_str = (rec->byyearday);
+               break;
+       case CAL_PROPERTY_TODO_BYWEEKNO:
+               *out_str = (rec->byweekno);
+               break;
+       case CAL_PROPERTY_TODO_BYMONTH:
+               *out_str = (rec->bymonth);
+               break;
+       case CAL_PROPERTY_TODO_BYSETPOS:
+               *out_str = (rec->bysetpos);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA1:
+               *out_str = (rec->sync_data1);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA2:
+               *out_str = (rec->sync_data2);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA3:
+               *out_str = (rec->sync_data3);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA4:
+               *out_str = (rec->sync_data4);
+               break;
+       case CAL_PROPERTY_TODO_START_TZID:
+               *out_str = (rec->start_tzid);
+               break;
+       case CAL_PROPERTY_TODO_DUE_TZID:
+               *out_str = (rec->due_tzid);
+               break;
+       case CAL_PROPERTY_TODO_ORGANIZER_NAME:
+               *out_str = (rec->organizer_name);
+               break;
+       case CAL_PROPERTY_TODO_ORGANIZER_EMAIL:
+               *out_str = (rec->organizer_email);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_todo_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       cal_todo_s *rec = (cal_todo_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_TODO_ID:
+               *out_value = (rec->index);
+               break;
+       case CAL_PROPERTY_TODO_CALENDAR_ID:
+               *out_value = (rec->calendar_id);
+               break;
+       case CAL_PROPERTY_TODO_TODO_STATUS:
+               *out_value = (rec->todo_status);
+               break;
+       case CAL_PROPERTY_TODO_PRIORITY:
+               *out_value = (rec->priority);
+               break;
+       case CAL_PROPERTY_TODO_SENSITIVITY:
+               *out_value = (rec->sensitivity);
+               break;
+       case CAL_PROPERTY_TODO_PROGRESS:
+               *out_value = (rec->progress);
+               break;
+       case CAL_PROPERTY_TODO_IS_DELETED:
+               *out_value = (rec->is_deleted);
+               break;
+       case CAL_PROPERTY_TODO_FREQ:
+               *out_value = (rec->freq);
+               break;
+       case CAL_PROPERTY_TODO_RANGE_TYPE:
+               *out_value = (rec->range_type);
+               break;
+       case CAL_PROPERTY_TODO_COUNT:
+               *out_value = (rec->count);
+               break;
+       case CAL_PROPERTY_TODO_INTERVAL:
+               *out_value = (rec->interval);
+               break;
+       case CAL_PROPERTY_TODO_WKST:
+               *out_value = (rec->wkst);
+               break;
+       case CAL_PROPERTY_TODO_HAS_ALARM:
+               *out_value = (rec->has_alarm);
+               break;
+       case CAL_PROPERTY_TODO_HAS_ATTENDEE:
+               *out_value = (rec->has_attendee);
+               break;
+       case CAL_PROPERTY_TODO_IS_ALLDAY:
+               *out_value = (rec->is_allday);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_todo_get_double( calendar_record_h record, unsigned int property_id, double* out_value )
+{
+       cal_todo_s *rec = (cal_todo_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_TODO_LATITUDE:
+               *out_value = (rec->latitude);
+               break;
+       case CAL_PROPERTY_TODO_LONGITUDE:
+               *out_value = (rec->longitude);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_todo_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value )
+{
+       cal_todo_s *rec = (cal_todo_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_TODO_CREATED_TIME:
+               *out_value = (rec->created_time);
+               break;
+       case CAL_PROPERTY_TODO_LAST_MODIFIED_TIME:
+               *out_value = (rec->last_mod);
+               break;
+       case CAL_PROPERTY_TODO_COMPLETED_TIME:
+               *out_value = (rec->completed_time);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_todo_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value )
+{
+       cal_todo_s *rec = (cal_todo_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_TODO_START:
+               *out_value = rec->start;
+               break;
+       case CAL_PROPERTY_TODO_DUE:
+               *out_value = rec->due;
+               break;
+       case CAL_PROPERTY_TODO_UNTIL:
+               *out_value = rec->until;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_todo_set_str( calendar_record_h record, unsigned int property_id, const char* value )
+{
+       cal_todo_s *rec = (cal_todo_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_TODO_SUMMARY:
+               CAL_FREE(rec->summary);
+               rec->summary = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_DESCRIPTION:
+               CAL_FREE(rec->description);
+               rec->description = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_LOCATION:
+               CAL_FREE(rec->location);
+               rec->location = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_CATEGORIES:
+               CAL_FREE(rec->categories);
+               rec->categories = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_UID:
+               CAL_FREE(rec->uid);
+               rec->uid = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_BYSECOND:
+               CAL_FREE(rec->bysecond);
+               rec->bysecond = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_BYMINUTE:
+               CAL_FREE(rec->byminute);
+               rec->byminute = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_BYHOUR:
+               CAL_FREE(rec->byhour);
+               rec->byhour = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_BYDAY:
+               CAL_FREE(rec->byday);
+               rec->byday = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_BYMONTHDAY:
+               CAL_FREE(rec->bymonthday);
+               rec->bymonthday = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_BYYEARDAY:
+               CAL_FREE(rec->byyearday);
+               rec->byyearday = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_BYWEEKNO:
+               CAL_FREE(rec->byweekno);
+               rec->byweekno = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_BYMONTH:
+               CAL_FREE(rec->bymonth);
+               rec->bymonth = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_BYSETPOS:
+               CAL_FREE(rec->bysetpos);
+               rec->bysetpos = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA1:
+               CAL_FREE(rec->sync_data1);
+               rec->sync_data1 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA2:
+               CAL_FREE(rec->sync_data2);
+               rec->sync_data2 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA3:
+               CAL_FREE(rec->sync_data3);
+               rec->sync_data3 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA4:
+               CAL_FREE(rec->sync_data4);
+               rec->sync_data4 = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_START_TZID:
+               CAL_FREE(rec->start_tzid);
+               rec->start_tzid = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_DUE_TZID:
+               CAL_FREE(rec->due_tzid);
+               rec->due_tzid = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_ORGANIZER_NAME:
+               CAL_FREE(rec->organizer_name);
+               rec->organizer_name = SAFE_STRDUP(value);
+               break;
+       case CAL_PROPERTY_TODO_ORGANIZER_EMAIL:
+               CAL_FREE(rec->organizer_email);
+               rec->organizer_email = SAFE_STRDUP(value);
+               break;
+       default:
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_todo_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       cal_todo_s *rec = (cal_todo_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_TODO_ID:
+               (rec->index) = value;
+               break;
+       case CAL_PROPERTY_TODO_CALENDAR_ID:
+               (rec->calendar_id) = value;
+               break;
+       case CAL_PROPERTY_TODO_TODO_STATUS:
+               switch (value) {
+               case CALENDAR_TODO_STATUS_NONE:
+               case CALENDAR_TODO_STATUS_NEEDS_ACTION:
+               case CALENDAR_TODO_STATUS_COMPLETED:
+               case CALENDAR_TODO_STATUS_IN_PROCESS:
+               case CALENDAR_TODO_STATUS_CANCELED:
+                       (rec->todo_status) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_TODO_PRIORITY:
+               switch (value) {
+               case CALENDAR_TODO_PRIORITY_NONE:
+               case CALENDAR_TODO_PRIORITY_LOW:
+               case CALENDAR_TODO_PRIORITY_NORMAL:
+               case CALENDAR_TODO_PRIORITY_HIGH:
+                       (rec->priority) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_TODO_SENSITIVITY:
+               (rec->sensitivity) = value;
+               break;
+       case CAL_PROPERTY_TODO_PROGRESS:
+               (rec->progress) = value;
+               break;
+       case CAL_PROPERTY_TODO_IS_DELETED:
+               (rec->is_deleted) = value;
+               break;
+       case CAL_PROPERTY_TODO_FREQ:
+               switch (value) {
+               case CALENDAR_RECURRENCE_NONE:
+               case CALENDAR_RECURRENCE_DAILY:
+               case CALENDAR_RECURRENCE_WEEKLY:
+               case CALENDAR_RECURRENCE_MONTHLY:
+               case CALENDAR_RECURRENCE_YEARLY:
+                       (rec->freq) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_TODO_RANGE_TYPE:
+               switch (value) {
+               case CALENDAR_RANGE_UNTIL:
+               case CALENDAR_RANGE_COUNT:
+               case CALENDAR_RANGE_NONE:
+                       (rec->range_type) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_TODO_COUNT:
+               (rec->count) = value;
+               break;
+       case CAL_PROPERTY_TODO_INTERVAL:
+               (rec->interval) = value;
+               break;
+       case CAL_PROPERTY_TODO_WKST:
+               switch (value) {
+               case CALENDAR_SUNDAY:
+               case CALENDAR_MONDAY:
+               case CALENDAR_TUESDAY:
+               case CALENDAR_WEDNESDAY:
+               case CALENDAR_THURSDAY:
+               case CALENDAR_FRIDAY:
+               case CALENDAR_SATURDAY:
+                       (rec->wkst) = value;
+                       break;
+               default:
+                       ERR("invalid parameter (value:%d)", value);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_PROPERTY_TODO_HAS_ALARM:
+               (rec->has_alarm) = value;
+               break;
+       case CAL_PROPERTY_TODO_HAS_ATTENDEE:
+               (rec->has_attendee) = value;
+               break;
+       case CAL_PROPERTY_TODO_IS_ALLDAY:
+               (rec->is_allday) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_todo_set_double( calendar_record_h record, unsigned int property_id, double value )
+{
+       cal_todo_s *rec = (cal_todo_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_TODO_LATITUDE:
+               (rec->latitude) = value;
+               break;
+       case CAL_PROPERTY_TODO_LONGITUDE:
+               (rec->longitude) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_todo_set_lli( calendar_record_h record, unsigned int property_id, long long int value )
+{
+       cal_todo_s *rec = (cal_todo_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_TODO_CREATED_TIME:
+               (rec->created_time) = value;
+               break;
+       case CAL_PROPERTY_TODO_LAST_MODIFIED_TIME:
+               (rec->last_mod) = value;
+               break;
+       case CAL_PROPERTY_TODO_COMPLETED_TIME:
+               (rec->completed_time) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_todo_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value )
+{
+       cal_todo_s *rec = (cal_todo_s*)(record);
+       switch( property_id ) {
+       case CAL_PROPERTY_TODO_START:
+               (rec->start) = value;
+               break;
+       case CAL_PROPERTY_TODO_DUE:
+               (rec->due) = value;
+               break;
+       case CAL_PROPERTY_TODO_UNTIL:
+               (rec->until) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_todo_reset_child_record_id(calendar_record_h child_record)
+{
+       cal_record_s *record = (cal_record_s*)child_record;
+       retv_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       switch (record->type) {
+       case CAL_RECORD_TYPE_ALARM:
+               ((cal_alarm_s *)record)->id = 0;
+               break;
+       case CAL_RECORD_TYPE_ATTENDEE:
+               ((cal_attendee_s *)record)->id = 0;
+               break;
+       case CAL_RECORD_TYPE_EXTENDED:
+               ((cal_extended_s *)record)->id = 0;
+               break;
+       default:
+               ERR("Invalid child record type (%d)", record->type);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+
+static int __cal_record_todo_add_child_record( calendar_record_h record, unsigned int property_id, calendar_record_h child_record )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_todo_s *rec = (cal_todo_s*)(record);
+       __cal_record_todo_reset_child_record_id(child_record);
+
+       switch( property_id ) {
+       case CAL_PROPERTY_TODO_CALENDAR_ALARM:
+               ret = calendar_list_add((calendar_list_h)rec->alarm_list, child_record);
+               rec->has_alarm = 1;
+               break;
+       case CAL_PROPERTY_TODO_CALENDAR_ATTENDEE:
+               ret = calendar_list_add((calendar_list_h)rec->attendee_list, child_record);
+               rec->has_attendee = 1;
+               break;
+       case CAL_PROPERTY_TODO_EXTENDED:
+               ret = calendar_list_add((calendar_list_h)rec->extended_list, child_record);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return ret;
+}
+
+static int __cal_record_todo_remove_child_record( calendar_record_h record, unsigned int property_id, calendar_record_h child_record )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_todo_s *rec = (cal_todo_s *)record;
+
+       switch (property_id) {
+       case CAL_PROPERTY_TODO_CALENDAR_ALARM:
+               ret = calendar_list_remove((calendar_list_h)rec->alarm_list, child_record);
+               if (rec->alarm_list->count == 0)
+                       rec->has_alarm = 0;
+               break;
+       case CAL_PROPERTY_TODO_CALENDAR_ATTENDEE:
+               ret = calendar_list_remove((calendar_list_h)rec->attendee_list, child_record);
+               if (rec->attendee_list->count == 0)
+                       rec->has_attendee = 0;
+               break;
+       case CAL_PROPERTY_TODO_EXTENDED:
+               ret = calendar_list_remove((calendar_list_h)rec->extended_list, child_record);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return ret;
+}
+
+static int __cal_record_todo_get_child_record_count( calendar_record_h record, unsigned int property_id , unsigned int* count )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_todo_s *rec = (cal_todo_s *)record;
+
+       retv_if(NULL == count, CALENDAR_ERROR_INVALID_PARAMETER);
+       *count = 0;
+
+       switch (property_id) {
+       case CAL_PROPERTY_TODO_CALENDAR_ALARM:
+               ret = calendar_list_get_count((calendar_list_h)rec->alarm_list, (int *)count);
+               break;
+       case CAL_PROPERTY_TODO_CALENDAR_ATTENDEE:
+               ret = calendar_list_get_count((calendar_list_h)rec->attendee_list, (int *)count);
+               break;
+       case CAL_PROPERTY_TODO_EXTENDED:
+               ret = calendar_list_get_count((calendar_list_h)rec->extended_list, (int *)count);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return ret;
+}
+
+static int __cal_record_todo_get_child_record_at_p( calendar_record_h record, unsigned int property_id, int index, calendar_record_h* child_record )
+{
+       int ret;
+       cal_todo_s *rec = (cal_todo_s*)(record);
+
+       retv_if(NULL == child_record, CALENDAR_ERROR_INVALID_PARAMETER);
+       *child_record = NULL;
+
+       switch (property_id) {
+       case CAL_PROPERTY_TODO_CALENDAR_ALARM:
+               ret = _cal_list_get_nth_record_p(rec->alarm_list, index, child_record);
+               break;
+       case CAL_PROPERTY_TODO_CALENDAR_ATTENDEE:
+               ret = _cal_list_get_nth_record_p(rec->attendee_list, index, child_record);
+               break;
+       case CAL_PROPERTY_TODO_EXTENDED:
+               ret = _cal_list_get_nth_record_p(rec->extended_list, index, child_record);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return ret;
+}
+
+static int __cal_record_todo_clone_child_record_list( calendar_record_h record, unsigned int property_id, calendar_list_h* out_list )
+{
+       int ret;
+       cal_todo_s *rec = (cal_todo_s*)(record);
+
+       retv_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER);
+       *out_list = NULL;
+
+       switch (property_id) {
+       case CAL_PROPERTY_TODO_CALENDAR_ALARM:
+               ret = _cal_list_clone((calendar_list_h)rec->alarm_list, out_list);
+               break;
+       case CAL_PROPERTY_TODO_CALENDAR_ATTENDEE:
+               ret = _cal_list_clone((calendar_list_h)rec->attendee_list, out_list);
+               break;
+       case CAL_PROPERTY_TODO_EXTENDED:
+               ret = _cal_list_clone((calendar_list_h)rec->extended_list, out_list);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)", property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return ret;
+}
diff --git a/common/cal_record_updated_info.c b/common/cal_record_updated_info.c
new file mode 100644 (file)
index 0000000..565c1d7
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>     //calloc
+#include <stdbool.h>        //bool
+#include <string.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+
+static int __cal_record_updated_info_create( calendar_record_h* out_record );
+static int __cal_record_updated_info_destroy( calendar_record_h record, bool delete_child );
+static int __cal_record_updated_info_clone( calendar_record_h record, calendar_record_h* out_record );
+static int __cal_record_updated_info_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+static int __cal_record_updated_info_set_int( calendar_record_h record, unsigned int property_id, int value );
+
+cal_record_plugin_cb_s _cal_record_updated_info_plugin_cb = {
+       .create = __cal_record_updated_info_create,
+       .destroy = __cal_record_updated_info_destroy,
+       .clone = __cal_record_updated_info_clone,
+       .get_str = NULL,
+       .get_str_p = NULL,
+       .get_int = __cal_record_updated_info_get_int,
+       .get_double = NULL,
+       .get_lli = NULL,
+       .get_caltime = NULL,
+       .set_str = NULL,
+       .set_int = __cal_record_updated_info_set_int,
+       .set_double = NULL,
+       .set_lli = NULL,
+       .set_caltime = NULL,
+       .add_child_record = NULL,
+       .remove_child_record = NULL,
+       .get_child_record_count = NULL,
+       .get_child_record_at_p = NULL,
+       .clone_child_record_list = NULL
+};
+
+static int __cal_record_updated_info_create( calendar_record_h* out_record )
+{
+       cal_updated_info_s *temp = NULL;
+       int ret= CALENDAR_ERROR_NONE;
+
+       temp = (cal_updated_info_s*)calloc(1,sizeof(cal_updated_info_s));
+       retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_updated_info_s:sch) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       *out_record = (calendar_record_h)temp;
+
+       return ret;
+}
+
+static int __cal_record_updated_info_destroy( calendar_record_h record, bool delete_child )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_updated_info_s *temp = (cal_updated_info_s*)(record);
+
+       CAL_FREE(temp);
+
+       return ret;
+}
+
+static int __cal_record_updated_info_clone( calendar_record_h record, calendar_record_h* out_record )
+{
+       cal_updated_info_s *out_data = NULL;
+       cal_updated_info_s *src_data = NULL;
+
+       src_data = (cal_updated_info_s*)(record);
+
+       out_data = calloc(1, sizeof(cal_updated_info_s));
+       retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_updated_info_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+       CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
+
+       out_data->type = src_data->type;
+       out_data->id = src_data->id;
+       out_data->calendar_id = src_data->calendar_id;
+       out_data->version = src_data->version;
+
+       *out_record = (calendar_record_h)out_data;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_updated_info_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
+{
+       cal_updated_info_s *rec = (cal_updated_info_s*)(record);
+
+       switch( property_id )
+       {
+       case CAL_PROPERTY_UPDATED_INFO_ID:
+               *out_value = (rec->id);
+               break;
+       case CAL_PROPERTY_UPDATED_INFO_CALENDAR_ID:
+               *out_value = (rec->calendar_id);
+               break;
+       case CAL_PROPERTY_UPDATED_INFO_TYPE:
+               *out_value = (rec->type);
+               break;
+       case CAL_PROPERTY_UPDATED_INFO_VERSION:
+               *out_value = (rec->version);
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_record_updated_info_set_int( calendar_record_h record, unsigned int property_id, int value )
+{
+       cal_updated_info_s *rec = (cal_updated_info_s*)(record);
+       switch( property_id )
+       {
+       case CAL_PROPERTY_UPDATED_INFO_ID:
+               (rec->id) = value;
+               break;
+       case CAL_PROPERTY_UPDATED_INFO_CALENDAR_ID:
+               (rec->calendar_id) = value;
+               break;
+       case CAL_PROPERTY_UPDATED_INFO_TYPE:
+               (rec->type) = value;
+               break;
+       case CAL_PROPERTY_UPDATED_INFO_VERSION:
+               (rec->version) = value;
+               break;
+       default:
+               ERR("invalid parameter (property:%d)",property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/cal_time.cpp b/common/cal_time.cpp
new file mode 100644 (file)
index 0000000..c8ababe
--- /dev/null
@@ -0,0 +1,852 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <unicode/utypes.h>
+#include <unicode/ucal.h>
+#include <unicode/uloc.h>
+#include <unicode/calendar.h>
+#include <unicode/timezone.h>
+#include <unicode/gregocal.h>
+#include <unicode/simpletz.h>
+#include <unicode/ustring.h>
+#include <unicode/strenum.h>
+#include <unicode/ustdio.h>
+#include <unicode/udat.h>
+#include <unicode/rbtz.h>
+#include <unicode/uclean.h>
+
+#include "calendar.h"
+#include "cal_internal.h"
+#include "cal_typedef.h"
+
+#include "cal_time.h"
+
+#define ULOC_LOCALE_IDENTIFIER_CAPACITY (ULOC_FULLNAME_CAPACITY + 1 + ULOC_KEYWORD_AND_VALUES_CAPACITY)
+#define uprv_strncpy(dst, src, size) U_STANDARD_CPP_NAMESPACE strncpy(dst, src, size)
+
+#define ms2sec(ms) (long long int)(ms / 1000.0)
+#define sec2ms(s) (s * 1000.0)
+
+int _cal_time_is_registered_tzid(const char *tzid)
+{
+       int is_found = false;
+       int i;
+       UErrorCode ec = U_ZERO_ERROR;
+
+       if (NULL == tzid)
+       {
+               ERR("tzid is NULL");
+               return false;
+       }
+
+       StringEnumeration* s = TimeZone::createEnumeration();
+       int32_t s_count = s->count(ec);
+
+       for (i = 0; i < s_count; i++)
+       {
+               char buf[128] = {0};
+               const UnicodeString *unicode_tzid = s->snext(ec);
+               unicode_tzid->extract(buf, sizeof(buf), NULL, ec);
+               if (!strncmp(tzid, buf, strlen(buf)))
+               {
+                       is_found = true;
+                       break;
+               }
+       }
+       delete s;
+       return is_found;
+}
+
+void _cal_time_get_registered_tzid_with_offset(int offset, char *registered_tzid, int tzid_size) // offset unit: second
+{
+       UErrorCode ec = U_ZERO_ERROR;
+
+       retm_if (NULL == registered_tzid, "Invalid parameter: registered_tzid is NULL");
+
+       StringEnumeration* s = TimeZone::createEnumeration(sec2ms(offset));
+       if (0 == s->count(ec)) {
+               DBG("No tzid of offset(%d)sec", offset);
+               return;
+       }
+
+       const UnicodeString *unicode_tzid = s->snext(ec);
+       unicode_tzid->extract(registered_tzid, tzid_size, NULL, ec);
+       delete s;
+}
+
+int _cal_time_get_timezone_from_table(const char *tzid, calendar_record_h *timezone, int *timezone_id)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       int count = 0;
+       int _timezone_id = 0;
+       calendar_record_h _timezone = NULL;
+       calendar_filter_h filter = NULL;
+       calendar_query_h query = NULL;
+       calendar_list_h list = NULL;
+
+       if (NULL == tzid || strlen(tzid) == 0)
+       {
+               DBG("tzid is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = calendar_connect();
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_connect() failed");
+               return ret;
+       }
+
+       ret = calendar_query_create(_calendar_timezone._uri, &query);
+       if (CALENDAR_ERROR_NONE != ret) goto ERROR_CONNECT;
+
+       ret = calendar_filter_create(_calendar_timezone._uri, &filter);
+       if (CALENDAR_ERROR_NONE != ret) goto ERROR_QUERY;
+
+       ret = calendar_filter_add_str(filter, _calendar_timezone.standard_name, CALENDAR_MATCH_EXACTLY, tzid);
+       if (CALENDAR_ERROR_NONE != ret) goto ERROR_FILTER;
+
+       ret = calendar_query_set_filter(query, filter);
+       if (CALENDAR_ERROR_NONE != ret) goto ERROR_FILTER;
+
+       ret = calendar_db_get_records_with_query(query, 0, 0, &list);
+       if (CALENDAR_ERROR_NONE != ret) goto ERROR_LIST;
+
+       ret = calendar_list_get_count(list, &count);
+       if (CALENDAR_ERROR_NONE != ret) goto ERROR_LIST;
+       DBG("tzid count(%d)", count);
+       if (count <= 0)
+       {
+               DBG("No count");
+               calendar_list_destroy(list, false);
+               calendar_filter_destroy(filter);
+               calendar_query_destroy(query);
+               calendar_disconnect();
+               return CALENDAR_ERROR_NONE;
+       }
+
+       ret = calendar_list_first(list);
+       if (CALENDAR_ERROR_NONE != ret) goto ERROR_LIST;
+
+       ret = calendar_list_get_current_record_p(list, &_timezone);
+       if (CALENDAR_ERROR_NONE != ret) goto ERROR_LIST;
+
+       ret = calendar_record_get_int(_timezone, _calendar_timezone.id, &_timezone_id);
+       if (CALENDAR_ERROR_NONE != ret) goto ERROR_LIST;
+
+       calendar_list_destroy(list, false);
+       calendar_filter_destroy(filter);
+       calendar_query_destroy(query);
+       calendar_disconnect();
+
+       if (timezone)
+       {
+               *timezone = _timezone;
+       }
+       else
+       {
+               calendar_record_destroy(_timezone, true);
+       }
+       if (timezone_id) *timezone_id = _timezone_id;
+
+       return CALENDAR_ERROR_NONE;
+
+ERROR_LIST:
+       ERR("list error");
+       calendar_list_destroy(list, true);
+ERROR_FILTER:
+       ERR("filter error");
+       calendar_filter_destroy(filter);
+ERROR_QUERY:
+       ERR("queryerror");
+       calendar_query_destroy(query);
+ERROR_CONNECT:
+       calendar_disconnect();
+
+       return ret;
+}
+
+static int __cal_time_get_like_utzid(UChar *utzid, int len, const char *tzid, calendar_record_h timezone, char **like_tzid)
+{
+       int gmtoffset;
+       UErrorCode ec = U_ZERO_ERROR;
+
+       if (NULL == timezone)
+       {
+               ERR("Invalid parameter: timezone is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       // make utzid
+       UnicodeString zoneStrID;
+       int32_t l = (len < 0 ? u_strlen(utzid) : len);
+       zoneStrID.setTo((UBool)(len < 0), utzid, l); /* temporary read-only alias */
+
+       // make simple timezone
+       cal_timezone_s *tz = (cal_timezone_s *)timezone;
+       gmtoffset = sec2ms(tz->tz_offset_from_gmt * 60);
+
+       if (tz->day_light_bias == 0)
+       {
+               char buf[128] = {0};
+               snprintf(buf, sizeof(buf), "Etc/GMT%c%d",
+                               gmtoffset < 0 ? '+' : '-',
+                               tz->tz_offset_from_gmt / 60);
+               DBG("No dayligit, set like tzid[%s]", buf);
+               *like_tzid = strdup(buf);
+               return CALENDAR_ERROR_NONE;
+       }
+
+       DBG("Try to find like tzid with daylight savings");
+       SimpleTimeZone *stz = new SimpleTimeZone(
+                       sec2ms(tz->tz_offset_from_gmt * 60),
+                       zoneStrID,
+                       tz->day_light_start_month -1,
+                       tz->day_light_start_position_of_week,
+                       tz->day_light_start_day,
+                       sec2ms(tz->day_light_start_hour * 3600),
+                       tz->std_start_month -1,
+                       tz->std_start_position_of_week,
+                       tz->std_start_day,
+                       sec2ms(tz->std_start_hour * 3600),
+                       sec2ms(tz->day_light_bias * 60),
+                       ec);
+
+       int i, j;
+       UDate now = Calendar::getNow();
+       TimeZoneTransition trans;
+       UDate stzudate[5];
+       int32_t stzrawoff[4];
+       int32_t stzdstoff[4];
+       stzudate[0] = now;
+       DBG("tzid[%s]", tzid);
+       for (i = 0; i < 4; i++) // get 4 date: dst begin & end, std begin & end
+       {
+               stz->getPreviousTransition(stzudate[i], (UBool)false, trans);
+               stz->getOffset(stzudate[i], (UBool)true, stzrawoff[i], stzdstoff[i], ec);
+               stzudate[i +1] = trans.getTime();
+               DBG("(%lld)(%d)(%d)", ms2sec(stzudate[i +1]), stzrawoff[i], stzdstoff[i]);
+       }
+       delete stz;
+
+       // extract from all
+       int32_t rawoff;
+       int32_t dstoff;
+       int32_t s_count;
+       int is_found = 0;
+       char *_like_tzid = NULL;
+       UDate udate;
+       UnicodeString canonicalID, tmpCanonical;
+       StringEnumeration* s = TimeZone::createEnumeration(gmtoffset);
+       s_count = s->count(ec);
+
+       DBG("Has count(%d) with the same gmtoffset(%d)", s_count, gmtoffset);
+       if (s_count == 0)
+       {
+               DBG("No count matched");
+               return -1;
+       }
+
+       for (i = 0; i < s_count; i++)
+       {
+               const UnicodeString *unicode_tzid = s->snext(ec);
+               TimeZone *_timezone = TimeZone::createTimeZone(*unicode_tzid);
+
+               if (_timezone->getDSTSavings() != (gmtoffset))
+               {
+                       delete _timezone;
+                       continue;
+               }
+
+               RuleBasedTimeZone *rule = (RuleBasedTimeZone *)_timezone;
+               udate = now;
+               for (j = 0; j < 4; j++)
+               {
+                       rule->getPreviousTransition(udate, (UBool)false, trans);
+                       rule->getOffset(udate, (UBool)true, rawoff, dstoff, ec);
+                       udate = trans.getTime();
+                       DBG("(%lld)(%d)(%d)", ms2sec(udate), rawoff, dstoff);
+
+                       if (udate == stzudate[i+1] && rawoff == stzrawoff[i] && dstoff == stzdstoff[i])
+                       {
+                               DBG("Found matched");
+                               is_found = 1;
+                               break;
+                       }
+               }
+
+               if (is_found)
+               {
+                       _like_tzid = (char *)calloc(unicode_tzid->length() +1, sizeof(char));
+                       if (NULL == _like_tzid) {
+                               ERR("calloc() Fail");
+                               i = s_count;
+                               break;
+                       }
+
+                       for (i = 0; i < unicode_tzid->length(); i++)
+                       {
+                               _like_tzid[i] = unicode_tzid->charAt(i);
+                       }
+                       DBG("Found and set like tzid[%s]", _like_tzid);
+                       *like_tzid = _like_tzid;
+                       delete _timezone;
+                       break;
+               }
+
+               delete _timezone;
+       }
+       delete s;
+       return CALENDAR_ERROR_NONE;
+}
+
+UCalendar *_cal_time_open_ucal(int calendar_system_type, const char *tzid, int wkst)
+{
+       UChar utf16_timezone[64] = {0};
+       u_uastrncpy(utf16_timezone, tzid, sizeof(utf16_timezone));
+
+       UErrorCode status = U_ZERO_ERROR;
+       UCalendar *ucal = NULL;
+
+       char localeBuf[ULOC_LOCALE_IDENTIFIER_CAPACITY] = {0};
+
+       switch (calendar_system_type)
+       {
+       case CALENDAR_SYSTEM_EAST_ASIAN_LUNISOLAR:
+               DBG("-----lunar");
+               uloc_setKeywordValue("calendar", "chinese", localeBuf, ULOC_LOCALE_IDENTIFIER_CAPACITY, &status);
+               ucal = ucal_open(utf16_timezone, -1, localeBuf, UCAL_TRADITIONAL, &status);
+               break;
+
+       default: // include CALENDAR_SYSTEM_NONE, CALENDAR_SYSTEM_GREGORIAN
+               ucal = ucal_open(utf16_timezone, -1, uloc_getDefault(), UCAL_GREGORIAN, &status);
+               break;
+       }
+
+       if (U_FAILURE(status)) {
+               ERR("ucal_open failed (%s)", u_errorName(status));
+               return NULL;
+       }
+
+       if (wkst >= CALENDAR_SUNDAY && wkst <= CALENDAR_SATURDAY)
+       {
+               DBG("set wkst(%d)", wkst);
+               ucal_setAttribute(ucal, UCAL_FIRST_DAY_OF_WEEK, wkst);
+       }
+
+       return ucal;
+}
+
+UCalendar *_cal_time_get_ucal(const char *tzid, int wkst)
+{
+       UChar utf16_timezone[64] = {0};
+       u_uastrncpy(utf16_timezone, tzid, sizeof(utf16_timezone));
+
+       UErrorCode status = U_ZERO_ERROR;
+       UCalendar *ucal = NULL;
+       ucal = ucal_open(utf16_timezone, -1, uloc_getDefault(), UCAL_GREGORIAN, &status);
+       if (U_FAILURE(status)) {
+               ERR("ucal_open failed (%s)", u_errorName(status));
+               return NULL;
+       }
+
+       if (wkst >= CALENDAR_SUNDAY && wkst <= CALENDAR_SATURDAY)
+       {
+               DBG("set wkst(%d)", wkst);
+               ucal_setAttribute(ucal, UCAL_FIRST_DAY_OF_WEEK, wkst);
+       }
+
+       return ucal;
+}
+
+int _cal_time_get_like_tzid(const char *tzid, calendar_record_h timezone, char **like_tzid)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       UChar *utzid = NULL;
+
+       if (NULL == timezone)
+       {
+               ERR("Invalid parameter: timezone is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (tzid == NULL)
+       {
+               DBG("tzid is NULL so set gmt");
+               tzid = CAL_TZID_GMT;
+       }
+
+       utzid = (UChar*)calloc(strlen(tzid) + 1, sizeof(UChar));
+       if (utzid == NULL)
+       {
+               ERR("Failed to calloc");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       u_uastrcpy(utzid, tzid);
+
+       ret = __cal_time_get_like_utzid(utzid, u_strlen(utzid), tzid, timezone, like_tzid);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               DBG("Failed to find from timezone table, so set GMT");
+               *like_tzid = strdup(CAL_TZID_GMT);
+       }
+       CAL_FREE(utzid);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+void _cal_time_set_caltime(UCalendar *ucal, calendar_time_s *ct)
+{
+       UErrorCode status = U_ZERO_ERROR;
+
+       switch (ct->type)
+       {
+       case CALENDAR_TIME_UTIME:
+               ucal_setMillis(ucal, sec2ms(ct->time.utime), &status);
+               retm_if(U_FAILURE(status), "ucal_setMillis() failed(%s)",
+                               u_errorName(status));
+               break;
+
+       case CALENDAR_TIME_LOCALTIME:
+               ucal_setDateTime(ucal,
+                               ct->time.date.year,
+                               ct->time.date.month -1,
+                               ct->time.date.mday,
+                               ct->time.date.hour,
+                               ct->time.date.minute,
+                               ct->time.date.second,
+                               &status);
+               retm_if(U_FAILURE(status), "ucal_setMillis() failed(%s)",
+                               u_errorName(status));
+               break;
+
+       default:
+               ERR("Invalid dtstart type. Current time is used in default");
+       }
+}
+
+char * _cal_time_extract_by(int calendar_system_type, const char *tzid, int wkst, calendar_time_s *ct, int field)
+{
+       int vali;
+       char buf[8] = {0};
+       char weeks[7][3] = {"SU", "MO", "TU", "WE", "TH", "FR", "SA"};
+       UCalendar *ucal = NULL;
+       UErrorCode status = U_ZERO_ERROR;
+
+       ucal = _cal_time_open_ucal(calendar_system_type, tzid, wkst);
+       if (NULL == ucal) {
+               ERR("_cal_time_open_ucal() is failed");
+               return NULL;
+       }
+       _cal_time_set_caltime(ucal, ct);
+
+       switch (field)
+       {
+       case CAL_MONTH:
+               vali = ucal_get(ucal, UCAL_MONTH, &status) + 1;
+               snprintf(buf, sizeof(buf), "%d", vali);
+               break;
+
+       case CAL_DATE:
+               vali = ucal_get(ucal, UCAL_DATE, &status);
+               snprintf(buf, sizeof(buf), "%d", vali);
+               break;
+
+       case CAL_DAY_OF_WEEK:
+               vali = ucal_get(ucal, UCAL_DAY_OF_WEEK, &status);
+               snprintf(buf, sizeof(buf), "%s", weeks[vali - 1]);
+               break;
+
+       default:
+               break;
+
+       }
+       ucal_close(ucal);
+       return strdup(buf);
+}
+
+char * _cal_time_convert_ltos(const char *tzid, long long int lli, int is_allday)
+{
+       int y, mon, d, h, min, s;
+       char buf[32] = {0};
+       UCalendar *ucal;
+       UErrorCode status = U_ZERO_ERROR;
+
+       if (tzid == NULL) {
+               DBG("tzid is NULL so set gmt");
+               tzid = CAL_TZID_GMT;
+       }
+
+       ucal = _cal_time_get_ucal(tzid, -1);
+       retvm_if(NULL == ucal, NULL, "_cal_time_get_ucal() Fail");
+
+       ucal_setMillis(ucal, sec2ms(lli), &status);
+       if (U_FAILURE(status)) {
+               ERR("ucal_setMillis failed (%s)", u_errorName(status));
+               ucal_close(ucal);
+               return NULL;
+       }
+
+       y = ucal_get(ucal, UCAL_YEAR, &status);
+       mon = ucal_get(ucal, UCAL_MONTH, &status) + 1;
+       d = ucal_get(ucal, UCAL_DATE, &status);
+       h = ucal_get(ucal, UCAL_HOUR_OF_DAY, &status);
+       min = ucal_get(ucal, UCAL_MINUTE, &status);
+       s = ucal_get(ucal, UCAL_SECOND, &status);
+
+       if (!strncmp(tzid, CAL_TZID_GMT, strlen(CAL_TZID_GMT)))
+       {
+               snprintf(buf, sizeof(buf), "%04d%02d%02dT%02d%02d%02d%s", y, mon, d, h, min, s,
+                               is_allday ? "" : "Z");
+       }
+       else
+       {
+               snprintf(buf, sizeof(buf), "%04d%02d%02dT%02d%02d%02d", y, mon, d, h, min, s);
+       }
+
+       ucal_close(ucal);
+
+       return strdup(buf);
+}
+
+long long int _cal_time_convert_itol(const char *tzid, int y, int mon, int d, int h, int min, int s)
+{
+       long long int lli;
+       UCalendar *ucal = NULL;
+       UErrorCode status = U_ZERO_ERROR;
+
+       ucal = _cal_time_get_ucal(tzid, -1);
+       retvm_if(NULL == ucal, -1, "_cal_time_get_ucal() Fail");
+
+       ucal_set(ucal, UCAL_YEAR, y);
+       ucal_set(ucal, UCAL_MONTH, mon -1);
+       ucal_set(ucal, UCAL_DATE, d);
+       ucal_set(ucal, UCAL_HOUR_OF_DAY, h);
+       ucal_set(ucal, UCAL_MINUTE, min);
+       ucal_set(ucal, UCAL_SECOND, s);
+       ucal_set(ucal, UCAL_MILLISECOND, 0);
+       lli = ms2sec(ucal_getMillis(ucal, &status));
+
+       ucal_close(ucal);
+       return lli;
+}
+
+int _cal_time_utoi(long long int utime, char *tzid, int *y, int *m, int *d, int *h, int *min, int *s)
+{
+       UCalendar *ucal = NULL;
+       UErrorCode status = U_ZERO_ERROR;
+
+       ucal = _cal_time_get_ucal(tzid, -1);
+       retvm_if(NULL == ucal, -1, "_cal_time_get_ucal() Fail");
+       ucal_setMillis(ucal, sec2ms(utime), &status);
+       if (y) *y = ucal_get(ucal, UCAL_YEAR, &status);
+       if (m) *m = ucal_get(ucal, UCAL_MONTH, &status) + 1;
+       if (d) *d = ucal_get(ucal, UCAL_DATE, &status);
+       if (h) *h = ucal_get(ucal, UCAL_HOUR_OF_DAY, &status);
+       if (min) *min = ucal_get(ucal, UCAL_MINUTE, &status);
+       if (s) *s = ucal_get(ucal, UCAL_SECOND, &status);
+
+       ucal_close(ucal);
+       return CALENDAR_ERROR_NONE;
+}
+
+long long int _cal_time_convert_stol(char *tzid, char *datetime)
+{
+       int y, mon, d, h, min, s;
+       char t, z;
+
+       if (datetime == NULL || strlen(datetime) == 0) {
+               ERR("Invalid argument");
+               return -1;
+       }
+
+       sscanf(datetime,  "%4d%2d%2d%c%2d%2d%2d%c",
+                       &y, &mon, &d, &t, &h, &min, &s, &z);
+
+       return _cal_time_convert_itol(tzid, y, mon, d, h, min, s);
+}
+
+int _cal_time_ltoi(char *tzid, long long int lli, int *year, int *month, int *mday)
+{
+       UCalendar *ucal;
+       UErrorCode status = U_ZERO_ERROR;
+
+       ucal = _cal_time_get_ucal(tzid, 1);
+       retvm_if(NULL == ucal, -1, "_cal_time_get_ucal() Fail");
+       ucal_setMillis(ucal, sec2ms(lli), &status);
+
+       if (year) *year = ucal_get(ucal, UCAL_YEAR, &status);
+       if (month) *month = ucal_get(ucal, UCAL_MONTH, &status) +1;
+       if (mday) *mday = ucal_get(ucal, UCAL_DATE, &status);
+
+       ucal_close(ucal);
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_time_ltoi2(char *tzid, long long int lli, int *nth, int *wday)
+{
+       UCalendar *ucal;
+       UErrorCode status = U_ZERO_ERROR;
+
+       ucal = _cal_time_get_ucal(tzid, 1);
+       ucal_setMillis(ucal, sec2ms(lli), &status);
+
+       if (wday)  *wday = ucal_get(ucal, UCAL_DAY_OF_WEEK, &status);
+       if (nth)
+       {
+               int temp = 0;
+               int temp2 = 0;
+               temp = ucal_get(ucal, UCAL_DAY_OF_WEEK_IN_MONTH, &status);
+               ucal_add(ucal, UCAL_DAY_OF_YEAR, 7, &status);
+               temp2 = ucal_get(ucal, UCAL_DAY_OF_WEEK_IN_MONTH, &status);
+               DBG("temp(%d) temp2(%d)", temp, temp2);
+               *nth = temp2 == 1 ? -1 : temp;
+       }
+
+       ucal_close(ucal);
+       return CALENDAR_ERROR_NONE;
+}
+
+long long int _cal_time_get_now(void)
+{
+       return ms2sec(ucal_getNow());
+}
+
+int _cal_time_get_next_date(calendar_time_s *today, calendar_time_s *next)
+{
+       if (NULL == today || NULL == next)
+       {
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       UCalendar *ucal = NULL;
+       UErrorCode status = U_ZERO_ERROR;
+       UChar *utzid = NULL;
+       const char *tzid = CAL_TZID_GMT;
+
+       utzid = (UChar*)calloc(strlen(tzid) + 1, sizeof(UChar));
+       if (utzid == NULL)
+       {
+               ERR("Failed to calloc");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       u_uastrcpy(utzid, tzid);
+       ucal = ucal_open(utzid, u_strlen(utzid), "en_US", UCAL_TRADITIONAL, &status);
+       if (U_FAILURE(status)) {
+               ERR("ucal_open failed (%s)", u_errorName(status));
+               CAL_FREE(utzid);
+               return status;
+       }
+
+       switch (today->type)
+       {
+       case CALENDAR_TIME_UTIME:
+
+               break;
+
+       case CALENDAR_TIME_LOCALTIME:
+               ucal_setDateTime(ucal,
+                               today->time.date.year,
+                               today->time.date.month-1,
+                               today->time.date.mday,
+                               today->time.date.hour,
+                               today->time.date.minute,
+                               today->time.date.second,
+                               &status);
+               DBG("today %04d/%02d/%02d %02d:%02d:%02d",
+                               today->time.date.year, today->time.date.month, today->time.date.mday,
+                               today->time.date.hour, today->time.date.minute, today->time.date.second);
+               ucal_add(ucal, UCAL_DAY_OF_YEAR, 1, &status);
+               next->time.date.year = ucal_get(ucal, UCAL_YEAR, &status);
+               next->time.date.month = ucal_get(ucal, UCAL_MONTH, &status) + 1;
+               next->time.date.mday = ucal_get(ucal, UCAL_DATE, &status);
+               next->time.date.hour = ucal_get(ucal, UCAL_HOUR_OF_DAY, &status);
+               next->time.date.minute = ucal_get(ucal, UCAL_MINUTE, &status);
+               next->time.date.second = ucal_get(ucal, UCAL_SECOND, &status);
+               DBG("next %04d/%02d/%02d %02d:%02d:%02d",
+                               next->time.date.year, next->time.date.month, next->time.date.mday,
+                               next->time.date.hour, next->time.date.minute, next->time.date.second);
+               break;
+       }
+
+       CAL_FREE(utzid);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_time_get_next_time(UCalendar *ucal, int offset, int freq, calendar_time_s *next)
+{
+       UErrorCode status = U_ZERO_ERROR;
+       if (NULL == next)
+       {
+               ERR("Invalid parameter: next is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       switch (next->type)
+       {
+       case CALENDAR_TIME_UTIME:
+               ucal_setMillis(ucal, sec2ms(next->time.utime), &status);
+               break;
+
+       case CALENDAR_TIME_LOCALTIME:
+               ucal_setDateTime(ucal,
+                               next->time.date.year,
+                               next->time.date.month - 1,
+                               next->time.date.mday,
+                               next->time.date.hour,
+                               next->time.date.minute,
+                               next->time.date.second,
+                               &status);
+               break;
+       }
+
+       UCalendarDateFields unit = UCAL_DATE;
+       switch (freq)
+       {
+       case CALENDAR_RECURRENCE_YEARLY:
+               DBG("CALENDAR_RECURRENCE_YEARLY:");
+               unit = UCAL_YEAR;
+               break;
+       case CALENDAR_RECURRENCE_MONTHLY:
+               DBG("CALENDAR_RECURRENCE_MONTHLY:");
+               unit = UCAL_MONTH;
+               break;
+       case CALENDAR_RECURRENCE_WEEKLY:
+               DBG("CALENDAR_RECURRENCE_WEEKLY:");
+               unit = UCAL_WEEK_OF_YEAR;
+               break;
+       case CALENDAR_RECURRENCE_DAILY:
+               DBG("CALENDAR_RECURRENCE_DAILY:");
+               unit = UCAL_DATE;
+               break;
+       default:
+               ERR("Invalid unit");
+               break;
+       }
+       ucal_add(ucal, unit, offset, &status);
+
+       switch (next->type)
+       {
+       case CALENDAR_TIME_UTIME:
+               next->time.utime = ms2sec(ucal_getMillis(ucal, &status));
+               DBG("next utime(%lld)", next->time.utime);
+               break;
+
+       case CALENDAR_TIME_LOCALTIME:
+               next->time.date.year = ucal_get(ucal, UCAL_YEAR, &status);
+               next->time.date.month = ucal_get(ucal, UCAL_MONTH, &status) + 1;
+               next->time.date.mday = ucal_get(ucal, UCAL_DATE, &status);
+               next->time.date.hour = ucal_get(ucal, UCAL_HOUR_OF_DAY, &status);
+               next->time.date.minute = ucal_get(ucal, UCAL_MINUTE, &status);
+               next->time.date.second = ucal_get(ucal, UCAL_SECOND, &status);
+               DBG("next date(%04d/%02d/%02d %02d:%02d:%02d)",
+                               next->time.date.year, next->time.date.month, next->time.date.mday,
+                               next->time.date.hour, next->time.date.minute, next->time.date.second);
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+/*
+ * this code from settings/src/conf_util/setting-confutil.c
+ * time zone : /usr/share/zoneinfo/Asia/Seoul
+ * read from   /opt/etc/localtime
+ */
+char *_cal_time_get_timezone(void)
+{
+       char buf[256] = {0};
+       ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf)-1);
+       if (-1 == len)
+       {
+               ERR("readlink() failed");
+               return NULL;
+       }
+       buf[len] = '\0';
+       return g_strdup(buf + strlen("/usr/share/zoneinfo/"));
+}
+
+long long int _cal_time_get_utime(UCalendar *ucal, int y, int mon, int d, int h, int min, int s)
+{
+       UErrorCode status = U_ZERO_ERROR;
+       if (ucal)
+       {
+               ucal_set(ucal, UCAL_YEAR, y);
+               ucal_set(ucal, UCAL_MONTH, mon -1);
+               ucal_set(ucal, UCAL_DATE, d);
+               ucal_set(ucal, UCAL_HOUR_OF_DAY, h);
+               ucal_set(ucal, UCAL_MINUTE, min);
+               ucal_set(ucal, UCAL_SECOND, s);
+               ucal_set(ucal, UCAL_MILLISECOND, 0);
+               return ms2sec(ucal_getMillis(ucal, &status));
+       }
+       return 0;
+}
+
+int _cal_time_get_component_from_lli(UCalendar *ucal, long long int lli, int *year, int *month, int *mday, int *hour, int *minute, int *second)
+{
+       UErrorCode status = U_ZERO_ERROR;
+
+       ucal_setMillis(ucal, sec2ms(lli), &status);
+
+       if (year) *year = ucal_get(ucal, UCAL_YEAR, &status);
+       if (month) *month = ucal_get(ucal, UCAL_MONTH, &status) +1;
+       if (mday) *mday = ucal_get(ucal, UCAL_DATE, &status);
+       if (hour) *hour = ucal_get(ucal, UCAL_DATE, &status);
+       if (minute) *minute = ucal_get(ucal, UCAL_DATE, &status);
+       if (second) *second = ucal_get(ucal, UCAL_DATE, &status);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+void _cal_time_u_cleanup(void)
+{
+       u_cleanup();
+}
+
+void _cal_time_get_tz_offset(const char *tz, time_t *zone_offset, time_t *dst_offset)
+{
+       UErrorCode status = U_ZERO_ERROR;
+       UCalendar *ucal = NULL;
+
+       ucal = _cal_time_get_ucal(tz, -1);
+       retm_if(NULL == ucal, "_cal_time_get_ucal() Fail");
+       int32_t zone = ucal_get(ucal, UCAL_ZONE_OFFSET, &status);
+       int32_t dst = ucal_get(ucal, UCAL_DST_OFFSET, &status);
+       ucal_close(ucal);
+
+       if (zone_offset) *zone_offset = ms2sec(zone);
+       if (dst_offset) *dst_offset = ms2sec(dst);
+}
+
+bool _cal_time_in_dst(const char *tz, long long int t)
+{
+       UErrorCode status = U_ZERO_ERROR;
+       UCalendar *ucal = NULL;
+
+       ucal = _cal_time_get_ucal(tz, -1);
+       retvm_if(NULL == ucal, false, "_cal_time_get_ucal() Fail");
+       ucal_setMillis(ucal, sec2ms(t), &status);
+       bool is_dst = ucal_inDaylightTime(ucal, &status);
+       ucal_close(ucal);
+
+       return is_dst;
+}
diff --git a/common/cal_time.h b/common/cal_time.h
new file mode 100644 (file)
index 0000000..1875541
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_TIME_H__
+#define __CALENDAR_SVC_TIME_H__
+
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <unicode/ucal.h>
+#include <unicode/ustring.h>
+#include <unicode/ustdio.h>
+#include <unicode/udat.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int _cal_time_is_registered_tzid(const char *tzid);
+void _cal_time_get_registered_tzid_with_offset(int offset, char *registered_tzid, int tzid_size);
+UCalendar *_cal_time_get_ucal(const char *tzid, int wkst);
+char * _cal_time_extract_by(int calendar_system_type, const char *tzid, int wkst, calendar_time_s *ct, int field);
+char * _cal_time_convert_ltos(const char *tzid, long long int lli, int is_allday);
+long long int _cal_time_convert_itol(const char *tzid, int y, int m, int d, int h, int min, int s);
+int _cal_time_utoi(long long int utime, char *tzid, int *y, int *m, int *d, int *h, int *min, int *s);
+long long int _cal_time_convert_stol(char *tzid, char *datetime);
+int _cal_time_ltoi(char *tzid, long long int lli, int *year, int *month, int *mday);
+int _cal_time_ltoi2(char *tzid, long long int lli, int *nth, int *wday);
+long long int _cal_time_get_now(void);
+int _cal_time_get_timezone_from_table(const char *tzid, calendar_record_h *timezone, int *timezone_id);
+int _cal_time_get_like_tzid(const char *tzid, calendar_record_h timezone, char **like_tzid);
+int _cal_time_get_next_date(calendar_time_s *today, calendar_time_s *next);
+char *_cal_time_get_timezone(void);
+long long int _cal_time_get_utime(UCalendar *ucal, int y, int mon, int d, int h, int min, int s);
+int _cal_time_get_component_from_lli(UCalendar *ucal, long long int lli, int *year, int *month, int *mday, int *hour, int *minute, int *second);
+int _cal_time_get_next_time(UCalendar *ucal, int offset, int freq, calendar_time_s *next);
+void _cal_time_u_cleanup(void);
+void _cal_time_get_tz_offset(const char *tz, time_t *zone_offset, time_t *dst_offset);
+bool _cal_time_in_dst(const char *tz, long long int t);
+UCalendar *_cal_time_open_ucal(int calendar_system_type, const char *tzid, int wkst);
+
+enum cal_extract_field {
+       CAL_MONTH,
+       CAL_DAY_OF_WEEK,
+       CAL_DATE,
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // __CALENDAR_SVC_TIME_H__
diff --git a/common/cal_typedef.h b/common/cal_typedef.h
new file mode 100755 (executable)
index 0000000..e81b51d
--- /dev/null
@@ -0,0 +1,529 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_TYPEDEF_H__
+#define __CALENDAR_SVC_TYPEDEF_H__
+
+#include <glib.h>
+#include <complex.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include "cal_record.h"
+
+#define CAL_TZID_GMT "Etc/GMT"
+#define CAL_NOTI_EVENT_CHANGED "/opt/usr/data/calendar-svc/.CALENDAR_SVC_EVENT_CHANGED"
+#define CAL_NOTI_TODO_CHANGED "/opt/usr/data/calendar-svc/.CALENDAR_SVC_TODO_CHANGED"
+#define CAL_NOTI_CALENDAR_CHANGED "/opt/usr/data/calendar-svc/.CALENDAR_SVC_CALENDAR_CHANGED"
+#define CAL_NOTI_IPC_READY "/opt/usr/data/calendar-svc/.CALENDAR_SVC_IPC_READY"
+#define CAL_NOTI_REMINDER_CAHNGED "reminder"
+#define CAL_FORMAT_LOCAL_DATETIME "%04d-%02d-%02dT%02d:%02d:%02d"
+
+/**
+ * @enum cal_priority_e
+ * This enumeration defines priority for todo data.
+ */
+typedef enum
+{
+       CAL_PRIORITY_LOW,       /**< priority low */
+       CAL_PRIORITY_MID,       /**< priority middle */
+       CAL_PRIORITY_HIGH       /**< priority high */
+}cal_priority_e;
+
+typedef enum
+{
+       CAL_PERMISSION_NONE = 0x00,
+       CAL_PERMISSION_READ = 0x01,
+       CAL_PERMISSION_WRITE = 0x02,
+} cal_permission_e;
+
+#define LOCAL_ACCOUNT_ID -1
+
+#define CAL_INVALID_ID                         (-1)
+
+typedef enum
+{
+       CAL_SCH_TYPE_NONE=0,           /**< None type */
+       CAL_SCH_TYPE_EVENT,    /**< schedule event type */
+       CAL_SCH_TYPE_TODO,     /**< task event type */
+       CAL_SCH_TYPE_MAX,      /**< max type */
+} cal_sch_type_e;
+
+typedef struct {
+       int count;
+       GList *record;
+       GList *cursor;
+} cal_list_s;
+
+/**
+ * This structure defines schedule information.
+ */
+typedef struct
+{
+       cal_record_s common;
+       int index;                              /**< Record index */
+       int calendar_id;
+
+       char *summary;                  /**< Summary, appointment, task: subject, birthday:Name */
+       char *description;              /**< Description,appointment, task: description, anniversary,holiday:occasion*/
+       char *location;                 /**< Location */
+       char *categories;
+       char *exdate;
+
+       calendar_event_status_e event_status;           /**< current task status */
+       cal_priority_e priority;                /**< Priority */
+       int timezone;                   /**< timezone of task */
+
+       int contact_id;                 /**< contact id for birthday in contact list */
+
+       int busy_status;                /**< ACS, G : Flag of busy or not */
+       int sensitivity;                /**< ACS, G : The sensitivity (public, private, confidential). #cal_visibility_type_t*/
+       int meeting_status;             /**< ACS, G : The status of the meeting. */
+       char *uid;                              /**< ACS, G : Unique ID of the meeting item */
+       char *organizer_name;           /**< ACS, G : Name of organizer(author) */
+       char *organizer_email;  /**< ACS, G : Email of organizer */
+
+       int original_event_id;        /**< original event id for recurrency exception */
+       double latitude;
+       double longitude;
+       int email_id;
+       long long int created_time;
+       int is_deleted; /**< for sync */
+       long long int last_mod;
+       int freq;
+       int range_type;
+       calendar_time_s until;
+       int count;
+       int interval;
+       char *bysecond;
+       char *byminute;
+       char *byhour;
+       char *byday;
+       char *bymonthday;
+       char *byyearday;
+       char *byweekno;
+       char *bymonth;
+       char *bysetpos;
+       int wkst;
+       char *recurrence_id;
+       char *rdate;
+       int has_attendee;
+       int has_alarm;
+       int system_type;
+       long updated;
+       char *sync_data1;
+       char *sync_data2;
+       char *sync_data3;
+       char *sync_data4;
+
+       calendar_time_s start;
+       char* start_tzid;
+       calendar_time_s end;
+       char* end_tzid;
+       int is_allday;
+       cal_list_s *alarm_list;
+       cal_list_s *attendee_list;
+       cal_list_s *exception_list;
+       cal_list_s *extended_list;
+}cal_event_s;
+
+typedef struct
+{
+       cal_record_s common;
+       int index;
+       int calendar_id;
+       char *summary;
+       char *description;
+       char *location;
+       char *categories;
+       calendar_todo_status_e todo_status;
+       cal_priority_e priority;
+       int sensitivity;
+       char *uid;
+       double latitude;
+       double longitude;
+       long long int created_time;
+       long long int completed_time;
+       int progress;
+       int is_deleted; /**< for sync */
+       long long int last_mod;
+       int freq;
+       int range_type;
+       calendar_time_s until;
+       int count;
+       int interval;
+       char *bysecond;
+       char *byminute;
+       char *byhour;
+       char *byday;
+       char *bymonthday;
+       char *byyearday;
+       char *byweekno;
+       char *bymonth;
+       char *bysetpos;
+       int wkst;
+       int has_alarm;
+       long updated;
+       char *sync_data1;
+       char *sync_data2;
+       char *sync_data3;
+       char *sync_data4;
+       calendar_time_s start;
+       char* start_tzid;
+       calendar_time_s due;
+       char* due_tzid;
+       char *organizer_name;
+       char *organizer_email;
+       int has_attendee;
+       int is_allday;
+
+       cal_list_s *alarm_list;
+       cal_list_s *attendee_list;
+       cal_list_s *extended_list;
+}cal_todo_s;
+
+typedef struct
+{
+       int freq;
+       int range_type;
+       calendar_time_s until;
+       int count;
+       int interval;
+       char *bysecond;
+       char *byminute;
+       char *byhour;
+       char *byday;
+       char *bymonthday;
+       char *byyearday;
+       char *byweekno;
+       char *bymonth;
+       char *bysetpos;
+       int wkst;
+}cal_rrule_s;
+
+/**
+ * This structure defines participant information of a meetting.
+ * ical: cutype, member, role, partstat, rsvp, delto, delfrom, sentby, cn,  dir, language
+ */
+typedef struct
+{
+       cal_record_s common;
+       int id; /* Internal property. Do not add to view_uri property */
+       int parent_id;
+       char *attendee_number;
+       int attendee_cutype;
+       int attendee_ct_index;
+       char *attendee_uid;
+
+       /* ical spec from here */
+       char *attendee_group;   /* cutype */
+       char *attendee_email;   /* member */
+       int attendee_role;              /* role */
+       int attendee_status;    /* partstat: ACCEPTED, DECLINED.. */
+       int attendee_rsvp;              /* rsvp */
+       char *attendee_delegatee_uri;   /* delfrom */
+       char *attendee_delegator_uri;   /* delto */
+       /* sentby */
+       char *attendee_name;    /* cn */
+       char *attendee_member;  /* member */
+
+}cal_attendee_s;
+
+/**
+ * This structure defines exception information of alarm.
+ */
+typedef struct
+{
+       cal_record_s common;
+       int id; /* Internal property. Do not add to view_uri property */
+       int parent_id;
+       int is_deleted;
+
+       int remind_tick;
+       int remind_tick_unit;
+
+       char *alarm_description;                        /**< Alert description */
+       char *alarm_summary;
+       int alarm_action;
+       char *alarm_attach;
+       calendar_time_s alarm;
+}cal_alarm_s;
+
+//This is the calendar schema
+typedef struct
+{
+       cal_record_s common;
+       int index;
+       int store_type;
+       char *uid;
+       long updated;
+       char *name;
+       char *description;
+       char *color;
+       char *location;
+       int visibility;
+       int sync_event;
+       int is_deleted;
+       int account_id;
+       char *sync_data1;
+       char *sync_data2;
+       char *sync_data3;
+       char *sync_data4;
+       int mode;
+} cal_calendar_s;
+
+
+/* type for timezone information save */
+typedef struct
+{
+       cal_record_s common;
+       int index;
+       int tz_offset_from_gmt;
+
+       char *standard_name;
+       int std_start_month;
+       int std_start_position_of_week;
+       int std_start_day;
+       int std_start_hour;
+       int standard_bias;
+
+       char *day_light_name;
+       int day_light_start_month;
+       int day_light_start_position_of_week;
+       int day_light_start_day;
+       int day_light_start_hour;
+       int day_light_bias;
+       int calendar_id;
+} cal_timezone_s;
+
+typedef struct
+{
+       cal_record_s common;
+       int event_id;
+       int calendar_id;
+       calendar_time_s start;
+       calendar_time_s end;
+       char *summary;
+       char *description;
+       char *location;
+       int busy_status;
+       int event_status;
+       int priority;
+       int sensitivity;
+       int has_rrule;  //rrule_id;
+       double latitude;
+       double longitude;
+       int has_alarm;
+       int original_event_id;
+       long long int last_mod;
+       char *sync_data1;
+} cal_instance_normal_s;
+
+typedef struct
+{
+       cal_record_s common;
+       int event_id;
+       int calendar_id;
+       calendar_time_s start;
+       calendar_time_s end;
+       char *summary;
+       char *description;
+       char *location;
+       int busy_status;
+       int event_status;
+       int priority;
+       int sensitivity;
+       int has_rrule;  //rrule_id;
+       double latitude;
+       double longitude;
+       int has_alarm;
+       int original_event_id;
+       long long int last_mod;
+       char *sync_data1;
+       int is_allday;
+} cal_instance_allday_s;
+
+typedef struct
+{
+       cal_record_s common;
+       int event_id;
+       int calendar_id;
+       calendar_time_s start;
+       calendar_time_s end;
+       char *summary;
+       char *description;
+       char *location;
+       int busy_status;
+       int event_status;
+       int priority;
+       int sensitivity;
+       int has_rrule;  //rrule_id;
+       double latitude;
+       double longitude;
+       int has_alarm;
+       int original_event_id;
+       long long int last_mod;
+       char *organizer_name;
+       char *categories;
+       int has_attendee;
+       char *sync_data1;
+       char *sync_data2;
+       char *sync_data3;
+       char *sync_data4;
+} cal_instance_normal_extended_s;
+
+typedef struct
+{
+       cal_record_s common;
+       int event_id;
+       int calendar_id;
+       calendar_time_s start;
+       calendar_time_s end;
+       char *summary;
+       char *description;
+       char *location;
+       int busy_status;
+       int event_status;
+       int priority;
+       int sensitivity;
+       int has_rrule;  //rrule_id;
+       double latitude;
+       double longitude;
+       int has_alarm;
+       int original_event_id;
+       long long int last_mod;
+       char *sync_data1;
+       char *organizer_name;
+       char *categories;
+       int has_attendee;
+       char *sync_data2;
+       char *sync_data3;
+       char *sync_data4;
+       int is_allday;
+} cal_instance_allday_extended_s;
+
+typedef struct
+{
+       cal_record_s common;
+       int type;
+       int id;
+       int calendar_id;
+       int version;
+}cal_updated_info_s;
+
+typedef enum
+{
+       CAL_NOTI_TYPE_EVENT = 0x0,
+       CAL_NOTI_TYPE_TODO,
+       CAL_NOTI_TYPE_CALENDAR,
+}cal_noti_type_e;
+
+typedef struct{
+       unsigned int property_id;
+       const char* fields;               // DB field
+}cal_property_info_s;
+
+typedef enum {
+       CAL_FILTER_STR,
+       CAL_FILTER_INT,
+       CAL_FILTER_DOUBLE,
+       CAL_FILTER_LLI,
+       CAL_FILTER_CALTIME,
+       CAL_FILTER_COMPOSITE,
+}cal_filter_type_e;
+
+typedef struct  {
+       int filter_type;     // composite
+}cal_filter_s;
+
+typedef struct {
+       int filter_type;
+       char *view_uri;
+       GSList *filter_ops; //calendar_filter_operator_e op;
+       GSList *filters;    //calendar_filter_h l_filter;
+       cal_property_info_s *properties;
+       int property_count;
+}cal_composite_filter_s;
+
+typedef struct  {
+       int filter_type;     //cal_filter_type_e
+       int property_id;
+       int match;              //calendar_match_str_flag_e or calendar_match_int_flag_e
+       union {
+               int i;
+               char *s;
+               double d;
+               long long int lli;
+               calendar_time_s caltime;
+       }value;
+}cal_attribute_filter_s;
+
+typedef struct  {
+       char* view_uri;
+       cal_composite_filter_s* filter;
+       int projection_count;
+       unsigned int *projection;
+       int sort_property_id;
+       bool asc;
+       cal_property_info_s *properties;
+       int property_count;
+       bool distinct;
+}cal_query_s;
+
+#define CAL_CALTIME_SET_UTIME(dest, src_utime) do {\
+       (dest).type = CALENDAR_TIME_UTIME; \
+       (dest).time.utime = src_utime; \
+} while(0)
+
+#define CAL_CALTIME_SET_DATE(dest, src_year, src_month, src_mday) do {\
+       (dest).type = CALENDAR_TIME_LOCALTIME; \
+       (dest).time.date.year = src_year; \
+       (dest).time.date.month = src_month; \
+       (dest).time.date.mday = src_mday; \
+} while(0)
+
+typedef struct {
+       int property_id;
+       union {
+               int i;
+               char *s;
+               double d;
+               long long int lli;
+               calendar_time_s caltime;
+       }value;
+}cal_search_value_s;
+
+typedef struct {
+       cal_record_s common;
+       GSList *values;
+}cal_search_s;
+
+typedef struct {
+       cal_record_s common;
+       int id;
+       int record_id;
+       int record_type;
+       char* key;
+       char* value;
+}cal_extended_s;
+
+/**
+ * @}
+ */
+
+#endif // __CALENDAR_SVC_TYPEDEF_H__
diff --git a/common/cal_vcalendar.c b/common/cal_vcalendar.c
new file mode 100644 (file)
index 0000000..2a0ae60
--- /dev/null
@@ -0,0 +1,274 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "calendar_vcalendar.h"
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_record.h"
+#include "cal_view.h"
+#include "cal_time.h"
+#include "cal_list.h"
+
+#include "cal_vcalendar.h"
+#include "cal_vcalendar_make.h"
+#include "cal_vcalendar_parse.h"
+
+#define ICALENAR_BUFFER_MAX (1024*1024)
+
+/*
+ * vcalendar should not have multi version: ver1.0 or 2.0 only.
+ * could have multi timezone events: MULTI BEGIN:VCALENDAR.
+ */
+API int calendar_vcalendar_make_from_records(calendar_list_h list, char **vcalendar_stream)
+{
+       int ret;
+       cal_make_s *b;
+       char *ical = NULL;
+
+       retvm_if(list == NULL, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid argument: calendar_list_h is NULL");
+       retvm_if(vcalendar_stream == NULL, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid argument: vcalendar_stream is NULL");
+
+       b = _cal_vcalendar_make_new();
+       retvm_if(!b, CALENDAR_ERROR_OUT_OF_MEMORY,
+                       "_cal_vcalendar_make_new() Failed");
+
+       ret = _cal_vcalendar_make_vcalendar(b, list);
+
+       if (ret < 0) {
+               _cal_vcalendar_make_free(&b);
+               return ret;
+       }
+
+       ical = _cal_vcalendar_make_get_data(b);
+       _cal_vcalendar_make_free(&b);
+
+       if (!ical) {
+               ERR("Failed to get ical data");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       if (!*ical) {
+               ERR("No ical data");
+               free(ical);
+               return CALENDAR_ERROR_NO_DATA;
+       }
+
+       *vcalendar_stream = ical;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static const char* __calendar_vcalendar_get_vcalendar_object(const char *original, char **pvcalendar_object)
+{
+       int len = 0;
+       const char *vcal_start = original;
+       const char *vcal_cursor = NULL;
+       bool new_line = false;
+       char *vcalendar_object = NULL;
+
+       retv_if(NULL == pvcalendar_object, original);
+       *pvcalendar_object = NULL;
+
+       while ('\n' == *vcal_start || '\r' == *vcal_start)
+               vcal_start++;
+
+       if (strncmp(vcal_start, "BEGIN:VCALENDAR", strlen("BEGIN:VCALENDAR")))
+               return vcal_start;
+
+       vcal_start += strlen("BEGIN:VCALENDAR");
+       while ('\n' == *vcal_start || '\r' == *vcal_start)
+               vcal_start++;
+       vcal_cursor = vcal_start;
+
+       while (*vcal_cursor) {
+               if (new_line) {
+                       if (0 == strncmp(vcal_cursor, "END:VCALENDAR", strlen("END:VCALENDAR"))) {
+                               vcal_cursor += strlen("END:VCALENDAR");
+                               while ('\r' == *vcal_cursor || '\n' == *vcal_cursor) {
+                                       new_line = true;
+                                       vcal_cursor++;
+                               }
+
+                               len = (int)vcal_cursor - (int)vcal_start;
+                               vcalendar_object = calloc(len + 1, sizeof(char));
+                               if (NULL == vcalendar_object) {
+                                       ERR("calloc() Fail");
+                                       return NULL;
+                               }
+                               memcpy(vcalendar_object, vcal_start, len);
+                               *pvcalendar_object = vcalendar_object;
+
+                               return vcal_cursor;
+                       }
+                       new_line = false;
+               }
+               vcal_cursor++;
+               while ('\r' == *vcal_cursor || '\n' == *vcal_cursor) {
+                       new_line = true;
+                       vcal_cursor++;
+               }
+       }
+       return vcal_cursor;
+}
+
+/*
+ * parse from here
+ */
+API int calendar_vcalendar_parse_to_calendar(const char* vcalendar_stream, calendar_list_h *out_list)
+{
+       int count = 0;
+       const char *cursor = NULL;
+       char *vcalendar_object = NULL;
+       calendar_error_e err;
+       calendar_list_h list = NULL;
+
+       retvm_if(vcalendar_stream == NULL, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid argument: vcalendar_stream is NULL");
+       retvm_if(out_list == NULL, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid argument: calendar_list_h * is NULL");
+
+       // get vcalendar object
+       cursor = vcalendar_stream;
+
+       int ret = 0;
+       ret = calendar_list_create(&list);
+       retvm_if (CALENDAR_ERROR_NONE != ret, ret, "Failed to calendar_list_create()");
+       while (NULL != (cursor = __calendar_vcalendar_get_vcalendar_object(cursor, &vcalendar_object))) {
+               if (NULL == vcalendar_object)
+                       break;
+
+               err = _cal_vcalendar_parse_vcalendar_object(vcalendar_object, list, NULL);
+               if (CALENDAR_ERROR_NONE != err) {
+                       ERR("_cal_vcalendar_parse_vcalendar_object() failed(%d)", err);
+                       calendar_list_destroy(list, true);
+                       free(vcalendar_object);
+                       return err;
+               }
+               free(vcalendar_object);
+       }
+       calendar_list_get_count(list, &count);
+       if (count <= 0) {
+               calendar_list_destroy(list, true);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       calendar_list_first(list);
+       *out_list = list;
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_vcalendar_parse_to_calendar_foreach(const char *vcalendar_file_path, calendar_vcalendar_parse_cb callback, void *user_data)
+{
+       FILE *file;
+       int buf_size, len;
+       char *stream = NULL;
+       char buf[1024];
+       vcalendar_foreach_s *foreach_data = NULL;
+
+       retvm_if(vcalendar_file_path == NULL, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid argument: vcalendar_file_path is NULL");
+       retvm_if(callback == NULL, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid argument: callback is NULL");
+
+       int ret = 0;
+       calendar_list_h list = NULL;
+       ret = calendar_list_create(&list);
+       retvm_if (CALENDAR_ERROR_NONE != ret, ret, "Failed to calendar_list_create()");
+
+       file = fopen(vcalendar_file_path, "r");
+       if (file == NULL) {
+               ERR("Invalid argument: no file");
+               calendar_list_destroy(list, true);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       len = 0;
+       buf_size = ICALENAR_BUFFER_MAX;
+       stream = calloc(ICALENAR_BUFFER_MAX, sizeof(char));
+       if (NULL == stream) {
+               ERR("calloc() Fail()");
+               calendar_list_destroy(list, true);
+               fclose(file);
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       foreach_data = calloc(1, sizeof(vcalendar_foreach_s));
+       if (NULL == foreach_data) {
+               ERR("calloc() Fail");
+               calendar_list_destroy(list, true);
+               free(stream);
+               fclose(file);
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       foreach_data->callback = callback;
+       foreach_data->user_data = user_data;
+       foreach_data->ret = true;
+
+       while (fgets(buf, sizeof(buf), file)) {
+               if (len + sizeof(buf) < buf_size) {
+                       len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
+               }
+               else {
+                       char *new_stream;
+                       buf_size *= 2;
+                       new_stream = realloc(stream, buf_size);
+                       if (new_stream) {
+                               stream = new_stream;
+                       }
+                       else {
+                               free(stream);
+                               fclose(file);
+                               free(foreach_data);
+                               calendar_list_destroy(list, true);
+                               ERR("out of memory");
+                               return CALENDAR_ERROR_OUT_OF_MEMORY;
+                       }
+                       len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
+               }
+
+               if (0 == strncmp(buf, "END:VCALENDAR", strlen("END:VCALENDAR"))) {
+                       DBG("end vcalendar");
+                       int err;
+                       char *vcalendar_object = NULL;
+                       __calendar_vcalendar_get_vcalendar_object(stream, &vcalendar_object);
+                       err = _cal_vcalendar_parse_vcalendar_object(vcalendar_object, list, foreach_data);
+                       if (CALENDAR_ERROR_NONE != err || false == foreach_data->ret) {
+                               ERR("_cal_vcalendar_parse_vcalendar_object() failed(%d)", err);
+                               calendar_list_destroy(list, true);
+                               free(vcalendar_object);
+                               free(stream);
+                               free(foreach_data);
+                               fclose(file);
+                               return err;
+                       }
+                       free(vcalendar_object);
+                       len = 0;
+               }
+       }
+
+       calendar_list_destroy(list, true);
+       free(stream);
+       free(foreach_data);
+       fclose(file);
+
+       return CALENDAR_ERROR_NONE;
+}
old mode 100755 (executable)
new mode 100644 (file)
similarity index 52%
rename from src/cals-alarm.h
rename to common/cal_vcalendar.h
index 9eed91b..018ffe2
@@ -1,7 +1,7 @@
 /*
  * Calendar Service
  *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  *
  */
-#ifndef __CALENDAR_SVC_ALARM_H__
-#define __CALENDAR_SVC_ALARM_H__
 
-#include "cals-time.h"
+#ifndef __CALENDAR_SVC_VCALENDAR_H__
+#define __CALENDAR_SVC_VCALENDAR_H__
+
+#define _RECORD(i) _calendar_##i
 
 enum {
-       CALS_ALARM_REMOVE_BY_EVENT_ID,
-       CALS_ALARM_REMOVE_BY_CALENDAR_ID,
-       CALS_ALARM_REMOVE_BY_ACC_ID,
-       CALS_ALARM_REMOVE_ALL,
+       VCALENDAR_TYPE_VEVENT = 0x1,
+       VCALENDAR_TYPE_VTODO,
 };
-int cals_alarm_remove(int type, int related_id);
-int cals_alarm_add(int event_id, cal_alarm_info_t *alarm_info, struct cals_time *start_time);
-int cals_alarm_get_event_id(int alarm_id);
-int cals_get_alarm_info(const int event_id, GList **alarm_list);
-
 
-#endif /* __CALENDAR_SVC_ALARM_H__ */
+#endif // __CALENDAR_SVC_VCALENDAR_H__
diff --git a/common/cal_vcalendar_make.c b/common/cal_vcalendar_make.c
new file mode 100644 (file)
index 0000000..039ff17
--- /dev/null
@@ -0,0 +1,2126 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "calendar_list.h"
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_record.h"
+#include "cal_view.h"
+#include "cal_time.h"
+
+#include "cal_vcalendar.h"
+#include "cal_vcalendar_make.h"
+
+typedef enum
+{
+       EVENT_ATTENDEE_REQ_PARTICIPANT_ROLE=0,
+       EVENT_ATTENDEE_OPT_PARTICIPANT_ROLE,
+       EVENT_ATTENDEE_NON_PARTICIPANT_ROLE,
+       EVENT_ATTENDEE_CHAIR_ROLE,
+} cal_event_attendee_role_type_t;
+
+typedef enum
+{
+       EVENT_ATTENDEE_NEEDS_ACTION_AT_STATUS=0,
+       EVENT_ATTENDEE_ACCEPTED_AT_STATUS,
+       EVENT_ATTENDEE_DECLINED_AT_STATUS,
+       EVENT_ATTENDEE_TENTATIVE_AT_STATUS,
+       EVENT_ATTENDEE_DELEGATED_AT_STATUS,
+       EVENT_ATTENDEE_COMPLETED_AT_STATUS,
+       EVENT_ATTENDEE_IN_PROCESS_AT_STATUS
+} cal_event_attendee_status_type_t;
+
+
+static const char *_att_role[] = {
+       [EVENT_ATTENDEE_REQ_PARTICIPANT_ROLE] = "REQ-PARTICIPANT",
+       [EVENT_ATTENDEE_OPT_PARTICIPANT_ROLE] = "OPT-PARTICIPANT",
+       [EVENT_ATTENDEE_NON_PARTICIPANT_ROLE] = "NON-PARTICIPANT",
+       [EVENT_ATTENDEE_CHAIR_ROLE] = "CHAIR",
+};
+
+static const char *_att_st[] = {
+       [EVENT_ATTENDEE_NEEDS_ACTION_AT_STATUS] = "NEEDS-ACTION",
+       [EVENT_ATTENDEE_ACCEPTED_AT_STATUS] = "ACCEPTED",
+       [EVENT_ATTENDEE_DECLINED_AT_STATUS] = "DECLINED",
+       [EVENT_ATTENDEE_TENTATIVE_AT_STATUS] = "TENTATIVE",
+       [EVENT_ATTENDEE_DELEGATED_AT_STATUS] = "DELEGATED",
+       [EVENT_ATTENDEE_COMPLETED_AT_STATUS] = "COMPLETED",
+       [EVENT_ATTENDEE_IN_PROCESS_AT_STATUS] = "IN-PROCESS",
+};
+
+#define _strlen(s) (((s) && *(s)) ? strlen(s) : 0)
+
+static inline int __cal_vcalendar_make_alloc(cal_make_s *b, int n)
+{
+       b->data = realloc(b->data, b->size + n);
+
+       retvm_if(!b->data, CALENDAR_ERROR_OUT_OF_MEMORY, "Failed to realloc");
+       b->size += n;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+cal_make_s *_cal_vcalendar_make_new(void)
+{
+       cal_make_s *b;
+
+       b = calloc(1, sizeof(cal_make_s));
+       if (!b) {
+               return NULL;
+       }
+
+       b->data = calloc(1, sizeof(char));
+       if (!b->data) {
+               free(b);
+               return NULL;
+       }
+
+       *b->data = '\0';
+       b->size = 1;
+
+       return b;
+}
+
+static inline int __cal_vcalendar_make_folding(cal_make_s *b)
+{
+       int ret;
+       ret = __cal_vcalendar_make_alloc(b, _strlen(b->lbuf) + 3);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       strncat(b->data, b->lbuf, b->size - _strlen(b->data) - 1);
+       strncat(b->data, "\r\n ", b->size - _strlen(b->data) - 1);
+       *b->lbuf = '\0';
+       return CALENDAR_ERROR_NONE;
+}
+
+static inline int __cal_vcalendar_make_set_str(cal_make_s *b, const char *s)
+{
+       int remain_lbuf;
+       int remain_str;
+       int k;
+       int ret;
+
+       remain_lbuf = sizeof(b->lbuf) - _strlen(b->lbuf);
+       remain_str = _strlen(s);
+
+       k = 0;
+       while ( remain_lbuf - 1 < remain_str) {
+               strncat(b->lbuf, s + k, remain_lbuf - 1);
+               k += remain_lbuf - 1;
+               remain_str -= remain_lbuf - 1;
+               ret = __cal_vcalendar_make_folding(b);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+               remain_lbuf = sizeof(b->lbuf);
+       }
+
+       strncat(b->lbuf, s + k, remain_lbuf - 1);
+       return CALENDAR_ERROR_NONE;
+}
+
+static inline int __cal_vcalendar_make_flush(cal_make_s *b)
+{
+       int ret;
+       ret = __cal_vcalendar_make_alloc(b, _strlen(b->lbuf) + 2);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       strncat(b->data, b->lbuf, b->size - _strlen(b->data) - 1);
+       strncat(b->data, "\r\n", b->size - _strlen(b->data) - 1);
+       *b->lbuf = '\0';
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_make_printf(cal_make_s *b, const char *s1, const char *s2)
+{
+       int ret;
+
+       if (s1) {
+               ret = __cal_vcalendar_make_set_str(b, s1);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       }
+
+       if (s2) {
+               ret = __cal_vcalendar_make_set_str(b, s2);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       }
+
+       return __cal_vcalendar_make_flush(b);
+}
+
+char *_cal_vcalendar_make_get_data(cal_make_s *b)
+{
+       if (!b || !b->data)
+               return NULL;
+       return strdup(b->data);
+}
+
+void _cal_vcalendar_make_free(cal_make_s **b)
+{
+       if (!b || !*b)
+               return;
+
+       if ((*b)->data)
+               free((*b)->data);
+
+       free(*b);
+       b = NULL;
+}
+
+static void __get_str_utime(int version, const char *tzid, long long int lli, char *out_str, int str_size)
+{
+       retm_if (NULL == out_str, "Invalid parameter: out_str is NULL");
+
+       time_t tt = (time_t)lli;
+       struct tm st = {0};
+       gmtime_r(&tt, &st);
+
+       bool has_tzid = false;
+       if ((version != 1) && (tzid && *tzid)) {
+               has_tzid = true;
+       }
+
+       snprintf(out_str, str_size, "%s%s%s%s%04d%02d%02dT%02d%02d%02dZ",
+                       has_tzid == true ? ";" : ":",
+                       has_tzid == true ? "TZID=" : "",
+                       has_tzid == true ? tzid : "",
+                       has_tzid == true ? ":" : "",
+                       st.tm_year + 1900, st.tm_mon + 1, st.tm_mday, st.tm_hour, st.tm_min, st.tm_sec);
+       DBG("version(%d) tzid[%s] out_str[%s]", version, tzid, out_str);
+}
+
+static void __get_str_localtime(int version, int y, int m, int d, int h, int n, int s, char *out_str, int str_size)
+{
+       retm_if (NULL == out_str, "Invalid parameter: out_str is NULL");
+
+       bool is_ver1 = true;
+       if (version != 1) {
+               is_ver1 = false;
+       }
+
+       if (true == is_ver1) {
+               snprintf(out_str, str_size, ":%04d%02d%02dT%02d%02d%02d", y, m, d, h, n, s);
+
+       } else {
+               snprintf(out_str, str_size, ";VALUE=DATE-TIME:%04d%02d%02dT%02d%02d%02d", y, m, d, h, n, s);
+       }
+       DBG("version(%d) out_str[%s]", version, out_str);
+}
+
+static int __cal_vcalendar_make_time(int version, cal_make_s *b, char *tzid, calendar_time_s *caltime, const char *prop)
+{
+       retvm_if(caltime == NULL, -1, "Invalid argument: calendar_time_s is NULL");
+
+       if (caltime->time.utime == CALENDAR_TODO_NO_START_DATE)
+       {
+               DBG("No start date");
+               return CALENDAR_ERROR_NONE;
+       }
+
+       char buf[256] = {0};
+       switch (caltime->type)
+       {
+       case CALENDAR_TIME_UTIME:
+               __get_str_utime(version, tzid, caltime->time.utime, buf, sizeof(buf));
+               break;
+
+       case CALENDAR_TIME_LOCALTIME:
+               __get_str_localtime(version,
+                               caltime->time.date.year, caltime->time.date.month, caltime->time.date.mday,
+                               caltime->time.date.hour, caltime->time.date.minute, caltime->time.date.second,
+                               buf, sizeof(buf));
+               break;
+       }
+       __cal_vcalendar_make_printf(b, prop, buf);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_make_encode_string(char *p, char **q)
+{
+       if (NULL == p)
+       {
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       int i = 0;
+       int j = 0;
+       int len = strlen(p) + 128;
+
+       char *_q = NULL;
+       _q = calloc(len, sizeof(char));
+       if (NULL == _q)
+       {
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       while (p[i])
+       {
+               if (j >= len)
+               {
+                       len += 128;
+                       _q = realloc(_q, len);
+                       if (NULL == _q)
+                       {
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+
+               if ('\n' == p[i])
+               {
+                       _q[j] = '\\';
+                       _q[j + 1] = 'n';
+                       j++;
+               }
+               else if (';' == p[i])
+               {
+                       _q[j] = '\\';
+                       _q[j + 1] = ';';
+                       j++;
+               }
+               else if (',' == p[i])
+               {
+                       _q[j] = '\\';
+                       _q[j + 1] = ',';
+                       j++;
+               }
+               else if ('\\' == p[i])
+               {
+                       _q[j] = '\\';
+                       _q[j + 1] = '\\';
+                       j++;
+               }
+               else
+               {
+                       _q[j] = p[i];
+               }
+               i++;
+               j++;
+       }
+       *q = _q;
+       return CALENDAR_ERROR_NONE;
+}
+
+
+/////////////////////////////////////////////////////////////////////////////
+static inline int __cal_vcalendar_make_class(cal_make_s *b, int v)
+{
+       const char *c;
+       // TODO : Need to define enumeration of class property
+       switch(v) {
+       case 0:
+               c = "PUBLIC"; break;
+       case 1:
+               c = "PRIVATE"; break;
+       case 2:
+               c = "CONFIDENTIAL"; break;
+       default:
+               c = "PUBLIC"; break;
+       }
+       __cal_vcalendar_make_printf(b, "CLASS:", c);
+       return CALENDAR_ERROR_NONE;
+}
+
+static inline int __cal_vcalendar_make_transp(cal_make_s *b, int v)
+{
+       // TODO : Need to define enumeration of transp property
+       __cal_vcalendar_make_printf(b, "TRANSP:", v? "OPAQUE":"TRANSPARENT");
+       return CALENDAR_ERROR_NONE;
+}
+
+static inline int __cal_vcalendar_make_created(int version, cal_make_s *b, long long int t)
+{
+       retvm_if (t == 0, CALENDAR_ERROR_NONE, "created time is 0");
+
+       char buf[256] = {0};
+       __get_str_utime(2, NULL, t, buf, sizeof(buf));
+       __cal_vcalendar_make_printf(b, version == 1 ? "DCREATED" : "CREATED", buf);
+       return CALENDAR_ERROR_NONE;
+}
+
+static inline int __cal_vcalendar_make_last_mod(cal_make_s *b, long long int lli)
+{
+       char* tmp_tzid = NULL;
+       tmp_tzid = _cal_time_convert_ltos(NULL, lli, 0);
+       if (tmp_tzid)
+       {
+               __cal_vcalendar_make_printf(b, "LAST-MODIFIED:",tmp_tzid);
+               CAL_FREE(tmp_tzid);
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int __cal_vcalendar_make_organizer(cal_make_s *b, char *cn, char *address)
+{
+       int ret;
+
+       ret = __cal_vcalendar_make_set_str(b, "ORGANIZER");
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       if (cn && *cn)
+       {
+               ret = __cal_vcalendar_make_set_str(b, ";CN=");
+               ret = __cal_vcalendar_make_set_str(b, cn);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       }
+
+       if (address && *address)
+       {
+               ret = __cal_vcalendar_make_set_str(b, ":mailto:");
+               ret = __cal_vcalendar_make_set_str(b, address);
+       }
+       __cal_vcalendar_make_flush(b);
+       return CALENDAR_ERROR_NONE;
+}
+
+static inline int __cal_vcalendar_make_priority(int version, cal_make_s *b, int v)
+{
+       int prio = 0;
+       char tmp[2];
+
+       switch (v)
+       {
+       case CALENDAR_EVENT_PRIORITY_HIGH:
+               prio = version == 1 ? 2 : 3;    // in version 2.0, one out of 1 ~ 4.
+               break;
+       case CALENDAR_EVENT_PRIORITY_NORMAL:
+               prio = version == 1 ? 1 : 5;
+               break;
+       case CALENDAR_EVENT_PRIORITY_LOW:
+               prio = version == 1 ? 0 : 7; // in version 2, one out of 6 ~ 9.
+               break;
+       default:
+               prio = 0; // means none.
+               break;
+       }
+
+       snprintf(tmp, sizeof(tmp), "%d", prio);
+       __cal_vcalendar_make_printf(b, "PRIORITY:", tmp);
+       return CALENDAR_ERROR_NONE;
+}
+
+static inline void __cal_vcalendar_make_todo_status(int version, cal_make_s *b, int v)
+{
+       const char *c = NULL;
+       switch (v)
+       {
+       case CALENDAR_TODO_STATUS_NONE:
+               c = (1 == version) ? NULL : "NONE";
+               break;
+       case CALENDAR_TODO_STATUS_NEEDS_ACTION:
+               c = (1 == version) ? "NEEDS ACTION" : "NEEDS-ACTION";
+               break;
+       case CALENDAR_TODO_STATUS_COMPLETED:
+               c = "COMPLETED";
+               break;
+       case CALENDAR_TODO_STATUS_IN_PROCESS:
+               c = (1 == version) ? NULL : "IN-PROCESS";
+               break;
+       case CALENDAR_TODO_STATUS_CANCELED:
+               c = (1 == version) ? NULL : "CANCELLED";
+               break;
+       }
+       if (c) __cal_vcalendar_make_printf(b, "STATUS:", c);
+}
+
+int __cal_vcalendar_make_dtstamp(cal_make_s *b, char *tzid)
+{
+       char* tmp_tzid = NULL;
+       tmp_tzid = _cal_time_convert_ltos(tzid, _cal_time_get_now(), 0);
+       if (tmp_tzid)
+       {
+               __cal_vcalendar_make_printf(b, "DTSTAMP:", tmp_tzid);
+               CAL_FREE(tmp_tzid);
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static inline int __cal_vcalendar_make_exdate(cal_make_s *b, char *s)
+{
+       __cal_vcalendar_make_printf(b, "EXDATE:", s);
+       return CALENDAR_ERROR_NONE;
+}
+
+int __cal_vcalendar_make_attendee(cal_make_s *b, calendar_record_h attendee)
+{
+       int ret;
+
+       retvm_if(attendee == NULL, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid argument: attendee is NULL");
+
+       ret = __cal_vcalendar_make_set_str(b, "ATTENDEE");
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       int cutype = 0;
+       ret = calendar_record_get_int(attendee, _calendar_attendee.cutype, &cutype);
+       ret = __cal_vcalendar_make_set_str(b, ";CUTYPE=");
+       switch (cutype)
+       {
+       case CALENDAR_ATTENDEE_CUTYPE_INDIVIDUAL:
+               ret = __cal_vcalendar_make_set_str(b, "INDIVIDUAL");
+               break;
+       case CALENDAR_ATTENDEE_CUTYPE_GROUP:
+               ret = __cal_vcalendar_make_set_str(b, "GROUP");
+               break;
+       case CALENDAR_ATTENDEE_CUTYPE_RESOURCE:
+               ret = __cal_vcalendar_make_set_str(b, "RESOURCE");
+               break;
+       case CALENDAR_ATTENDEE_CUTYPE_ROOM:
+               ret = __cal_vcalendar_make_set_str(b, "ROOM");
+               break;
+       case CALENDAR_ATTENDEE_CUTYPE_UNKNOWN:
+               ret = __cal_vcalendar_make_set_str(b, "UNKNOWN");
+               break;
+       }
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       char *member = NULL;
+       ret = calendar_record_get_str_p(attendee, _calendar_attendee.member, &member);
+       if (member && *member) {
+               ret = __cal_vcalendar_make_set_str(b, ";MEMBER=");
+               ret = __cal_vcalendar_make_set_str(b, member);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       }
+
+       int role = 0;
+       ret = calendar_record_get_int(attendee, _calendar_attendee.role, &role);
+       {
+               ret = __cal_vcalendar_make_set_str(b, ";ROLE=");
+               ret = __cal_vcalendar_make_set_str(b, _att_role[role]);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       }
+
+       int status = 0;
+       ret = calendar_record_get_int(attendee, _calendar_attendee.status, &status);
+       {
+               ret = __cal_vcalendar_make_set_str(b, ";PARTSTAT=");
+               ret = __cal_vcalendar_make_set_str(b, _att_st[status]);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       }
+
+       int rsvp = 0;
+       ret = calendar_record_get_int(attendee, _calendar_attendee.rsvp, &rsvp);
+       {
+               ret = __cal_vcalendar_make_set_str(b, ";RSVP=");
+               ret = __cal_vcalendar_make_set_str(b, rsvp ? "TRUE" : "FALSE");
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       }
+
+       char *delegatee_uri = NULL;
+       ret = calendar_record_get_str_p(attendee, _calendar_attendee.delegatee_uri, &delegatee_uri);
+       if (delegatee_uri && *delegatee_uri)
+       {
+               ret = __cal_vcalendar_make_set_str(b, ";DELEGATED-TO=");
+               ret = __cal_vcalendar_make_set_str(b, delegatee_uri);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       }
+
+       char *delegator_uri = NULL;
+       ret = calendar_record_get_str_p(attendee, _calendar_attendee.delegator_uri, &delegator_uri);
+       if (delegator_uri && *delegator_uri)
+       {
+               ret = __cal_vcalendar_make_set_str(b, ";DELEGATED-FROM=");
+               ret = __cal_vcalendar_make_set_str(b, delegator_uri);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       }
+
+       // TODO : No 'sentby' member in cal_participant_info_t
+
+       char *name = NULL;
+       ret = calendar_record_get_str_p(attendee, _calendar_attendee.name, &name);
+       if (name && *name) {
+               ret = __cal_vcalendar_make_set_str(b, ";CN=");
+               ret = __cal_vcalendar_make_set_str(b, name);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       }
+
+       char *email = NULL;
+       ret = calendar_record_get_str_p(attendee, _calendar_attendee.email, &email);
+       if (email && *email)
+       {
+               ret = __cal_vcalendar_make_set_str(b, ":mailto:");
+               ret = __cal_vcalendar_make_set_str(b, email);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       }
+
+       __cal_vcalendar_make_flush(b);
+       return CALENDAR_ERROR_NONE;
+}
+
+static const char *vl_tick(calendar_alarm_time_unit_type_e unit, int tick)
+{
+       static char buf[32] = {0};
+
+       int i = 0;
+       if (tick > 0) {
+               *buf = '-';
+               i++;
+
+       } else {
+               tick = -tick;
+       }
+
+       switch (unit) {
+       case CALENDAR_ALARM_TIME_UNIT_WEEK:
+               snprintf(buf + i, sizeof(buf) - i, "P%dW", tick);
+               break;
+       case CALENDAR_ALARM_TIME_UNIT_DAY:
+               snprintf(buf + i, sizeof(buf) - i, "P%dD", tick);
+               break;
+       case CALENDAR_ALARM_TIME_UNIT_HOUR:
+               snprintf(buf + i, sizeof(buf) - i, "PT%dH", tick);
+               break;
+       case CALENDAR_ALARM_TIME_UNIT_MINUTE:
+               snprintf(buf + i, sizeof(buf) - i, "PT%dM", tick);
+               break;
+       default:
+               buf[0] = '\0';
+       }
+
+       return buf;
+}
+
+int __cal_vcalendar_make_audio(cal_make_s *b, calendar_record_h alarm)
+{
+       retvm_if (NULL == b, CALENDAR_ERROR_INVALID_PARAMETER, "b is NULL");
+       retvm_if (NULL == alarm, CALENDAR_ERROR_INVALID_PARAMETER, "alarm is NULL");
+
+       int ret = 0;
+       int unit = 0;
+       ret = calendar_record_get_int(alarm, _calendar_alarm.tick_unit, &unit);
+       retvm_if (CALENDAR_ERROR_NONE != ret, ret, "failed to get unit");
+
+       if (CALENDAR_ALARM_TIME_UNIT_SPECIFIC == unit) {
+               calendar_time_s at = {0};
+               ret = calendar_record_get_caltime(alarm, _calendar_alarm.alarm_time, &at);
+               warn_if (CALENDAR_ERROR_NONE != ret, "failed to get alarm_time");
+
+               if (CALENDAR_TIME_UTIME == at.type) {
+                       char *datetime = _cal_time_convert_ltos(NULL, at.time.utime, 0);
+                       __cal_vcalendar_make_printf(b, "TRIGGER;VALUE=DATE-TIME:", datetime);
+                       free(datetime);
+
+               } else {
+                       char datetime[32] = {0};
+                       snprintf(datetime, sizeof(datetime), "%04d%02d%02dT%02d%02d%02d",
+                                       at.time.date.year, at.time.date.month, at.time.date.mday,
+                                       at.time.date.hour, at.time.date.minute, at.time.date.second);
+                       __cal_vcalendar_make_printf(b, "TRIGGER;VALUE=DATE-TIME:", datetime);
+               }
+
+       } else {
+               int tick = 0;
+               ret = calendar_record_get_int(alarm, _calendar_alarm.tick, &tick);
+               warn_if (CALENDAR_ERROR_NONE != ret, "failed to get tick");
+
+               __cal_vcalendar_make_printf(b, "TRIGGER:", vl_tick(unit, tick));
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+/* alarm in ver1.0
+ * aalarm: runTime, snoozeTime, repeatCount, audioContent (AALARM;TYPE=WAVE;VALUE=URL:19960415T235959; ; ; file:///mmedia/taps.wav)
+ * dalarm: runTime, snoozeTime, repeatCount, displayString
+ * malarm: runTime, snoozeTime, repeatCount, addressString, noteString
+ * palarm: runTime, snoozeTime, repeatCount, procedureName
+ */
+int __cal_vcalendar_make_aalarm(cal_make_s *b, calendar_record_h record, calendar_record_h alarm)
+{
+       retvm_if (NULL == b, CALENDAR_ERROR_INVALID_PARAMETER, "b is NULL");
+       retvm_if (NULL == record, CALENDAR_ERROR_INVALID_PARAMETER, "record is NULL");
+       retvm_if (alarm == NULL, CALENDAR_ERROR_INVALID_PARAMETER, "alarm is NULL");
+
+       int ret = CALENDAR_ERROR_NONE;
+
+       // set alarm
+       int unit = 0;
+       ret = calendar_record_get_int(alarm, _calendar_alarm.tick_unit, &unit);
+       retvm_if (CALENDAR_ERROR_NONE != ret, ret, "failed to get unit");
+
+       char datetime[32] = {0};
+       if (CALENDAR_ALARM_TIME_UNIT_SPECIFIC == unit) {
+               calendar_time_s at = {0};
+               ret = calendar_record_get_caltime(alarm, _calendar_alarm.alarm_time, &at);
+               warn_if (CALENDAR_ERROR_NONE != ret, "failed to get alarm_time");
+
+               if (CALENDAR_TIME_UTIME == at.type) {
+                       char *buf = _cal_time_convert_ltos(NULL, at.time.utime, 0);
+                       snprintf(datetime, sizeof(datetime), "%s;;;", buf);
+                       free(buf);
+
+               } else {
+                       snprintf(datetime, sizeof(datetime), "%04d%02d%02dT%02d%02d%02d;;;",
+                                       at.time.date.year, at.time.date.month, at.time.date.mday,
+                                       at.time.date.hour, at.time.date.minute, at.time.date.second);
+               }
+
+       } else { // has tick, unit
+               int tick = 0;
+               ret = calendar_record_get_int(alarm, _calendar_alarm.tick, &tick);
+               retvm_if (CALENDAR_ERROR_NONE != ret, ret, "Failed to get tick");
+
+               char *uri = NULL;
+               ret = calendar_record_get_uri_p(record, &uri);
+               retvm_if (CALENDAR_ERROR_NONE != ret, ret, "calendar_record_get_uri_p() failed");
+
+               calendar_time_s st = {0};
+               if (!strncmp(uri, _calendar_event._uri, strlen(_calendar_event._uri))) {
+                       ret = calendar_record_get_caltime(record, _calendar_event.start_time, &st);
+                       retvm_if (CALENDAR_ERROR_NONE != ret, ret, "Failed to get start");
+
+               } else if (!strncmp(uri, _calendar_todo._uri, strlen(_calendar_todo._uri))) {
+                       ret = calendar_record_get_caltime(record, _calendar_todo.due_time, &st);
+                       retvm_if (CALENDAR_ERROR_NONE != ret, ret, "Failed to get due");
+               }
+
+               if (CALENDAR_TIME_UTIME == st.type) {
+                       long long int lli = st.time.utime - (tick * unit);
+                       char *buf = _cal_time_convert_ltos(NULL, lli, 0);
+                       snprintf(datetime, sizeof(datetime), "%s;;;", buf);
+                       free(buf);
+                       DBG("aalarm: [%s] = (%lld) - (tick(%d) * unit(%d))", datetime, st.time.utime, tick, unit);
+
+               } else {
+                       struct tm tm = {0};
+                       tm.tm_year = st.time.date.year - 1900;
+                       tm.tm_mon = st.time.date.month - 1;
+                       tm.tm_mday = st.time.date.mday;
+                       tm.tm_hour = st.time.date.hour;
+                       tm.tm_min = st.time.date.minute;
+                       tm.tm_sec = st.time.date.second;
+                       time_t tt = mktime(&tm);
+                       tt -= (tick * unit);
+                       localtime_r(&tt, &tm);
+
+                       snprintf(datetime, sizeof(datetime), "%04d%02d%02dT%02d%02d%02d",
+                                       tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+                                       tm.tm_hour, tm.tm_min, tm.tm_sec);
+
+                       DBG("aalarm: [%s]", datetime);
+               }
+       }
+       __cal_vcalendar_make_printf(b, "AALARM:", datetime);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int __cal_vcalendar_make_alarm(cal_make_s *b, calendar_record_h alarm)
+{
+       int ret;
+       retvm_if(alarm == NULL, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid argument: alarm is NULL");
+
+       // TODO : No action type is defined
+       ret = __cal_vcalendar_make_printf(b, "BEGIN:VALARM", NULL);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       ret = __cal_vcalendar_make_audio(b, alarm);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       int action = 0;
+       ret = calendar_record_get_int(alarm, _calendar_alarm.action, &action);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       switch (action)
+       {
+       default:
+       case CALENDAR_ALARM_ACTION_AUDIO:
+               ret = __cal_vcalendar_make_printf(b, "ACTION:", "AUDIO");
+               break;
+       case CALENDAR_ALARM_ACTION_DISPLAY:
+               ret = __cal_vcalendar_make_printf(b, "ACTION:", "DISPLAY");
+               break;
+       case CALENDAR_ALARM_ACTION_EMAIL:
+               ret = __cal_vcalendar_make_printf(b, "ACTION:", "EMAIL");
+               break;
+       }
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       char *summary = NULL;
+       ret = calendar_record_get_str_p(alarm, _calendar_alarm.summary, &summary);
+       if (summary && *summary) {
+               ret = __cal_vcalendar_make_printf(b, "SUMMARY:", summary);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       }
+
+       char *description = NULL;
+       ret = calendar_record_get_str_p(alarm, _calendar_alarm.description, &description);
+       if (description && *description) {
+               ret = __cal_vcalendar_make_printf(b, "DESCRIPTION:", description);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+       }
+
+       __cal_vcalendar_make_printf(b, "END:VALARM", NULL);
+       return CALENDAR_ERROR_NONE;
+}
+
+int __cal_vcalendar_make_rrule_append_mday(char *buf, int buf_len, char *mday)
+{
+       int i;
+       int num;
+       int length = 0;
+       char **t = NULL;
+       char *p = NULL;
+
+       if (NULL == buf || NULL == mday)
+       {
+               ERR("Invalid parameter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       t = g_strsplit_set(mday, " ,", -1);
+       if (!t) {
+               ERR("g_strsplit_set() is failed");
+               g_strfreev(t);
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       int len = strlen(buf);
+       length = g_strv_length(t);
+       for (i = 0; i < length; i++)
+       {
+               if (*t[i] == '\0') continue;
+
+               p = t[i];
+               num = atoi(p);
+               len += snprintf(buf +len, buf_len -len, "%d%s ", num, num > 0 ? "" : "-");
+       }
+       g_strfreev(t);
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_vcalendar_make_rrule_append_setpos(calendar_record_h record, char *buf, int buf_len)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char *bysetpos = NULL;
+
+       ret = calendar_record_get_str_p(record, _calendar_event.bysetpos, &bysetpos);
+       retm_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_int() failed(%d)", ret);
+
+       int blen = strlen(buf);
+       if (bysetpos && '\0' != bysetpos[0]) {
+               // in ver1.0, "3, 5, -4" -> "3+ 5+ 4-"
+               char **t = NULL;
+               t = g_strsplit_set(bysetpos, " ,", -1);
+
+               int len = g_strv_length(t);
+
+               int i;
+               for (i = 0; i < len; i++)
+               {
+                       if (*t[i] == '\0') continue;
+
+                       int setpos = atoi(t[i]);
+                       DBG("%d", setpos);
+
+                       if (setpos == 0) {
+                               DBG("Invalid setpos(0)");
+                               continue;
+                       }
+                       blen += snprintf(buf +blen, buf_len -blen, "%d%s ", setpos * (setpos < 0 ? -1 : 1), setpos < 0 ? "-" : "+");
+               }
+               g_strfreev(t);
+       } else {
+               // in ver2.0, 3TH should be changed to setpos:3, byday:TH
+               char *byday = NULL;
+               ret = calendar_record_get_str_p(record, _calendar_event.byday, &byday);
+               retm_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_int() failed(%d)", ret);
+               if (NULL == byday || '\0' == byday[0]) {
+                       blen += snprintf(buf +blen, buf_len -blen, "%s", "1+ ");
+                       return;
+               }
+
+               int len = strlen(byday);
+
+               int i = 0;
+               while (i < len && (byday[i] < '1' || byday[i] > '9'))
+                       i++;
+               if (i == len) {
+                       // byday: TH
+                       blen += snprintf(buf +blen, buf_len -blen, "%s", "1+ ");
+                       return;
+               }
+
+               int j = 0; // byday: 3TH
+               while ((i + j) <= len && (byday[i + j] >= '1' && byday[i + j] <= '9'))
+                       j++;
+
+               char num[32] = {0};
+               snprintf(num, j + 1, "%s", &byday[i]);
+               blen += snprintf(buf +blen, buf_len -blen, "%s+ ", num);
+       }
+}
+
+void __cal_vcalendar_make_rrule_append_text_wday(int rrule_type, char *buf, int buf_len, char *wday)
+{
+       ret_if(NULL == buf);
+
+       int i, j;
+       int length = 0;
+       char **t = NULL;
+       char *p = NULL;
+
+       t = g_strsplit_set(wday, " ,", -1);
+       if (!t) {
+               ERR("g_strsplit_set() is failed");
+               g_strfreev(t);
+               return;
+       }
+       int len = strlen(buf);
+       length = g_strv_length(t);
+       for (i = 0; i < length; i++) {
+               if (*t[i] == '\0') continue;
+
+               p = t[i];
+               while (*p == ' ') // del space
+                       p++;
+
+               // number pard
+               j = 0;
+               while (p[j] == '+' || p[j] == '-' || (p[j] >= '1' && p[j] <= '9'))
+                       j++;
+               len += snprintf(buf +len, buf_len - len, "%s ", p +j);
+       }
+       g_strfreev(t);
+       return;
+}
+
+void __cal_vcalendar_make_rrule_append_wkst(calendar_record_h record, char *buf, int buf_len)
+{
+       ret_if(NULL == buf);
+
+       const char wday[7][3] = {"SU", "MO", "TU", "WE", "TH", "FR", "SA"};
+       int wkst = CALENDAR_SUNDAY;
+       calendar_record_get_int(record, _calendar_event.wkst, &wkst);
+       DBG("wkst(%d) [%s]", wkst, wday[wkst - 1]);
+       int len = strlen(buf);
+       snprintf(buf +len, buf_len -len, "WKST=%s ", wday[wkst - 1]);
+}
+
+int __cal_vcalendar_make_rrule_append_wday(int rrule_type, char *buf, int buf_len, char *wday)
+{
+       int i, j;
+       int num = 0, num_past;
+       int length = 0;
+       char **t = NULL;
+       char *p = NULL;
+       char buf_temp[8] = {0};
+
+       num_past = 0;
+       t = g_strsplit_set(wday, " ,", -1);
+       if (!t) {
+               ERR("g_strsplit_set() is failed");
+               g_strfreev(t);
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       length = g_strv_length(t);
+       DBG("len(%d)", length);
+
+       int len = strlen(buf);
+       for (i = 0; i < length; i++) {
+               if (*t[i] == '\0')
+                       continue;
+
+               p = t[i];
+               j = 0; // get number
+               while (p[j] == '+' || p[j] == '-' || (p[j] >= '1' && p[j] <= '9'))
+                       j++;
+
+               if (j > 0) {
+                       if (CALENDAR_RECURRENCE_WEEKLY == rrule_type) {
+                               num_past = num;
+                       } else {
+                               if (*p == '-') {
+                                       snprintf(buf_temp, j + 1, "%s", p + 1);
+                                       num = atoi(buf_temp);
+                                       if (0 == i) {
+                                               num_past = num;
+                                               len += snprintf(buf +len, buf_len -len, "%s- ", buf_temp);
+                                       }
+                               } else {
+                                       snprintf(buf_temp, j + 1, "%s", p);
+                                       num = atoi(buf_temp);
+                                       if (0 == i)
+                                       {
+                                               num_past = num;
+                                               len += snprintf(buf +len, buf_len -len, "%s+ ", buf_temp);
+                                       }
+                               }
+                       }
+
+                       if (num_past == num) {
+                               len += snprintf(buf +len, sizeof(buf) -len, "%s ", p +j);
+                       } else {
+                               ERR("Out of 1.0 spec");
+                       }
+                       DBG("%d num(%d) val[%s]", i, num, p + j);
+               } else {
+                       len += snprintf(buf +len, sizeof(buf) -len, "%s ", p);
+               }
+               DBG("[%s]", buf);
+       }
+       g_strfreev(t);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int __cal_vcalendar_make_rrule_append_until(char *buf, int buf_len, calendar_record_h record)
+{
+       int ret;
+       int range_type = 0;
+       int count;
+       char *until_str = NULL;
+       char buf_range[256] = {0};
+       calendar_time_s caltime;
+
+       ret = calendar_record_get_int(record, _calendar_event.range_type, &range_type);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_record_get_int() failed");
+               return ret;
+       }
+
+       switch (range_type)
+       {
+       case CALENDAR_RANGE_COUNT:
+               ret = calendar_record_get_int(record, _calendar_event.count, &count);
+               if (CALENDAR_ERROR_NONE != ret)
+               {
+                       ERR("calendar_record_get_int() failed");
+                       return ret;
+               }
+               snprintf(buf_range, sizeof(buf_range), "#%d", count);
+               break;
+
+       case CALENDAR_RANGE_UNTIL:
+               memset(&caltime, 0x0, sizeof(calendar_time_s));
+
+               ret = calendar_record_get_caltime(record, _calendar_event.until_time, &caltime);
+               if (CALENDAR_ERROR_NONE != ret)
+               {
+                       ERR("calendar_record_get_caltime() failed");
+                       return ret;
+               }
+               switch (caltime.type)
+               {
+               case CALENDAR_TIME_UTIME:
+                       until_str = _cal_time_convert_ltos(NULL, caltime.time.utime, 0);
+                       snprintf(buf_range, sizeof(buf_range), "%s", until_str);
+                       CAL_FREE(until_str);
+                       break;
+
+               case CALENDAR_TIME_LOCALTIME:
+                       snprintf(buf_range, sizeof(buf_range), "%04d%02d%02dT%02d%02d%02d",
+                                       caltime.time.date.year, caltime.time.date.month, caltime.time.date.mday,
+                                       caltime.time.date.hour, caltime.time.date.minute, caltime.time.date.second);
+                       break;
+               }
+               break;
+
+       case CALENDAR_RANGE_NONE:
+               snprintf(buf_range, sizeof(buf_range), "#0");
+               break;
+       }
+       int len = strlen(buf);
+       snprintf(buf +len, buf_len -len, "%s", buf_range);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_make_rrule_ver1(cal_make_s *b, calendar_record_h record)
+{
+       int ret;
+       int freq;
+       int interval = 1;
+       char *byyearday = NULL;
+       char *bymonth = NULL;
+       char *bymonthday = NULL;
+       char *byday = NULL;
+       char buf[2048] = {0};
+
+       cal_record_s * rec = (cal_record_s *)record;
+       if (NULL == rec)
+       {
+               ERR("Invalid parameter: record is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = calendar_record_get_int(record, _calendar_event.freq, &freq);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_record_get_int() failed");
+               return ret;
+       }
+       ret = calendar_record_get_int(record, _calendar_event.interval, &interval);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_record_get_int() failed");
+               return ret;
+       }
+       ret = calendar_record_get_str_p(record, _calendar_event.byyearday, &byyearday);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_record_get_str_p() failed");
+               return ret;
+       }
+       ret = calendar_record_get_str_p(record, _calendar_event.bymonth, &bymonth);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_record_get_str_p() failed");
+               return ret;
+       }
+       ret = calendar_record_get_str_p(record, _calendar_event.byday, &byday);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_record_get_str_p() failed");
+               return ret;
+       }
+       ret = calendar_record_get_str_p(record, _calendar_event.bymonthday, &bymonthday);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_record_get_str_p() failed");
+               return ret;
+       }
+
+       interval = interval > 0 ? interval : 1;
+       int len = 0;
+       switch (freq)
+       {
+       case CALENDAR_RECURRENCE_YEARLY:
+               if (bymonth && *bymonth) {
+                       len = snprintf(buf, sizeof(buf), "YM%d ", interval);
+                       __cal_vcalendar_make_rrule_append_mday(buf, sizeof(buf), bymonth);
+
+                       if (byday && *byday) {
+                               // ex> YM1 6 MP1 1+ TH
+                               snprintf(buf +len, sizeof(buf)-len, "MP%d", interval);
+                               __cal_vcalendar_make_rrule_append_setpos(record, buf, sizeof(buf));
+                               __cal_vcalendar_make_rrule_append_text_wday(CALENDAR_RECURRENCE_MONTHLY, buf, sizeof(buf), byday);
+                               __cal_vcalendar_make_rrule_append_wkst(record, buf, sizeof(buf));
+                       } else if (bymonthday && *bymonthday) {
+                               // ex> YM1 2 MD 1
+                               snprintf(buf +len, sizeof(buf)-len, "MD%d", interval);
+                               __cal_vcalendar_make_rrule_append_mday(buf, sizeof(buf), bymonthday);
+                       } else {
+                               ERR("Out of scope");
+                       }
+               } else if (byyearday && *byyearday) {
+                       snprintf(buf, sizeof(buf), "YD%d ", interval);
+                       __cal_vcalendar_make_rrule_append_mday(buf, sizeof(buf), byyearday);
+               } else {
+                       ERR("Out of scope");
+               }
+               break;
+
+       case CALENDAR_RECURRENCE_MONTHLY:
+               if (byday && *byday)
+               {
+                       snprintf(buf, sizeof(buf), "MP%d ", interval);
+                       __cal_vcalendar_make_rrule_append_setpos(record, buf, sizeof(buf));
+                       __cal_vcalendar_make_rrule_append_text_wday(CALENDAR_RECURRENCE_MONTHLY, buf, sizeof(buf), byday);
+                       __cal_vcalendar_make_rrule_append_wkst(record, buf, sizeof(buf));
+               }
+               else if (bymonthday && *bymonthday)
+               {
+                       snprintf(buf, sizeof(buf), "MD%d ", interval);
+                       __cal_vcalendar_make_rrule_append_mday(buf, sizeof(buf), bymonthday);
+               }
+               else
+               {
+                       ERR("Invalid parameter");
+               }
+               break;
+
+       case CALENDAR_RECURRENCE_WEEKLY:
+               snprintf(buf, sizeof(buf), "W%d ", interval);
+               __cal_vcalendar_make_rrule_append_wday(CALENDAR_RECURRENCE_WEEKLY, buf, sizeof(buf), byday);
+               __cal_vcalendar_make_rrule_append_wkst(record, buf, sizeof(buf));
+               break;
+
+       case CALENDAR_RECURRENCE_DAILY:
+               snprintf(buf, sizeof(buf), "D%d ", interval);
+               break;
+
+       default:
+               break;
+       }
+
+       __cal_vcalendar_make_rrule_append_until(buf, sizeof(buf), record);
+
+       return __cal_vcalendar_make_printf(b, "RRULE:", buf);
+}
+
+static int __cal_vcalendar_make_rrule(cal_make_s *b, int freq, calendar_record_h record)
+{
+       int ret;
+       int num;
+       int len = 0;
+       char *text = NULL;
+       char buf[1024] = {0};
+       calendar_time_s caltime = {0};
+
+       switch (freq) {
+       case CALENDAR_RECURRENCE_DAILY:
+               len = snprintf(buf, sizeof(buf), "%s", "FREQ=DAILY");
+               break;
+       case CALENDAR_RECURRENCE_WEEKLY:
+               len = snprintf(buf, sizeof(buf), "%s", "FREQ=WEEKLY");
+               break;
+       case CALENDAR_RECURRENCE_MONTHLY:
+               len = snprintf(buf, sizeof(buf), "%s", "FREQ=MONTHLY");
+               break;
+       case CALENDAR_RECURRENCE_YEARLY:
+               len = snprintf(buf, sizeof(buf), "%s", "FREQ=YEARLY");
+               break;
+       default:
+               break;
+       }
+
+       ret = calendar_record_get_int(record, _calendar_event.interval, &num);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_int() Failed(%d)", ret);
+       len += snprintf(buf +len, sizeof(buf) -len, ";INTERVAL=%d", num);
+
+       ret = calendar_record_get_str_p(record, _calendar_event.bysecond, &text);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_str_p() Failed(%d)", ret);
+       if (text && *text) {
+               DBG("BYSECOND= [%s]", text);
+               len += snprintf(buf +len, sizeof(buf) -len, ";BYSECOND=%s", text);
+               text = NULL;
+       }
+
+       ret = calendar_record_get_str_p(record, _calendar_event.byminute, &text);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_str_p() Failed(%d)", ret);
+       if (text && *text) {
+               DBG("BYMINUTE= [%s]", text);
+               len += snprintf(buf +len, sizeof(buf) -len, ";BYMINUTE=%s", text);
+               text = NULL;
+       }
+
+       ret = calendar_record_get_str_p(record, _calendar_event.byhour, &text);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_str_p() Failed(%d)", ret);
+       if (text && *text) {
+               DBG("BYHOUR= [%s]", text);
+               len += snprintf(buf +len, sizeof(buf) -len, ";BYHOUR=%s", text);
+               text = NULL;
+       }
+
+       ret = calendar_record_get_str_p(record, _calendar_event.byday, &text);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_str_p() Failed(%d)", ret);
+       if (text && *text) {
+               DBG("BYDAY= [%s]", text);
+               len += snprintf(buf +len, sizeof(buf) -len, ";BYDAY=%s", text);
+               text = NULL;
+       }
+
+       ret = calendar_record_get_str_p(record, _calendar_event.bymonthday, &text);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_str_p() Failed(%d)", ret);
+       if (text && *text) {
+               DBG("BYMONTHDAY= [%s]", text);
+               len += snprintf(buf +len, sizeof(buf) -len, ";BYMONTHDAY=%s", text);
+               text = NULL;
+       }
+
+       ret = calendar_record_get_str_p(record, _calendar_event.byyearday, &text);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_str_p() Failed(%d)", ret);
+       if (text && *text) {
+               DBG("BYYEARDAY= [%s]", text);
+               len += snprintf(buf +len, sizeof(buf) -len, ";BYYEARDAY=%s", text);
+               text = NULL;
+       }
+
+       ret = calendar_record_get_str_p(record, _calendar_event.byweekno, &text);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_str_p() Failed(%d)", ret);
+       if (text && *text) {
+               DBG("BYWEEKNO= [%s]", text);
+               len += snprintf(buf +len, sizeof(buf) -len, ";BYWEEKNO=%s", text);
+               text = NULL;
+       }
+
+       ret = calendar_record_get_str_p(record, _calendar_event.bymonth, &text);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_str_p() Failed(%d)", ret);
+       if (text && *text) {
+               DBG("BYMONTH= [%s]", text);
+               len += snprintf(buf +len, sizeof(buf) -len, ";BYMONTH=%s", text);
+               text = NULL;
+       }
+
+       ret = calendar_record_get_str_p(record, _calendar_event.bysetpos, &text);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_str_p() Failed(%d)", ret);
+       if (text && *text) {
+               DBG("BYSETPOS= [%s]", text);
+               len += snprintf(buf +len, sizeof(buf) -len, ";BYSETPOS=%s", text);
+               text = NULL;
+       }
+
+       num = CALENDAR_SUNDAY; // default set
+       ret = calendar_record_get_int(record, _calendar_event.wkst, &num);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_int() Failed(%d)", ret);
+       const char *wday_str[7] = {"SU", "MO", "TU", "WE", "TH", "FR", "SA"};
+       len += snprintf(buf +len, sizeof(buf) -len, ";WKST=%s", wday_str[num-1]);
+
+       // until
+       ret = calendar_record_get_int(record, _calendar_event.range_type, &num);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_int() Failed(%d)", ret);
+       switch (num) {
+       case CALENDAR_RANGE_COUNT:
+               ret = calendar_record_get_int(record, _calendar_event.count, &num);
+               warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_int() Failed(%d)", ret);
+               len += snprintf(buf +len, sizeof(buf) -len, ";COUNT=%d", num);
+               break;
+
+       case CALENDAR_RANGE_UNTIL:
+               ret = calendar_record_get_caltime(record, _calendar_event.until_time, &caltime);
+               warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Failed(%d)", ret);
+
+               if (caltime.type == CALENDAR_TIME_UTIME) {
+                       char *tmp_tzid = NULL;
+                       tmp_tzid = _cal_time_convert_ltos(NULL, caltime.time.utime, 0);
+                       if (NULL == tmp_tzid)
+                               break;
+                       len += snprintf(buf +len, sizeof(buf) -len, ";UNTIL=%s", tmp_tzid);
+                       CAL_FREE(tmp_tzid);
+               } else {
+                       len += snprintf(buf +len, sizeof(buf) -len, ";UNTIL=%04d%02d%02dT%02d%02d%02dZ",
+                                       caltime.time.date.year, caltime.time.date.month, caltime.time.date.mday,
+                                       caltime.time.date.hour, caltime.time.date.minute, caltime.time.date.second);
+               }
+               break;
+
+       case CALENDAR_RANGE_NONE:
+               break;
+       default:
+               break;
+       }
+       return __cal_vcalendar_make_printf(b, "RRULE:", buf);
+}
+/////////////////////////////////////////////////////////////////////////////
+
+static int __cal_vcalendar_make_child_extended(cal_make_s *b, calendar_record_h child, bool *has_lunar)
+{
+       int ret;
+       char *key = NULL;
+       char *value = NULL;
+       if (NULL == child)
+       {
+               ERR("Invalid argument: child is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = calendar_record_get_str_p(child, _calendar_extended_property.key, &key);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_record_get_str_p() failed");
+               return ret;
+       }
+       if (NULL == key || strncmp(key, "X-", strlen("X-")))
+       {
+               DBG("Not extended for vcalendar[%s]", key);
+               return CALENDAR_ERROR_NONE;
+       }
+
+       ret = calendar_record_get_str_p(child, _calendar_extended_property.value, &value);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_record_get_str_p() failed");
+               return ret;
+       }
+
+       // check lunar: will handle next
+       if (has_lunar) {
+               if ((!strncmp(key, "X-LUNAR", strlen("X-LUNAR")) && !strncmp(value, ":SET", strlen(":SET"))) ||
+                               (!strncmp(key, "X-LUNAR:", strlen("X-LUNAR:")) && !strncmp(value, "SET", strlen("SET")))) {
+                       *has_lunar = true;
+                       return CALENDAR_ERROR_NONE;
+               }
+       }
+
+       ret = __cal_vcalendar_make_printf(b, key, value);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("__cal_vcalendar_make_printf() failed");
+               return ret;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int __cal_vcalendar_make_printf_str_p(calendar_record_h record, unsigned int property_id, cal_make_s *b, const char *property_str)
+{
+       int ret;
+       char *strval = NULL;
+
+       ret = calendar_record_get_str_p(record, property_id, &strval);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_record_get_str_p() failed(ret:%d): categories", ret);
+               return ret;
+       }
+       if (strval && (strlen(strval) > 0))
+       {
+               char *encoded = NULL;
+               if (_calendar_event.summary == property_id
+                               || _calendar_event.description == property_id
+                               || _calendar_event.location == property_id
+                               || _calendar_todo.summary == property_id
+                               || _calendar_todo.description == property_id
+                               || _calendar_todo.location == property_id)
+               {
+                       __cal_vcalendar_make_encode_string(strval, &encoded);
+                       if (encoded)
+                       {
+                               ret = __cal_vcalendar_make_printf(b, property_str, encoded);
+                               free(encoded);
+                               if (CALENDAR_ERROR_NONE != ret)
+                               {
+                                       ERR("__cal_vcalendar_make_printf() failed(ret:%d)", ret);
+                                       return ret;
+                               }
+                       }
+               }
+               else
+               {
+                       ret = __cal_vcalendar_make_printf(b, property_str, strval);
+                       if (CALENDAR_ERROR_NONE != ret)
+                       {
+                               ERR("__cal_vcalendar_make_printf() failed(ret:%d)", ret);
+                               return ret;
+                       }
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int __cal_vcalendar_make_event(int version, cal_make_s *b, calendar_record_h record)
+{
+       int i;
+       int ret;
+
+       ret = __cal_vcalendar_make_printf(b, "BEGIN:VEVENT", NULL);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       // sensitivity
+       int sensitivity = 0;
+       ret = calendar_record_get_int(record, _calendar_event.sensitivity, &sensitivity);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get sensitivity(%d)", ret);
+
+       ret = __cal_vcalendar_make_class(b, sensitivity);
+       warn_if(CALENDAR_ERROR_NONE != ret, "__cal_vcalendar_make_class() is failed");
+
+       // busy_status
+       int busy_status = 0;
+       ret = calendar_record_get_int(record, _calendar_event.busy_status, &busy_status);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get busy_status(%d)", ret);
+
+       ret = __cal_vcalendar_make_transp(b, busy_status);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       // summary
+       __cal_vcalendar_make_printf_str_p(record, _calendar_event.summary, b, "SUMMARY:");
+
+       // start tzid
+       char *tzid = NULL;
+       ret = calendar_record_get_str_p(record, _calendar_event.start_tzid, &tzid);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_str_p() is failed(%d)", ret);
+
+       // dtstart_type
+       calendar_time_s dtstart = {0};
+       ret = calendar_record_get_caltime(record, _calendar_event.start_time, &dtstart);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() is failed(%d)", ret);
+
+       ret = __cal_vcalendar_make_time(version, b, tzid, &dtstart, "DTSTART");
+       warn_if(CALENDAR_ERROR_NONE != ret, "__cal_vcalendar_make_time() is failed(%d)", ret);
+
+       // dtend
+       calendar_time_s dtend = {0};
+       ret = calendar_record_get_caltime(record, _calendar_event.end_time, &dtend);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get end_time(%d)", ret);
+
+       ret = __cal_vcalendar_make_time(version, b, tzid, &dtend, "DTEND");
+       warn_if(CALENDAR_ERROR_NONE != ret, "__cal_vcalendar_make_time() is failed(%d)", ret);
+
+       // created_time
+       long long int created = 0;
+       ret = calendar_record_get_lli(record, _calendar_event.created_time, &created);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get created_time(%d)", ret);
+
+       ret = __cal_vcalendar_make_created(version, b, created);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       // description
+       __cal_vcalendar_make_printf_str_p(record, _calendar_event.description, b, "DESCRIPTION:");
+
+       // rrule
+       int freq = 0;
+       ret = calendar_record_get_int(record, _calendar_event.freq, &freq);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get last_modified_time(%d)", ret);
+       if (freq) {
+               switch (version)
+               {
+               case 1:
+                       __cal_vcalendar_make_rrule_ver1(b, record);
+                       break;
+
+               default:
+                       __cal_vcalendar_make_rrule(b, freq, record);
+               }
+       }
+
+       // last_mod
+       /* keis want to skip for there potential error.
+               ret = calendar_record_get_lli(record, _calendar_event.last_modified_time, &llival);
+               retvm_if(CALENDAR_ERROR_NONE != ret, -1,
+               "Failed to get last_modified_time(%d)", ret);
+
+               ret = __cal_vcalendar_make_last_mod(b, llival);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+        */
+       // location
+       __cal_vcalendar_make_printf_str_p(record, _calendar_event.location, b, "LOCATION:");
+
+       // organizer email
+       if (version != 1) {
+               char *organizer_name = NULL;
+               ret = calendar_record_get_str_p(record, _calendar_event.organizer_name, &organizer_name);
+               warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get organizer_name(%d)", ret);
+
+               char *organizer_email = NULL;
+               ret = calendar_record_get_str_p(record, _calendar_event.organizer_email, &organizer_email);
+               warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get organizer_email(%d)", ret);
+
+               if (organizer_email) {
+                       ret = __cal_vcalendar_make_organizer(b, organizer_name, organizer_email);
+                       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+               } else {
+                       DBG("No organizer name or email");
+               }
+       }
+
+       // priority
+       int priority = 0;
+       ret = calendar_record_get_int(record, _calendar_event.priority, &priority);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get priority(%d)", ret);
+
+       ret = __cal_vcalendar_make_priority(version, b, priority);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       // TODO : seq
+
+       // dtstamp
+       /* keis want to skip for there potential error.
+               ret = __cal_vcalendar_make_dtstamp(b, tzid);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+        */
+
+       // categories
+       __cal_vcalendar_make_printf_str_p(record, _calendar_event.categories, b, "CATEGORIES:");
+
+       // uid
+       __cal_vcalendar_make_printf_str_p(record, _calendar_event.uid, b, "UID:");
+
+       // exdate
+       __cal_vcalendar_make_printf_str_p(record, _calendar_event.exdate, b, "EXDATE:");
+
+       unsigned int count;
+       calendar_record_h child = NULL;
+
+       // attendee
+       count = 0;
+       ret = calendar_record_get_child_record_count(record, _calendar_event.calendar_attendee, &count);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child count(%d)", ret);
+
+       for (i = 0; i < count; i++)
+       {
+               ret = calendar_record_get_child_record_at_p(record, _calendar_event.calendar_attendee, i, &child);
+               warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child attendee(%d)", ret);
+
+               ret = __cal_vcalendar_make_attendee(b, child);
+               warn_if(CALENDAR_ERROR_NONE != ret, "Failed to make attendee(%d)", ret);
+       }
+       if (count <= 0)
+       {
+               DBG("No attendee");
+       }
+
+       // alarm
+       count = 0;
+       switch (version)
+       {
+       case 1:
+               // In ver 1.0, only first alarm will be dealt with.
+               ret = calendar_record_get_child_record_count(record, _calendar_event.calendar_alarm, &count);
+               warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child count(%d)", ret);
+               for (i = 0; i < count; i++)
+               {
+                       ret = calendar_record_get_child_record_at_p(record, _calendar_event.calendar_alarm, i, &child);
+                       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child alarm(%d)", ret);
+
+                       ret = __cal_vcalendar_make_aalarm(b, record, child);
+                       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+               }
+               if (count <= 0)
+               {
+                       DBG("No alarm in ver1.0");
+               }
+               break;
+
+       default:
+               ret = calendar_record_get_child_record_count(record, _calendar_event.calendar_alarm, &count);
+               warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child count(%d)", ret);
+
+               for (i = 0; i < count; i++)
+               {
+                       ret = calendar_record_get_child_record_at_p(record, _calendar_event.calendar_alarm, i, &child);
+                       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child alarm(%d)", ret);
+
+                       ret = __cal_vcalendar_make_alarm(b, child);
+                       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to make alarm(%d)", ret);
+               }
+               if (count <= 0)
+               {
+                       DBG("No alarm in ver2.0");
+               }
+       }
+
+       // extended
+       bool has_lunar = false;
+       count = 0;
+       ret = calendar_record_get_child_record_count(record, _calendar_event.extended, &count);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child count(%d)", ret);
+
+       for (i = 0; i < count; i++)
+       {
+               ret = calendar_record_get_child_record_at_p(record, _calendar_event.extended, i, &child);
+               warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child alarm(%d)", ret);
+
+               ret = __cal_vcalendar_make_child_extended(b, child, &has_lunar);
+               warn_if(CALENDAR_ERROR_NONE != ret, "Failed to make extended(%d)", ret);
+       }
+       if (count <= 0)
+       {
+               DBG("No extended");
+       }
+
+       // lunar
+       int calendar_system_type = 0;
+       ret = calendar_record_get_int(record, _calendar_event.calendar_system_type, &calendar_system_type);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get calendar_record_type(%d)", ret);
+
+       if (true == has_lunar || CALENDAR_SYSTEM_EAST_ASIAN_LUNISOLAR == calendar_system_type) {
+               __cal_vcalendar_make_printf(b, "X-LUNAR:SET", NULL);
+       }
+
+       return __cal_vcalendar_make_printf(b, "END:VEVENT", NULL);
+}
+
+int __cal_vcalendar_make_todo(int version, cal_make_s *b, calendar_record_h record)
+{
+       int ret;
+
+       //_cal_db_rrule_fill_record(record);
+
+       ret = __cal_vcalendar_make_printf(b, "BEGIN:VTODO", NULL);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       // sensitivity
+       int sensitivity = 0;
+       ret = calendar_record_get_int(record, _calendar_todo.sensitivity, &sensitivity);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get sensitivity(%d)", ret);
+
+       ret = __cal_vcalendar_make_class(b, sensitivity);
+       warn_if(CALENDAR_ERROR_NONE != ret, "__cal_vcalendar_make_class() is failed");
+
+       // summary
+       __cal_vcalendar_make_printf_str_p(record, _calendar_todo.summary, b, "SUMMARY:");
+
+       // due tzid
+       char *tzid = NULL;
+       ret = calendar_record_get_str_p(record, _calendar_todo.due_tzid, &tzid);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_str_p() is failed(%d)", ret);
+
+       // dtstart_type
+       calendar_time_s dtstart = {0};
+       ret = calendar_record_get_caltime(record, _calendar_todo.start_time, &dtstart);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() is failed(%d)", ret);
+
+       DBG("dtstart");
+       ret = __cal_vcalendar_make_time(version, b, tzid, &dtstart, "DTSTART");
+       warn_if(CALENDAR_ERROR_NONE != ret, "__cal_vcalendar_make_time() is failed(%d)", ret);
+
+       // dtend
+       calendar_time_s due = {0};
+       ret = calendar_record_get_caltime(record, _calendar_todo.due_time, &due);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get due_time(%d)", ret);
+
+       ret = __cal_vcalendar_make_time(version, b, tzid, &due, "DUE");
+       warn_if(CALENDAR_ERROR_NONE != ret, "__cal_vcalendar_make_time() failed(%d)", ret);
+
+       // created_time
+       long long int created = 0;
+       ret = calendar_record_get_lli(record, _calendar_todo.created_time, &created);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get created_time(%d)", ret);
+
+       ret = __cal_vcalendar_make_created(version, b, created);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       // description
+       __cal_vcalendar_make_printf_str_p(record, _calendar_todo.description, b, "DESCRIPTION:");
+
+
+       // TODO : geo
+
+       // last_mod
+       /* keis want to skip for there potential error.
+               ret = calendar_record_get_lli(record, _calendar_todo.last_modified_time, &llival);
+               warn_if(CALENDAR_ERROR_NONE != ret, -1,
+               "Failed to get last_modified_time(%d)", ret);
+
+               ret = __cal_vcalendar_make_last_mod(b, llival);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+        */
+
+       // location
+       __cal_vcalendar_make_printf_str_p(record, _calendar_todo.location, b, "LOCATION:");
+
+       // priority
+       int priority = 0;
+       ret = calendar_record_get_int(record, _calendar_todo.priority, &priority);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get priority(%d)", ret);
+
+       DBG("priority(%d)", priority);
+       ret = __cal_vcalendar_make_priority(version, b, priority);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       // status
+       int status = 0;
+       ret = calendar_record_get_int(record, _calendar_todo.todo_status, &status);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get status(%d)", ret);
+
+       __cal_vcalendar_make_todo_status(version, b, status);
+
+       // completed time: must be located below "todo status".
+       if (CALENDAR_TODO_STATUS_COMPLETED == status) {
+               long long int completed_time = 0;
+               ret = calendar_record_get_lli(record, _calendar_todo.completed_time, &completed_time);
+               warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get completed_time(%d)", ret);
+
+               if (completed_time != 0) {
+                       char buf[256] = {0};
+                       __get_str_utime(2, NULL, completed_time, buf, sizeof(buf));
+                       __cal_vcalendar_make_printf(b, "COMPLETED", buf);
+               }
+       }
+
+       // TODO : seq
+
+       // dtstamp
+       /* keis want to skip for there potential error.
+               ret = __cal_vcalendar_make_dtstamp(b, tzid);
+               retv_if(CALENDAR_ERROR_NONE != ret, ret);
+        */
+
+       // categories
+       __cal_vcalendar_make_printf_str_p(record, _calendar_todo.categories, b, "CATEGORIES:");
+
+       // uid
+       __cal_vcalendar_make_printf_str_p(record, _calendar_todo.uid, b, "UID:");
+
+       // alarm
+       int i;
+       unsigned int count;
+       calendar_record_h child = NULL;
+
+       switch (version)
+       {
+       case 1:
+               // In ver 1.0, only first alarm will be dealt with.
+               ret = calendar_record_get_child_record_count(record, _calendar_todo.calendar_alarm, &count);
+               warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child count(%d)", ret);
+
+               for (i = 0; i < count; i++)
+               {
+                       ret = calendar_record_get_child_record_at_p(record, _calendar_todo.calendar_alarm, i, &child);
+                       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child alarm(%d)", ret);
+
+                       ret = __cal_vcalendar_make_aalarm(b, record, child);
+                       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+               }
+               if (count <= 0)
+               {
+                       DBG("No alarm in ver1.0");
+               }
+               break;
+
+       default:
+               ret = calendar_record_get_child_record_count(record, _calendar_todo.calendar_alarm, &count);
+               warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child count(%d)", ret);
+
+               for (i = 0; i < count; i++)
+               {
+                       ret = calendar_record_get_child_record_at_p(record, _calendar_todo.calendar_alarm, i, &child);
+                       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child alarm(%d)", ret);
+
+                       ret = __cal_vcalendar_make_alarm(b, child);
+                       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+               }
+               if (count <= 0)
+               {
+                       DBG("No alarm in ver2.0");
+               }
+       }
+
+       // extended
+       count = 0;
+       ret = calendar_record_get_child_record_count(record, _calendar_todo.extended, &count);
+       warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child count(%d)", ret);
+
+       for (i = 0; i < count; i++)
+       {
+               ret = calendar_record_get_child_record_at_p(record, _calendar_todo.extended, i, &child);
+               warn_if(CALENDAR_ERROR_NONE != ret, "Failed to get child alarm(%d)", ret);
+
+               ret = __cal_vcalendar_make_child_extended(b, child, NULL);
+               warn_if(CALENDAR_ERROR_NONE != ret, "Failed to make extended(%d)", ret);
+       }
+       if (count <= 0)
+       {
+               DBG("No extended");
+       }
+
+       return __cal_vcalendar_make_printf(b, "END:VTODO", NULL);
+}
+
+int __cal_vcalendar_make_parent_extended(cal_make_s *b, calendar_list_h list, int *has_extended, int *version)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       GList *l = NULL;
+       cal_list_s *cal_list = (cal_list_s *)list;
+
+       if (NULL == list)
+       {
+               ERR("Invalid parameter: list is NULL");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       l = g_list_first(cal_list->record);
+       while (l)
+       {
+               char *uri = NULL;
+               calendar_record_h record = (calendar_record_h)l->data;
+               calendar_record_get_uri_p(record, &uri);
+               if (strncmp(uri, _calendar_extended_property._uri, strlen(_calendar_extended_property._uri)))
+               {
+                       l = g_list_next(l);
+                       continue;
+               }
+
+               *has_extended = 1;
+               cal_extended_s *extended = (cal_extended_s *)record;
+               if (NULL == extended)
+               {
+                       ERR("extended is NULL");
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+               ret = __cal_vcalendar_make_printf(b, extended->key, extended->value);
+               warn_if(CALENDAR_ERROR_NONE != ret, "__cal_vcalendar_make_printf() Failed(%d)", ret);
+               DBG("extended key[%s] value[%s]", extended->key, extended->value);
+               if (!strncmp(extended->key, "VERSION", strlen("VERSION")))
+               {
+                       if (strstr(extended->value, "1.0"))
+                       {
+                               *version = 1;
+                       }
+                       else
+                       {
+                               *version = 2;
+                       }
+
+                       DBG("version (%s)", extended->value);
+                       break;
+               }
+               l = g_list_next(l);
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+char *__get_tzid(calendar_record_h record, int property_tzid)
+{
+       int ret = 0;
+       char *tzid = NULL;
+
+       ret = calendar_record_get_str_p(record, property_tzid, &tzid);
+       retvm_if(CALENDAR_ERROR_NONE != ret, NULL, "Failed to get tzid(%d)", ret);
+       return tzid;
+}
+
+void __append_head(cal_make_s *b)
+{
+       int ret = 0;
+
+       ret = __cal_vcalendar_make_printf(b, "BEGIN", ":VCALENDAR");
+       retm_if(CALENDAR_ERROR_NONE != ret, "__cal_vcalendar_make_printf() is failed(%d)", ret);
+
+       ret = __cal_vcalendar_make_printf(b, "PRODID:vCal ID Default", NULL);
+       retm_if(CALENDAR_ERROR_NONE != ret, "__cal_vcalendar_make_printf() is failed(%d)", ret);
+}
+
+void __append_tail(cal_make_s *b)
+{
+       int ret = 0;
+
+       ret = __cal_vcalendar_make_printf(b, "END", ":VCALENDAR");
+       retm_if(CALENDAR_ERROR_NONE != ret, "__cal_vcalendar_make_printf() is failed(%d)", ret);
+}
+
+void __append_version(cal_make_s *b, int version)
+{
+       int ret = 0;
+       char buf[32] = {0};
+
+       snprintf(buf, sizeof(buf), ":%d.0", version);
+       ret = __cal_vcalendar_make_printf(b, "VERSION", buf);
+       retm_if(CALENDAR_ERROR_NONE != ret, "__cal_vcalendar_make_printf() is failed(%d)", ret);
+}
+
+void __append_tz(cal_make_s *b, calendar_record_h record, int property_tzid, int property_created)
+{
+       int ret = 0;
+
+       char *tzid = NULL;
+       ret = calendar_record_get_str_p(record, property_tzid, &tzid);
+       retm_if(CALENDAR_ERROR_NONE != ret, "Failed to get tzid(%d)", ret);
+
+       long long int created = 0;
+       ret = calendar_record_get_lli(record, property_created, &created);
+       retm_if(CALENDAR_ERROR_NONE != ret, "Failed to get created time(%d)", ret);
+
+       time_t zone = 0;
+       time_t dst = 0;
+       _cal_time_get_tz_offset(tzid, &zone, &dst);
+       DBG("offset zone(%ld), dst (%ld)", zone, dst);
+
+       bool in_dst = _cal_time_in_dst(tzid, created);
+       dst = in_dst ? dst : 0; // dst in TZ is depending on created time.
+       DBG("tzid[%s] created time(%lld) in_dst(%d)", tzid, created, in_dst);
+
+       int h = (zone / 3600) + (dst / 3600);
+       int m = (zone % 3600) / 60 + (dst % 3600) / 60;
+
+       char buf[32] = {0};
+       snprintf(buf, sizeof(buf), ":%s%02d:%02d",
+                       h == 0 ? "" : (h < 0 ? "-" : "+"),
+                       h < 0 ? (-1 * h) : h, m < 0 ? (-1 * m) : m);
+
+       ret = __cal_vcalendar_make_printf(b, "TZ", buf);
+       retm_if(CALENDAR_ERROR_NONE != ret, "__cal_vcalendar_make_printf() is failed");
+       DBG("append tzid[%s]", buf);
+}
+
+static int __make_vcalendar_ver1(cal_make_s *b, calendar_list_h list)
+{
+       retvm_if (NULL == list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid paramter:list is NULL");
+
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_record_h record = NULL;
+
+       int version = 1;
+       __append_head(b);
+       __append_version(b, version);
+
+       // start
+       char *tzid_old = NULL;
+       char *tzid_new = NULL;
+
+       ret = calendar_list_first(list);
+       retvm_if (CALENDAR_ERROR_NONE != ret, ret, "calendar_list_first() Failed");
+       do {
+               ret = calendar_list_get_current_record_p(list, &record);
+               if (CALENDAR_ERROR_NONE != ret) break;
+
+               // start vcalendar
+               char *uri = NULL;
+               ret = calendar_record_get_uri_p(record, &uri);
+               DBG("uri[%s]", uri);
+
+               if (!strcmp(uri, CALENDAR_VIEW_EVENT)) {
+                       tzid_new = __get_tzid(record, _calendar_event.start_tzid);
+                       if (tzid_new) {
+                               if (NULL == tzid_old) {
+                                       DBG("tzid old is NULL");
+                                       __append_tz(b, record, _calendar_event.start_tzid, _calendar_event.created_time);
+
+                               } else if (strcmp(tzid_old, tzid_new)) { // has different tzid
+                                       DBG("tzid_old [%s] tzid_new[%s]", tzid_old, tzid_new);
+                                       __append_tail(b);
+                                       __append_head(b);
+                                       __append_version(b, version);
+                                       __append_tz(b, record, _calendar_event.start_tzid, _calendar_event.created_time);
+
+                               } else {
+                                       DBG("else");
+                               }
+                               tzid_old = tzid_new;
+                       }
+                       ret = __cal_vcalendar_make_event(version, b, record);
+                       if (CALENDAR_ERROR_NONE != ret)
+                               break;
+
+               } else if (!strcmp(uri, CALENDAR_VIEW_TODO)) {
+                       tzid_new = __get_tzid(record, _calendar_todo.due_tzid);
+                       if (tzid_new) {
+                               if (NULL == tzid_old) {
+                                       DBG("tzid old is NULL");
+                                       __append_tz(b, record, _calendar_todo.due_tzid, _calendar_todo.created_time);
+
+                               } else if (strcmp(tzid_old, tzid_new)) { // has different tzid
+                                       DBG("tzid_old [%s] tzid_new[%s]", tzid_old, tzid_new);
+                                       __append_tail(b);
+                                       __append_head(b);
+                                       __append_version(b, version);
+                                       __append_tz(b, record, _calendar_todo.due_tzid, _calendar_todo.created_time);
+
+                               } else {
+                                       DBG("else");
+                               }
+                               tzid_old = tzid_new;
+                       }
+                       ret = __cal_vcalendar_make_todo(version, b, record);
+                       if (CALENDAR_ERROR_NONE != ret)
+                               break;
+
+               } else if (!strcmp(uri, CALENDAR_VIEW_EXTENDED)) {
+                       cal_extended_s *extended = (cal_extended_s *)record;
+                       if (!strncmp(extended->key, "VERSION", strlen("VERSION"))) continue;
+
+                       ret = __cal_vcalendar_make_printf(b, extended->key, extended->value);
+                       if (CALENDAR_ERROR_NONE != ret) break;
+
+                       DBG("extended key[%s] value[%s]", extended->key, extended->value);
+
+               } else if (!strcmp(uri, CALENDAR_VIEW_TIMEZONE)) {
+                       DBG("Not support timezone");
+
+               } else if (!strcmp(uri, CALENDAR_VIEW_CALENDAR)) {
+                       DBG("Not support calendar");
+
+               } else {
+                       DBG("Unable to understand uri[%s]", uri);
+               }
+
+       } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+       __append_tail(b);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __make_vcalendar_ver2(cal_make_s *b, calendar_list_h list)
+{
+       retvm_if (NULL == list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid paramter:list is NULL");
+
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_record_h record = NULL;
+
+       int version = 2;
+       __append_head(b);
+       __append_version(b, version);
+
+       ret = calendar_list_first(list);
+       retvm_if (CALENDAR_ERROR_NONE != ret, ret, "calendar_list_first() Failed");
+
+       do {
+               ret = calendar_list_get_current_record_p(list, &record);
+               if (CALENDAR_ERROR_NONE != ret) break;
+
+               // start vcalendar
+               char *uri = NULL;
+               ret = calendar_record_get_uri_p(record, &uri);
+               DBG("uri[%s]", uri);
+
+               if (!strcmp(uri, CALENDAR_VIEW_EVENT)) {
+                       ret = __cal_vcalendar_make_event(version, b, record);
+                       if (CALENDAR_ERROR_NONE != ret) break;
+
+               } else if (!strcmp(uri, CALENDAR_VIEW_TODO)) {
+                       ret = __cal_vcalendar_make_todo(version, b, record);
+                       if (CALENDAR_ERROR_NONE != ret) break;
+
+               } else if (!strcmp(uri, CALENDAR_VIEW_EXTENDED)) {
+                       cal_extended_s *extended = (cal_extended_s *)record;
+                       if (!strncmp(extended->key, "VERSION", strlen("VERSION"))) continue;
+
+                       ret = __cal_vcalendar_make_printf(b, extended->key, extended->value);
+                       if (CALENDAR_ERROR_NONE != ret) break;
+
+                       DBG("extended key[%s] value[%s]", extended->key, extended->value);
+
+               } else if (!strcmp(uri, CALENDAR_VIEW_TIMEZONE)) {
+                       DBG("Not support timezone");
+
+               } else if (!strcmp(uri, CALENDAR_VIEW_CALENDAR)) {
+                       DBG("Not support calendar");
+
+               } else {
+                       DBG("Unable to understand uri[%s]", uri);
+               }
+
+       } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+       __append_tail(b);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_vcalendar_make_vcalendar(cal_make_s *b, calendar_list_h list)
+{
+       retvm_if (NULL == list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid paramter:list is NULL");
+
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_record_h record = NULL;
+
+       int version = 2;
+
+       ret = calendar_list_first(list);
+       retvm_if (CALENDAR_ERROR_NONE != ret, ret, "calendar_list_first() Failed");
+       do {
+               ret = calendar_list_get_current_record_p(list, &record);
+               if(CALENDAR_ERROR_NONE != ret)
+                       break;
+
+               char *uri = NULL;
+               ret = calendar_record_get_uri_p(record, &uri);
+               if(CALENDAR_ERROR_NONE != ret)
+                       break;
+
+               if (!strcmp(uri, CALENDAR_VIEW_EXTENDED)) {
+                       cal_extended_s *extended = (cal_extended_s *)record;
+                       if (!strncmp(extended->key, "VERSION", strlen("VERSION"))) {
+                               version = strstr(extended->value, "1.0") ? 1 : 2;
+                               break;
+                       }
+               }
+
+       } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+       DBG("make as version(%d)", version);
+
+       switch (version)
+       {
+       case 1:
+               __make_vcalendar_ver1(b, list);
+               break;
+       case 2:
+               __make_vcalendar_ver2(b, list);
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/cal_vcalendar_make.h b/common/cal_vcalendar_make.h
new file mode 100644 (file)
index 0000000..1a1ccb4
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_VCALENDAR_MAKE_H__
+#define __CALENDAR_SVC_VCALENDAR_MAKE_H__
+
+#include "calendar_vcalendar.h"
+
+typedef struct {
+       int size;
+       char *data;
+       char lbuf[76];
+} cal_make_s ;
+
+cal_make_s *_cal_vcalendar_make_new(void);
+int _cal_vcalendar_make_vcalendar(cal_make_s *b, calendar_list_h list);
+char *_cal_vcalendar_make_get_data(cal_make_s *b);
+void _cal_vcalendar_make_free(cal_make_s **b);
+
+#endif // __CALENDAR_SVC_VCALENDAR_MAKE_H__
diff --git a/common/cal_vcalendar_parse.c b/common/cal_vcalendar_parse.c
new file mode 100644 (file)
index 0000000..a4947ec
--- /dev/null
@@ -0,0 +1,3247 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include <ctype.h>
+#include <vconf.h>
+
+#include "calendar_list.h"
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_record.h"
+#include "cal_view.h"
+#include "cal_time.h"
+
+#include "cal_vcalendar.h"
+#include "cal_vcalendar_parse.h"
+
+static UCalendar *__g_ucal_local; // to reduce time, set ucal
+static UCalendar *__g_ucal_gmt; // to reduce time, set ucal
+static char *__g_tzid;
+static bool __g_is_allday; // this is for ver1.0 "X-ALLDAY"
+static int __g_version;
+
+enum {
+       ENCODE_NONE = 0x0,
+       CHARSET_UTF8 = 0x0001,            // charset masking 0x00FF
+       CHARSET_UTF16 = 0x002,            // charset masking 0x00FF
+       ENCODE_BASE64 = 0x0100,           // encoding masking 0xFF00
+       ENCODE_QUOTED_PRINTABLE = 0x0200, // encoding masking 0xFF00
+       ENCODE_MAX,
+};
+
+struct _record_func {
+       char *prop;
+       int (*func)(calendar_record_h record, void *data);
+};
+
+char *_cal_vcalendar_parse_valarm(int type, calendar_record_h record, void *data);
+
+static char __cal_vcalendar_parse_decode_hexa(char *p)
+{
+       int i;
+       char decoded[2] = {0x00, 0x00};
+
+       for (i = 0; i < 2; i++) {
+               switch (p[i]) {
+               case '0' ... '9':
+                       decoded[i] = p[i] - '0';
+                       break;
+               case 'a' ... 'f':
+                       decoded[i] = p[i] - 'a' + 10;
+                       break;
+               case 'A' ... 'F':
+                       decoded[i] = p[i] - 'A' + 10;
+                       break;
+               }
+       }
+       return (char)((decoded[0] << 4) + decoded[1]);
+}
+
+static int __cal_vcalendar_parse_decode_string(char *p, int *len)
+{
+       ENTER();
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       int i = 0;
+       int j = 0;
+       while (p[i])
+       {
+               if ('\\' == p[i])
+               {
+                       if ('n' == p[i + 1] || 'N' == p[i + 1])
+                       {
+                               p[j] = '\n';
+                               i++;
+                       }
+                       else if ('\\' == p[i + 1])
+                       {
+                               p[j] = '\\';
+                               i++;
+                       }
+                       else if (';' == p[i + 1])
+                       {
+                               p[j] = ';';
+                               i++;
+                       }
+                       else if (',' == p[i + 1])
+                       {
+                               p[j] = ',';
+                               i++;
+                       }
+                       else
+                       {
+                               p[j] = p[i];
+                       }
+               }
+               else
+               {
+                       p[j] = p[i];
+               }
+               i++;
+               j++;
+       }
+       p[j] = '\0';
+       LEAVE();
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_decode_quoted_printable(char *p, int *len)
+{
+       int i = 0, j = 0;
+       char ch;
+
+       DBG("Before[%s]", p);
+
+       while (p[i]) {
+               if (p[i] == '=') {
+                       if (p[i+1] == 0x09 || p[i+1] == 0x20) {
+                               i +=3;
+
+                       } else if (p[i+1] == '\r' || p[i+1] == '\n') {
+                               i +=3;
+
+                       } else {
+                               if (p[i+1] == '0' && tolower(p[i+2]) == 'd' &&
+                                               p[i+3] == '=' && p[i+4] == '0' && tolower(p[i+5]) == 'a') {
+                                       p[j] = '\n';
+                                       j++;
+                                       i += 6;
+                               } else {
+                                       ch = __cal_vcalendar_parse_decode_hexa(&p[i+1]);
+                                       p[j] = ch;
+                                       j++;
+                                       i += 3;
+                               }
+                       }
+               } else {
+                       p[j] = p[i];
+                       j++;
+                       i++;
+               }
+       }
+       p[j] = '\0';
+       *len = i;
+       DBG("After[%s]", p);
+       return CALENDAR_ERROR_NONE;
+}
+
+static GHashTable *__hash_table_property_decode = NULL;
+static void __cal_vcalendar_parse_init_table_property_decode(void)
+{
+       ENTER();
+       if (__hash_table_property_decode)
+               return;
+
+       __hash_table_property_decode = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_property_decode, (gpointer)"CHARSET=UTF-8", (gpointer)CHARSET_UTF8);
+       g_hash_table_insert(__hash_table_property_decode, (gpointer)"CHARSET=UTF-16", (gpointer)CHARSET_UTF16);
+       g_hash_table_insert(__hash_table_property_decode, (gpointer)"ENCODING=BASE64", (gpointer)ENCODE_BASE64);
+       g_hash_table_insert(__hash_table_property_decode, (gpointer)"ENCODING=QUOTED-PRINTABLE", (gpointer)ENCODE_QUOTED_PRINTABLE);
+       LEAVE();
+}
+
+static int __cal_vcalendar_parse_get_property_decode_index(char *p)
+{
+       return (int)g_hash_table_lookup(__hash_table_property_decode, p);
+}
+
+static int __cal_vcalendar_parse_decode_text(char *p, int *margin)
+{
+       ENTER();
+       retvm_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER, "p is NULL");
+       retvm_if(strlen(p) == 0, CALENDAR_ERROR_NONE, "length is 0");
+
+       char **t = NULL;
+       t = g_strsplit(p, ":", -1); // cut until contents(FMTTYPE=image/vnd.microsoft.icon;ENCODING=BASE64;VALUE=BINARY:)
+       if (NULL == t)
+       {
+               ERR("g_strsplit() failed");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       int tlen = g_strv_length(t);
+       int len_prop = 0;
+       int encode = ENCODE_NONE;
+       if (1 == tlen)
+       {
+               ERR("No text");
+               g_strfreev(t);
+               return CALENDAR_ERROR_NONE;
+       }
+
+       len_prop = strlen(t[0]);
+       if (NULL == t[0] || len_prop == 0)
+       {
+               ERR("text is NULL");
+               g_strfreev(t);
+               return CALENDAR_ERROR_NONE;
+       }
+
+       if (margin) *margin = len_prop + 1;
+       __cal_vcalendar_parse_init_table_property_decode();
+
+       char **s = NULL;
+       int slen = 0;
+       s = g_strsplit(t[0], ";", -1);
+       if (NULL == s)
+       {
+               ERR("g_strsplit() failed");
+               g_strfreev(t);
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       slen = g_strv_length(s);
+       DBG("encoding count(%d)", slen);
+
+       int i;
+       for (i = 0; i < slen; i++)
+       {
+               DBG("[%s]", s[i]);
+               encode |= __cal_vcalendar_parse_get_property_decode_index(s[i]);
+       }
+       g_strfreev(s);
+       g_strfreev(t);
+
+       int len = 0;
+       switch (encode & 0xFF00)
+       {
+       case ENCODE_QUOTED_PRINTABLE:
+               __cal_vcalendar_parse_decode_quoted_printable(p + len_prop + 1, &len);
+               break;
+       case ENCODE_NONE:
+       case ENCODE_BASE64:
+       default:
+               __cal_vcalendar_parse_decode_string(p + len_prop + 1, &len);
+               break;
+       }
+       LEAVE();
+       return CALENDAR_ERROR_NONE;
+}
+////////////////////////////////////////////////////////////////////////
+
+int _cal_vcalendar_parse_unfolding(char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       char *q = p;
+       while ('\0' != *p) {
+               if ('=' == *p && '\r' == *(p + 1) && '\n' == *(p + 2)) // ver 1.0
+               {
+                       p += 3;
+               }
+               else if ('=' == *p && '\n' == *(p + 1)) // ver 1.0 not spec but allow
+               {
+                       p += 2;
+               }
+               else if ('\r' == *p && '\n' == *(p + 1) && ' ' == *(p + 2)) // ver 2.0 with white space
+               {
+                       p += 3;
+               }
+               else if ('\n' == *p && ' ' == *(p + 1)) // ver 2.0 not spec but allow with white space
+               {
+                       p += 2;
+               }
+               else if ('\r' == *p && '\n' == *(p + 1) && '\t' == *(p + 2)) // ver 2.0 with tab
+               {
+                       p += 3;
+               }
+               else if ('\n' == *p && '\t' == *(p + 1)) // ver 2.0 not spec but allow with tab
+               {
+                       p += 2;
+               }
+               else
+               {
+               }
+               *q = *p;
+               p++;
+               q++;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+char *_cal_vcalendar_parse_read_line(char *p, char **line)
+{
+       while (*p == ' ') p++; // remove empty space
+
+       char *q = p;
+       while (*p != '\n' && *p != '\0') p++;
+
+       if (*(p -1) == '\r')
+       {
+               *(p -1) = '\0';
+       }
+       else
+       {
+               *p = '\0';
+       }
+       *line = q;
+       p++;
+
+       DBG("line[%s]", *line);
+       return p;
+}
+
+char *_cal_vcalendar_parse_read_key_value(char *p, char **prop, char **cont)
+{
+       retvm_if (NULL == p, NULL, "Invalid parameter: p is NULL");
+
+       while (*p == ' ') p++; // remove empty space
+
+       char *q = p;
+       while (*p != ';' && *p != ':')
+       {
+               if (*p == '\0')
+               {
+                       ERR("Found NULL in the key string");
+                       *prop = NULL;
+                       *cont = NULL;
+                       return NULL;
+               }
+               p++;
+       }
+       *p = '\0';
+       *prop = q;
+       p++;
+
+       q = p;
+       while (*p != '\n' && *p != '\0') p++;
+
+       if (*(p -1) == '\r')
+       {
+               *(p -1) = '\0';
+       }
+       else
+       {
+               *p = '\0';
+       }
+       *cont = q;
+       p++;
+
+       DBG("[%s][%s]", *prop, *cont);
+       return p;
+}
+
+static int __cal_vcalendar_parse_dtstamp(int type, calendar_list_h list, calendar_record_h event, char *p)
+{
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_uid(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       int ret = CALENDAR_ERROR_NONE;
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = _cal_record_set_str(record, _calendar_event.uid, p);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               break;
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = _cal_record_set_str(record, _calendar_todo.uid, p);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_get_tzid_from_list(calendar_list_h list, const char *tzid, calendar_record_h *timezone)
+{
+       GList *l = NULL;
+
+       if (list == NULL || tzid == NULL)
+       {
+               return -1;
+       }
+
+       cal_list_s *cal_list = (cal_list_s *)list;
+       l = g_list_first(cal_list->record);
+
+       while (l)
+       {
+               char *uri = NULL;
+               calendar_record_h record = (calendar_record_h)l->data;
+               calendar_record_get_uri_p(record, &uri);
+               if (strncmp(uri, _calendar_timezone._uri, strlen(_calendar_timezone._uri)))
+               {
+                       l = g_list_next(l);
+                       continue;
+               }
+
+               cal_timezone_s *tz = (cal_timezone_s *)record;
+               if (!strncmp(tz->standard_name, tzid, strlen(tzid)))
+               {
+                       DBG("Found same tzid[%s] in the list", tzid);
+                       *timezone = record;
+                       break;
+               }
+               l = g_list_next(l);
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int __cal_vcalendar_parse_caltime_get(char *p, calendar_time_s *caltime)
+{
+       int y, m, d, h, n, s;
+       switch (strlen(p))
+       {
+       case 8: // YYYYMMDD, no tzid, no value
+               sscanf(p, "%04d%02d%02d", &y, &m, &d);
+               caltime->type = CALENDAR_TIME_LOCALTIME;
+               caltime->time.date.year = y;
+               caltime->time.date.month = m;
+               caltime->time.date.mday = d;
+               caltime->time.date.hour = 0;
+               caltime->time.date.minute = 0;
+               caltime->time.date.second = 0;
+               DBG("allday set (%04d/%02d/%02d %02d:%02d:%02d)", y, m, d, 0, 0, 0);
+               break;
+
+       case 15: // YYYYMMDDTHHMMSS
+               DBG("local");
+               sscanf(p, "%04d%02d%02dT%02d%02d%02d", &y, &m, &d, &h, &n, &s);
+               __g_is_allday = true;
+               caltime->type = CALENDAR_TIME_LOCALTIME;
+               caltime->time.date.year = y;
+               caltime->time.date.month = m;
+               caltime->time.date.mday = d;
+               caltime->time.date.hour = h;
+               caltime->time.date.minute = n;
+               caltime->time.date.second = s;
+               DBG("allday set (%04d/%02d/%02d %02d:%02d:%02d)", y, m, d, h, n, s);
+               break;
+
+       case 16: // YYYYMMDDTHHMMSSZ
+               DBG("utime");
+               sscanf(p,  "%04d%02d%02dT%02d%02d%02dZ", &y, &m, &d, &h, &n, &s);
+               caltime->type = CALENDAR_TIME_UTIME;
+               caltime->time.utime = _cal_time_get_utime(__g_ucal_gmt, y, m, d, h, n, s);
+               DBG("time(%lld)", caltime->time.utime);
+               break;
+       }
+       return 0;
+}
+
+enum
+{
+       __CAL_VCALENDAR_PARSE_NONE = 0,
+       __CAL_VCALENDAR_PARSE_TZID,
+       __CAL_VCALENDAR_PARSE_VALUE,
+};
+
+static GHashTable *__hash_table_property_time = NULL;
+static void __cal_vcalendar_parse_init_table_property_time(void)
+{
+       if (__hash_table_property_time)
+               return;
+
+       __hash_table_property_time = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_property_time, (gpointer)"TZID", (gpointer)__CAL_VCALENDAR_PARSE_TZID);
+       g_hash_table_insert(__hash_table_property_time, (gpointer)"VALUE", (gpointer)__CAL_VCALENDAR_PARSE_VALUE);
+}
+
+static int __cal_vcalendar_parse_get_property_time_index(char *p)
+{
+       return (int)g_hash_table_lookup(__hash_table_property_time, p);
+}
+
+void __cal_vcalendar_parse_time_remove_quot(char *p)
+{
+       if (NULL == p || strlen(p) == 0)
+       {
+               return;
+       }
+       // to remove quotation(ex> "abc" -> abc)
+       int len = strlen(p);
+       int i = 0;
+       if (*p == '\"')
+       {
+               for (i = 0; i < len; i++)
+               {
+                       p[i] = p[i+1];
+               }
+               p[len - 2] = '\0';
+       }
+       DBG("[%s]", p);
+}
+
+int __cal_vcalendar_parse_time(char *p, calendar_list_h list, calendar_time_s *caltime)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       char **t = g_strsplit_set(p, ";:", -1);
+       if (NULL == t)
+       {
+               ERR("g_strsplit_set() failed");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       int len = g_strv_length(t);
+
+       /* DTSTART:19971102
+        * DTSTART:19980119T070000Z
+        * DTSTART:20140916T070000
+        */
+       if (1 == len) {
+               __cal_vcalendar_parse_caltime_get(p, caltime);
+               g_strfreev(t);
+               return CALENDAR_ERROR_NONE;
+       }
+
+       /* DTSTART;VALUE=DATE:1997031
+        * DTSTART;TZID=US-Eastern:19980119T020000
+        * DTSTART;TZID=Asia/Seoul;VALUE=DATE-TIME:19980119T020000Z
+        */
+       __cal_vcalendar_parse_init_table_property_time();
+       int i;
+       for (i = 0; i < len; i++)
+       {
+               char **s = g_strsplit(t[i], "=", 2);
+               if (NULL == s)
+               {
+                       ERR("g_strsplit() failed");
+                       break;
+               }
+
+               switch (__cal_vcalendar_parse_get_property_time_index(s[0]))
+               {
+               case __CAL_VCALENDAR_PARSE_TZID:
+                       DBG("__CAL_VCALENDAR_PARSE_TZID [%s]", s[1]);
+                       __cal_vcalendar_parse_time_remove_quot(s[1]);
+                       if (__g_tzid) {
+                               DBG("has __g_tzid[%s]", __g_tzid);
+                               if (!strncmp(s[1], __g_tzid, strlen(__g_tzid))) {
+                                       DBG("has same tzid");
+                                       break; // pass
+
+                               } else { // has tzid but different
+                                       DBG("dfferent tizd [%s] with __g_tzid", s[1]);
+                                       free(__g_tzid);
+                                       __g_tzid = NULL;
+
+                                       if (__g_ucal_local) {
+                                               ucal_close(__g_ucal_local);
+                                               __g_ucal_local = NULL;
+                                       }
+                               }
+                       }
+
+                       // NO __g_ucal_local, so set OR has g_tzid_local but different
+                       if (false == (_cal_time_is_registered_tzid(s[1])))
+                       {
+                               char *like_tzid = NULL;
+                               calendar_record_h timezone = NULL;
+                               // try get timezone info from the list
+                               __cal_vcalendar_parse_get_tzid_from_list(list, s[1], &timezone);
+                               if (timezone)
+                               {
+                                       DBG("Found from the list");
+                                       _cal_time_get_like_tzid(s[1], timezone, &like_tzid);
+                                       DBG("[%s]", like_tzid);
+                                       __g_tzid = like_tzid;
+                               }
+                               else
+                               {
+                                       DBG("Nowhere to find, so set gmt");
+                                       __g_tzid = strdup(CAL_TZID_GMT); // should set not to come here again.
+                               }
+                       }
+                       else
+                       {
+                               __g_tzid = strdup(s[1]);
+                       }
+                       __g_ucal_local = _cal_time_get_ucal(__g_tzid, 1); // set wkst sunday
+                       DBG("set tzid [%s]", __g_tzid);
+                       break;
+
+               case __CAL_VCALENDAR_PARSE_VALUE:
+                       DBG("__CAL_VCALENDAR_PARSE_VALUE");
+                       break;
+               default:
+                       __cal_vcalendar_parse_caltime_get(t[i], caltime);
+                       break;
+               }
+               g_strfreev(s);
+       }
+       g_strfreev(t);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_dtstart(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       calendar_time_s caltime = {0};
+       __cal_vcalendar_parse_time(p, list, &caltime);
+
+       int ret = CALENDAR_ERROR_NONE;
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = _cal_record_set_str(record, _calendar_event.start_tzid, __g_tzid ? __g_tzid : CAL_TZID_GMT);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               ret = _cal_record_set_caltime(record, _calendar_event.start_time, caltime);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_caltime() Failed(%d)", ret);
+               break;
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = _cal_record_set_str(record, _calendar_todo.start_tzid, __g_tzid ? __g_tzid : CAL_TZID_GMT);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               ret = _cal_record_set_caltime(record, _calendar_todo.start_time, caltime);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_caltime() Failed(%d)", ret);
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+/* created: UTC value */
+static int __cal_vcalendar_parse_created(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       int y = 0, m = 0, d = 0;
+       int h = 0, n = 0, s = 0;
+       sscanf(p,  "%04d%02d%02dT%02d%02d%02dZ", &y, &m, &d, &h, &n, &s);
+       long long int created = _cal_time_get_utime(__g_ucal_gmt, y, m, d, h, n, s);
+
+       int ret = CALENDAR_ERROR_NONE;
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = _cal_record_set_lli(record, _calendar_event.created_time, created);
+               break;
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = _cal_record_set_lli(record, _calendar_todo.created_time, created);
+               break;
+       }
+       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_lli() Failed(%d)", ret);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_description(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       int len = 0;
+       __cal_vcalendar_parse_decode_text(p, &len);
+
+       int ret = CALENDAR_ERROR_NONE;
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = _cal_record_set_str(record, _calendar_event.description, p + len);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               break;
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = _cal_record_set_str(record, _calendar_todo.description, p + len);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               break;
+       }
+       DBG("description(%s)\n", p + len);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_last_mod(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       int y = 0, m = 0, d = 0;
+       int h = 0, n = 0, s = 0;
+       sscanf(p,  "%04d%02d%02dT%02d%02d%02dZ", &y, &m, &d, &h, &n, &s);
+       long long int last_mod = _cal_time_get_utime(__g_ucal_gmt, y, m, d, h, n, s);
+
+       int ret = CALENDAR_ERROR_NONE;
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = _cal_record_set_lli(record, _calendar_event.last_modified_time, last_mod);
+               break;
+
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = _cal_record_set_lli(record, _calendar_todo.last_modified_time, last_mod);
+               break;
+       }
+       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_lli() Failed(%d)", ret);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_location(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       int len = 0;
+       __cal_vcalendar_parse_decode_text(p, &len);
+
+       int ret = CALENDAR_ERROR_NONE;
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = _cal_record_set_str(record, _calendar_event.location, p + len);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               break;
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = _cal_record_set_str(record, _calendar_todo.location, p + len);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_priority(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       if (p[0] < '0' || p[0] > '9') {
+               DBG("warning check range\n");
+               return -1;
+       }
+       int original_priority = atoi(p);
+       int modified_priority;
+
+       switch (__g_version)
+       {
+       case 1:
+               switch (original_priority)
+               {
+               case 0:
+                       modified_priority = CALENDAR_TODO_PRIORITY_LOW;
+                       break;
+               case 1:
+                       modified_priority = CALENDAR_TODO_PRIORITY_NORMAL;
+                       break;
+               case 2:
+                       modified_priority = CALENDAR_TODO_PRIORITY_HIGH;
+                       break;
+               default:
+                       DBG("Unable to parse [%s]", p);
+                       modified_priority = CALENDAR_TODO_PRIORITY_NONE;
+                       break;
+               }
+               break;
+
+       case 2:
+       default:
+               switch (original_priority)
+               {
+               case 1 ... 4:
+                       modified_priority = CALENDAR_TODO_PRIORITY_HIGH;
+                       break;
+               case 5:
+                       modified_priority = CALENDAR_TODO_PRIORITY_NORMAL;
+                       break;
+               case 6 ... 9:
+                       modified_priority = CALENDAR_TODO_PRIORITY_LOW;
+                       break;
+               default:
+                       DBG("Unable to parse [%s]", p);
+                       modified_priority = CALENDAR_TODO_PRIORITY_NONE;
+                       break;
+               }
+               break;
+       }
+
+       DBG("convert priority(%d) -> (%d)", original_priority, modified_priority);
+       int ret = CALENDAR_ERROR_NONE;
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = _cal_record_set_int(record, _calendar_event.priority, modified_priority);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+               break;
+
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = _cal_record_set_int(record, _calendar_todo.priority, modified_priority);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static GHashTable *__hash_table_property_status_event = NULL;
+static void __cal_vcalendar_parse_init_table_property_status_event(void)
+{
+       if (__hash_table_property_status_event)
+               return;
+
+       __hash_table_property_status_event = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_property_status_event, (gpointer)"TENTATIVE", (gpointer)CALENDAR_EVENT_STATUS_TENTATIVE);
+       g_hash_table_insert(__hash_table_property_status_event, (gpointer)"CONFIRMED", (gpointer)CALENDAR_EVENT_STATUS_CONFIRMED);
+       g_hash_table_insert(__hash_table_property_status_event, (gpointer)"CANCELLED", (gpointer)CALENDAR_EVENT_STATUS_CANCELLED);
+}
+
+static int __cal_vcalendar_parse_get_property_status_event_index(char *p)
+{
+       return (int)g_hash_table_lookup(__hash_table_property_status_event, p);
+}
+
+static GHashTable *__hash_table_property_status_todo = NULL;
+static void __cal_vcalendar_parse_init_table_property_status_todo(void)
+{
+       if (__hash_table_property_status_todo)
+               return;
+
+       __hash_table_property_status_todo = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_property_status_todo, (gpointer)"NEEDS-ACTION", (gpointer)CALENDAR_TODO_STATUS_NEEDS_ACTION);
+       g_hash_table_insert(__hash_table_property_status_todo, (gpointer)"NEEDS ACTION", (gpointer)CALENDAR_TODO_STATUS_NEEDS_ACTION);
+       g_hash_table_insert(__hash_table_property_status_todo, (gpointer)"COMPLETED", (gpointer)CALENDAR_TODO_STATUS_COMPLETED);
+       g_hash_table_insert(__hash_table_property_status_todo, (gpointer)"IN-PROCESS", (gpointer)CALENDAR_TODO_STATUS_IN_PROCESS);
+       g_hash_table_insert(__hash_table_property_status_todo, (gpointer)"CANCELLED", (gpointer)CALENDAR_TODO_STATUS_CANCELED);
+}
+
+static int __cal_vcalendar_parse_get_property_status_todo_index(char *p)
+{
+       return (int)g_hash_table_lookup(__hash_table_property_status_todo, p);
+}
+
+static int __cal_vcalendar_parse_status(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       int status;
+
+       int ret = CALENDAR_ERROR_NONE;
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               __cal_vcalendar_parse_init_table_property_status_event();
+               status = __cal_vcalendar_parse_get_property_status_event_index(p);
+               if (0 == status)
+               {
+                       status = CALENDAR_EVENT_STATUS_NONE;
+               }
+               ret = _cal_record_set_int(record, _calendar_event.event_status, status);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+               break;
+
+       case CALENDAR_BOOK_TYPE_TODO:
+               __cal_vcalendar_parse_init_table_property_status_todo();
+               status = __cal_vcalendar_parse_get_property_status_todo_index(p);
+               if (0 == status)
+               {
+                       status = CALENDAR_TODO_STATUS_NONE;
+               }
+               ret = _cal_record_set_int(record, _calendar_todo.todo_status, status);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_summary(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       int len = 0;
+       __cal_vcalendar_parse_decode_text(p, &len);
+
+       int ret = CALENDAR_ERROR_NONE;
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = _cal_record_set_str(record, _calendar_event.summary, p + len);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               break;
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = _cal_record_set_str(record, _calendar_todo.summary, p + len);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               break;
+       }
+       DBG("summary[%s]", p + len);
+       return CALENDAR_ERROR_NONE;
+}
+
+enum {
+       __RRULE_VER1_BYYEARDAY = 0,
+       __RRULE_VER1_BYMONTH,
+       __RRULE_VER1_BYMONTHDAY,
+       __RRULE_VER1_BYSETPOS,
+       __RRULE_VER1_BYDAY,
+};
+
+#define CHECK_BYSTR() do { \
+       if (strlen(bystr) > 0) \
+       { \
+               DBG("check bystr[%s]", bystr); \
+               switch (by) \
+               { \
+               case __RRULE_VER1_BYYEARDAY: \
+                                                                                         ret = _cal_record_set_str(record, _calendar_event.byyearday, bystr); \
+                       break; \
+               case __RRULE_VER1_BYMONTH: \
+                                                                                       ret = _cal_record_set_str(record, _calendar_event.bymonth, bystr); \
+                       break; \
+               case __RRULE_VER1_BYMONTHDAY: \
+                                                                                               ret = _cal_record_set_str(record, _calendar_event.bymonthday, bystr); \
+                       break; \
+               case __RRULE_VER1_BYSETPOS: \
+                                                                                        ret = _cal_record_set_str(record, _calendar_event.byday, bystr); \
+                       break; \
+               case __RRULE_VER1_BYDAY: \
+                                                                                ret = _cal_record_set_str(record, _calendar_event.byday, bystr); \
+                       break; \
+               default: \
+                                       DBG("Unable to parse"); \
+                       break; \
+               } \
+               memset(bystr, 0x0, sizeof(bystr)); \
+               nth_week = 0; \
+       } \
+} while (0)
+
+static int __cal_vcalendar_parse_rrule_ver1(calendar_record_h record, char *p)
+{
+       if (NULL == p)
+       {
+               ERR("Invalid parameter: p is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       char **t = g_strsplit(p, " ", -1);
+       if (!t) {
+               ERR("g_strsplit failed");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       int freq = -1;
+       int interval = -1;
+       int by = 0;
+       int lent = 0;
+       char bystr[2048] ={0};
+       int range_type = -1;
+       int nth_week = 0;
+       int length = g_strv_length(t);
+       int i;
+       int ret;
+       for (i = 0; i < length; i++)
+       {
+               if (t[i] == NULL || strlen(t[i]) == 0)
+               {
+                       continue;
+               }
+               int len = strlen(t[i]);
+               if (*t[i] == 'Y' && *(t[i] + 1) == 'D')
+               {
+                       CHECK_BYSTR();
+                       if (freq < 0) freq = CALENDAR_RECURRENCE_YEARLY;
+                       by = __RRULE_VER1_BYYEARDAY;
+                       if (interval < 0) interval = len == 2 ? 1 : atoi(t[i] + 2);
+               }
+               else if (*t[i] == 'Y' && *(t[i] + 1) == 'M')
+               {
+                       CHECK_BYSTR();
+                       if (freq < 0) freq = CALENDAR_RECURRENCE_YEARLY;
+                       by = __RRULE_VER1_BYMONTH;
+                       if (interval < 0) interval = len == 2 ? 1 : atoi(t[i] + 2);
+               }
+               else if (*t[i] == 'M' && *(t[i] + 1) == 'D')
+               {
+                       CHECK_BYSTR();
+                       if (freq < 0) freq = CALENDAR_RECURRENCE_MONTHLY;
+                       by = __RRULE_VER1_BYMONTHDAY;
+                       if (interval < 0) interval = len == 2 ? 1 : atoi(t[i] + 2);
+               }
+               else if (*t[i] == 'M' && *(t[i] + 1) == 'P')
+               {
+                       CHECK_BYSTR();
+                       if (freq < 0) freq = CALENDAR_RECURRENCE_MONTHLY;
+                       by = __RRULE_VER1_BYSETPOS;
+                       if (interval < 0) interval = len == 2 ? 1 : atoi(t[i] + 2);
+               }
+               else if (*t[i] == 'W' && *(t[i] + 1) != 'E') // not WED
+               {
+                       CHECK_BYSTR();
+                       if (freq < 0) freq = CALENDAR_RECURRENCE_WEEKLY;
+                       by = __RRULE_VER1_BYDAY;
+                       if (interval < 0) interval = len == 1 ? 1 : atoi(t[i] + 1);
+               }
+               else if (*t[i] == 'D')
+               {
+                       CHECK_BYSTR();
+                       if (freq < 0) freq = CALENDAR_RECURRENCE_DAILY;
+                       by = __RRULE_VER1_BYMONTHDAY;
+                       if (interval < 0) interval = len == 1 ? 1 : atoi(t[i] + 1);
+               }
+               else if (*t[i] == '#')
+               {
+                       CHECK_BYSTR();
+                       range_type = CALENDAR_RANGE_COUNT;
+                       int count = atoi(t[i] + 1);
+                       if (count == 0)
+                       {
+                               ret = _cal_record_set_int(record, _calendar_event.range_type, CALENDAR_RANGE_NONE);
+                               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+                               DBG("endless");
+                       }
+                       else
+                       {
+                               /*
+                                       calendar_time_s ct = {0};
+                                       ret = calendar_record_get_caltime(record, _calendar_event.start_time, &ct);
+                                       _cal_time_get_next_time(__g_ucal_gmt, interval *count -1, freq, &ct);
+                                       ret = _cal_record_set_int(record, _calendar_event.range_type, CALENDAR_RANGE_UNTIL);
+                                       ret = _cal_record_set_caltime(record, _calendar_event.until_time, ct);
+                                */
+                               ret = _cal_record_set_int(record, _calendar_event.range_type, CALENDAR_RANGE_COUNT);
+                               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+                               ret = _cal_record_set_int(record, _calendar_event.count, count);
+                               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+                               DBG("set until and count(%d)", count);
+                       }
+               }
+               else if (len < strlen("YYYYMMDDTHHMMSS")) // by
+               {
+                       switch (by)
+                       {
+                       case __RRULE_VER1_BYYEARDAY:
+                       case __RRULE_VER1_BYMONTH:
+                       case __RRULE_VER1_BYMONTHDAY:
+                               len += snprintf(bystr +len, sizeof(bystr) -len, "%s%s", 0 == len ? "": ",", t[i]);
+                               break;
+
+                       case __RRULE_VER1_BYSETPOS:
+                               {
+                                       if (*t[i] >= '0' && *t[i] <= '9')
+                                       {
+                                               char *bysetpos = NULL;
+                                               calendar_record_get_str_p(record, _calendar_event.bysetpos, &bysetpos);
+                                               int pos = 0;
+
+                                               if (*(t[i] + len - 1) == '-')
+                                               {
+                                                       char *num = strdup(t[i]);
+                                                       if (NULL == num) {
+                                                               ERR("num is NULL");
+                                                               break;
+                                                       }
+                                                       num[len - 1] = '\0';
+                                                       pos = atoi(num);
+                                                       pos *= -1;
+                                                       free(num);
+                                                       num = NULL;
+                                                       DBG("(%d)", pos);
+                                               }
+                                               else
+                                               {
+                                                       char *num = strdup(t[i]);
+                                                       if (NULL == num) {
+                                                               ERR("num is NULL");
+                                                               break;
+                                                       }
+                                                       num[len - 1] = '\0';
+                                                       pos = atoi(num);
+                                                       free(num);
+                                                       num = NULL;
+                                                       DBG("(%d)", pos);
+                                               }
+
+                                               if (pos != 0) {
+                                                       char buf[1024] = {0};
+                                                       snprintf(buf, sizeof(buf), "%s%s%d", bysetpos ? bysetpos : "", bysetpos ? "," : "", pos);
+                                                       DBG("pos[%s]", buf);
+                                                       _cal_record_set_str(record, _calendar_event.bysetpos, buf);
+                                               }
+                                       } else {
+                                               len += snprintf(bystr +len, sizeof(bystr) -len, "%s%s", 0 == strlen(bystr) ? "" : ",", t[i]);
+                                       }
+                               }
+                               break;
+
+                       case __RRULE_VER1_BYDAY:
+                               if (*t[i] >= '0' && *t[i] <= '9') // get nth_week : -2
+                               {
+                                       if (*(t[i] + len - 1) == '-') {
+                                               char *num = strdup(t[i]);
+                                               if (NULL == num)
+                                                       break;
+                                               num[len - 1] = '\0';
+                                               nth_week = atoi(num);
+                                               nth_week *= -1;
+                                               free(num);
+                                               num = NULL;
+                                       }
+                                       if (*(t[i] + len - 1) == '+') {
+                                               char *num = strdup(t[i]);
+                                               if (NULL == num)
+                                                       break;
+                                               num[len - 1] = '\0';
+                                               nth_week = atoi(num);
+                                               free(num);
+                                               num = NULL;
+                                       }
+                                       else
+                                       {
+                                               nth_week = atoi(t[i]);
+                                       }
+                               } else {
+                                       // nth_week : -2, t[i] : MO -> -2MO
+                                       len += snprintf(bystr +len, sizeof(bystr) -len, "%s%d%s", 0 == len ? "" : ",", nth_week == 0 ? 1 : nth_week, t[i]);
+                               }
+                               break;
+                       }
+               }
+               else if (len >= strlen("YYYYMMDDTHHMMSS")) // until
+               {
+                       CHECK_BYSTR();
+                       if (range_type >= 0)
+                       {
+                               ERR("range type is already set(%d), so skip until", range_type);
+                               continue;
+                       }
+                       range_type = CALENDAR_RANGE_UNTIL;
+                       ret = _cal_record_set_int(record, _calendar_event.range_type, CALENDAR_RANGE_UNTIL);
+                       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+                       calendar_time_s ut = {0};
+                       __cal_vcalendar_parse_caltime_get(t[i], &ut);
+                       ret = _cal_record_set_caltime(record, _calendar_event.until_time, ut);
+                       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_caltime() Failed(%d)", ret);
+                       DBG("range until");
+               }
+               else
+               {
+                       CHECK_BYSTR();
+               }
+       }
+       CHECK_BYSTR();
+       ret = _cal_record_set_int(record, _calendar_event.freq, freq);
+       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+       ret = _cal_record_set_int(record, _calendar_event.interval, interval);
+       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+       DBG("freq(%d) interval(%d)", freq, interval);
+       if (range_type < 0)
+       {
+               ret = _cal_record_set_int(record, _calendar_event.range_type, CALENDAR_RANGE_NONE);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+               DBG("range none");
+       }
+       g_strfreev(t);
+       return CALENDAR_ERROR_NONE;
+}
+
+static GHashTable *__hash_table_property_freq = NULL;
+static void __cal_vcalendar_parse_init_table_property_freq(void)
+{
+       if (__hash_table_property_freq)
+               return;
+
+       __hash_table_property_freq = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_property_freq, (gpointer)"YEARLY", (gpointer)CALENDAR_RECURRENCE_YEARLY);
+       g_hash_table_insert(__hash_table_property_freq, (gpointer)"MONTHLY", (gpointer)CALENDAR_RECURRENCE_MONTHLY);
+       g_hash_table_insert(__hash_table_property_freq, (gpointer)"WEEKLY", (gpointer)CALENDAR_RECURRENCE_WEEKLY);
+       g_hash_table_insert(__hash_table_property_freq, (gpointer)"DAILY", (gpointer)CALENDAR_RECURRENCE_DAILY);
+       g_hash_table_insert(__hash_table_property_freq, (gpointer)"HOURLY", (gpointer)CALENDAR_RECURRENCE_NONE);
+       g_hash_table_insert(__hash_table_property_freq, (gpointer)"MINUTELY", (gpointer)CALENDAR_RECURRENCE_NONE);
+       g_hash_table_insert(__hash_table_property_freq, (gpointer)"SECONDLY", (gpointer)CALENDAR_RECURRENCE_NONE);
+}
+
+static int __cal_vcalendar_parse_get_property_freq_index(char *p)
+{
+       return (int)g_hash_table_lookup(__hash_table_property_freq, p);
+}
+static int __cal_vcalendar_parse_freq(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       int ret;
+       int freq = -1;
+
+       __cal_vcalendar_parse_init_table_property_freq();
+       freq = __cal_vcalendar_parse_get_property_freq_index(q);
+       ret = _cal_record_set_int(event, _calendar_event.freq, freq);
+       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+       return CALENDAR_ERROR_NONE;
+}
+static int __cal_vcalendar_parse_until(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       int ret;
+       calendar_time_s stime = {0};
+       calendar_time_s until = {0};
+       int y = 0, m = 0, d = 0;
+       int h = 0, n = 0, s = 0;
+
+       /* until value type has the same value as the dtstart */
+       ret = _cal_record_set_int(event, _calendar_event.range_type, CALENDAR_RANGE_UNTIL);
+       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+       ret = calendar_record_get_caltime(event, _calendar_event.start_time, &stime);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Failed(%d)", ret);
+       until.type = stime.type;
+
+       switch (stime.type)
+       {
+       case CALENDAR_TIME_UTIME:
+               sscanf(q, "%4d%2d%2dT%2d%2d%2dZ", &y, &m, &d, &h, &n, &s);
+               until.time.utime = _cal_time_get_utime(__g_ucal_gmt, y, m, d, h, n, s);
+               break;
+
+       case CALENDAR_TIME_LOCALTIME:
+               sscanf(q, "%4d%2d%2dT%2d%2d%2d", &y, &m, &d, &h, &n, &s);
+               until.time.date.year = y;
+               until.time.date.month = m;
+               until.time.date.mday = d;
+               until.time.date.hour = h;
+               until.time.date.minute = n;
+               until.time.date.second = s;
+               break;
+       }
+       ret = _cal_record_set_caltime(event, _calendar_event.until_time, until);
+       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_caltime() Failed(%d)", ret);
+
+       return CALENDAR_ERROR_NONE;
+}
+static int __cal_vcalendar_parse_count(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       int ret;
+       ret = _cal_record_set_int(event, _calendar_event.range_type, CALENDAR_RANGE_COUNT);
+       int c = atoi(q);
+       ret = _cal_record_set_int(event, _calendar_event.count, c < 0 ? 0 : c);
+       return ret;
+}
+static int __cal_vcalendar_parse_interval(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       int c = atoi(q);
+       return _cal_record_set_int(event, _calendar_event.interval, c < 0 ? 0 : c);
+}
+static int __cal_vcalendar_parse_bysecond(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       return _cal_record_set_str(event, _calendar_event.bysecond, q);
+}
+static int __cal_vcalendar_parse_byminute(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       return _cal_record_set_str(event, _calendar_event.byminute, q);
+}
+static int __cal_vcalendar_parse_byhour(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       return _cal_record_set_str(event, _calendar_event.byhour, q);
+}
+static int __cal_vcalendar_parse_byday(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       return _cal_record_set_str(event, _calendar_event.byday, q);
+}
+static int __cal_vcalendar_parse_bymonthday(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       return _cal_record_set_str(event, _calendar_event.bymonthday, q);
+}
+static int __cal_vcalendar_parse_byyearday(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       return _cal_record_set_str(event, _calendar_event.byyearday, q);
+}
+static int __cal_vcalendar_parse_byweekno(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       return _cal_record_set_str(event, _calendar_event.byweekno, q);
+}
+static int __cal_vcalendar_parse_bymonth(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       return _cal_record_set_str(event, _calendar_event.bymonth, q);
+}
+static int __cal_vcalendar_parse_bysetpos(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       return _cal_record_set_str(event, _calendar_event.bysetpos, q);
+}
+
+static GHashTable *__hash_table_weekname = NULL;
+static void __cal_vcalendar_parse_init_table_weekname(void)
+{
+       if (__hash_table_weekname)
+               return;
+
+       __hash_table_weekname = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_weekname, (gpointer)"SU", (gpointer)CALENDAR_SUNDAY);
+       g_hash_table_insert(__hash_table_weekname, (gpointer)"MO", (gpointer)CALENDAR_MONDAY);
+       g_hash_table_insert(__hash_table_weekname, (gpointer)"TU", (gpointer)CALENDAR_TUESDAY);
+       g_hash_table_insert(__hash_table_weekname, (gpointer)"WE", (gpointer)CALENDAR_WEDNESDAY);
+       g_hash_table_insert(__hash_table_weekname, (gpointer)"TH", (gpointer)CALENDAR_THURSDAY);
+       g_hash_table_insert(__hash_table_weekname, (gpointer)"FR", (gpointer)CALENDAR_FRIDAY);
+       g_hash_table_insert(__hash_table_weekname, (gpointer)"SA", (gpointer)CALENDAR_SATURDAY);
+}
+
+static int __cal_vcalendar_parse_get_weekname_index(char *p)
+{
+       return (int)g_hash_table_lookup(__hash_table_weekname, p);
+}
+
+static int __cal_vcalendar_parse_wkst(calendar_record_h event, char *q)
+{
+       retv_if(q == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       __cal_vcalendar_parse_init_table_weekname();
+       int wkst = __cal_vcalendar_parse_get_weekname_index(q);
+       return _cal_record_set_int(event, _calendar_event.wkst, wkst);
+}
+
+static GHashTable *__hash_table_property_rrule = NULL;
+static void __cal_vcalendar_parse_init_table_property_rrule(void)
+{
+       if (__hash_table_property_rrule)
+               return;
+
+       __hash_table_property_rrule = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"FREQ", (gpointer)(__cal_vcalendar_parse_freq));
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"UNTIL", (gpointer)(__cal_vcalendar_parse_until));
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"COUNT", (gpointer)(__cal_vcalendar_parse_count));
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"INTERVAL", (gpointer)(__cal_vcalendar_parse_interval));
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"BYSECOND", (gpointer)(__cal_vcalendar_parse_bysecond));
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"BYMINUTE", (gpointer)(__cal_vcalendar_parse_byminute));
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"BYHOUR", (gpointer)(__cal_vcalendar_parse_byhour));
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"BYDAY", (gpointer)(__cal_vcalendar_parse_byday));
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"BYMONTHDAY", (gpointer)(__cal_vcalendar_parse_bymonthday));
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"BYYEARDAY", (gpointer)(__cal_vcalendar_parse_byyearday));
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"BYWEEKNO", (gpointer)(__cal_vcalendar_parse_byweekno));
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"BYMONTH", (gpointer)(__cal_vcalendar_parse_bymonth));
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"BYSETPOS", (gpointer)(__cal_vcalendar_parse_bysetpos));
+       g_hash_table_insert(__hash_table_property_rrule, (gpointer)"WKST", (gpointer)(__cal_vcalendar_parse_wkst));
+}
+
+typedef int (*func_property_rrule)(calendar_record_h event, char *q);
+static int __cal_vcalendar_parse_get_property_rrule_index(char *p, calendar_record_h event, char *q)
+{
+       func_property_rrule func = g_hash_table_lookup(__hash_table_property_rrule, p);
+       if (func)
+       {
+               func(event, q);
+       }
+       else
+       {
+               DBG("No func");
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_rrule_ver2(calendar_record_h record, char *p)
+{
+       char **t = g_strsplit_set(p, ";:", -1);
+       if (NULL == t)
+       {
+               ERR("g_strsplit_set() failed");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       int i;
+       int len = g_strv_length(t);
+
+       __cal_vcalendar_parse_init_table_property_rrule();
+
+       for (i = 0; i < len; i++)
+       {
+               char **s = g_strsplit(t[i], "=", 2);
+               if (NULL == s)
+               {
+                       ERR("g_strsplit() failed");
+                       break;
+               }
+               DBG("[%s][%s]", s[0], s[1]);
+               __cal_vcalendar_parse_get_property_rrule_index(s[0], record, s[1]);
+               g_strfreev(s);
+       }
+       g_strfreev(t);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_rrule(int type, calendar_list_h list, calendar_record_h record, char *cont)
+{
+       int version = 0;
+       char *p = (char *)cont;
+
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       version = strstr(p, "FREQ=") ? 2 : 1;
+       DBG("This rrule is for ver%d", version);
+
+       // set default
+       int ret = CALENDAR_ERROR_NONE;
+       ret = _cal_record_set_int(record, _calendar_event.interval, 1);
+       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+       ret = _cal_record_set_int(record, _calendar_event.range_type, CALENDAR_RANGE_NONE);
+       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_int() Failed(%d)", ret);
+
+       // set rrule
+       switch (version)
+       {
+       case 1:
+               __cal_vcalendar_parse_rrule_ver1(record, p);
+               break;
+
+       case 2:
+               __cal_vcalendar_parse_rrule_ver2(record, p);
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_dtend(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       calendar_time_s caltime = {0};
+       __cal_vcalendar_parse_time(p, list, &caltime);
+
+       int ret = CALENDAR_ERROR_NONE;
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = _cal_record_set_str(record, _calendar_event.end_tzid, __g_tzid ? __g_tzid : CAL_TZID_GMT);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               ret = _cal_record_set_caltime(record, _calendar_event.end_time, caltime);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_caltime() Failed(%d)", ret);
+               break;
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = _cal_record_set_str(record, _calendar_todo.due_tzid, __g_tzid ? __g_tzid : CAL_TZID_GMT);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               ret = _cal_record_set_caltime(record, _calendar_todo.due_time, caltime);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_caltime() Failed(%d)", ret);
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_due(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       calendar_time_s caltime = {0};
+       __cal_vcalendar_parse_time(p, list, &caltime);
+
+       int ret = CALENDAR_ERROR_NONE;
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = _cal_record_set_str(record, _calendar_event.end_tzid, __g_tzid ? __g_tzid : CAL_TZID_GMT);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               ret = _cal_record_set_caltime(record, _calendar_event.end_time, caltime);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_caltime() Failed(%d)", ret);
+               break;
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = _cal_record_set_str(record, _calendar_todo.due_tzid, __g_tzid ? __g_tzid : CAL_TZID_GMT);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               ret = _cal_record_set_caltime(record, _calendar_todo.due_time, caltime);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_caltime() Failed(%d)", ret);
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_completed(int type, calendar_list_h list, calendar_record_h event, char *p)
+{
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_percent(int type, calendar_list_h list, calendar_record_h event, char *p)
+{
+       return CALENDAR_ERROR_NONE;
+}
+
+static GHashTable *__hash_table_parameter_attendee_role = NULL;
+static void __cal_vcalendar_parse_init_table_parameter_attendee_role(void)
+{
+       if (__hash_table_parameter_attendee_role)
+               return;
+
+       __hash_table_parameter_attendee_role = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_parameter_attendee_role, (gpointer)"REQ-PARTICIPANT", (gpointer)CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT);
+       g_hash_table_insert(__hash_table_parameter_attendee_role, (gpointer)"OPT-PARTICIPANT", (gpointer)CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT);
+       g_hash_table_insert(__hash_table_parameter_attendee_role, (gpointer)"NON-PARTICIPANT", (gpointer)CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT);
+       g_hash_table_insert(__hash_table_parameter_attendee_role, (gpointer)"CHAIR", (gpointer)CALENDAR_ATTENDEE_ROLE_CHAIR);
+}
+
+static int __cal_vcalendar_parse_get_parameter_attendee_role_index(char *p)
+{
+       return (int)g_hash_table_lookup(__hash_table_parameter_attendee_role, p);
+}
+
+static GHashTable *__hash_table_parameter_attendee_partstat = NULL;
+static void __cal_vcalendar_parse_init_table_parameter_attendee_partstat(void)
+{
+       if (__hash_table_parameter_attendee_partstat)
+               return;
+
+       __hash_table_parameter_attendee_partstat = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_parameter_attendee_partstat, (gpointer)"NEEDS-ACTION", (gpointer)CALENDAR_ATTENDEE_STATUS_PENDING);
+       g_hash_table_insert(__hash_table_parameter_attendee_partstat, (gpointer)"ACCEPTED", (gpointer)CALENDAR_ATTENDEE_STATUS_ACCEPTED);
+       g_hash_table_insert(__hash_table_parameter_attendee_partstat, (gpointer)"DECLINED", (gpointer)CALENDAR_ATTENDEE_STATUS_DECLINED);
+       g_hash_table_insert(__hash_table_parameter_attendee_partstat, (gpointer)"TENTATIVE", (gpointer)CALENDAR_ATTENDEE_STATUS_TENTATIVE);
+       g_hash_table_insert(__hash_table_parameter_attendee_partstat, (gpointer)"DELEGATED", (gpointer)CALENDAR_ATTENDEE_STATUS_DELEGATED);
+       g_hash_table_insert(__hash_table_parameter_attendee_partstat, (gpointer)"COMPLETED", (gpointer)CALENDAR_ATTENDEE_STATUS_COMPLETED);
+       g_hash_table_insert(__hash_table_parameter_attendee_partstat, (gpointer)"IN-PROCESS", (gpointer)CALENDAR_ATTENDEE_STATUS_IN_PROCESS);
+}
+
+static int __cal_vcalendar_parse_get_parameter_attendee_partstat_index(char *p)
+{
+       return (int)g_hash_table_lookup(__hash_table_parameter_attendee_partstat, p);
+}
+
+static GHashTable *__hash_table_parameter_attendee_cutype = NULL;
+static void __cal_vcalendar_parse_init_table_parameter_attendee_cutype(void)
+{
+       if (__hash_table_parameter_attendee_cutype)
+               return;
+
+       __hash_table_parameter_attendee_cutype = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_parameter_attendee_cutype, (gpointer)"INDIVIDUAL", (gpointer)CALENDAR_ATTENDEE_CUTYPE_INDIVIDUAL);
+       g_hash_table_insert(__hash_table_parameter_attendee_cutype, (gpointer)"GROUP", (gpointer)CALENDAR_ATTENDEE_CUTYPE_GROUP);
+       g_hash_table_insert(__hash_table_parameter_attendee_cutype, (gpointer)"RESOURCE", (gpointer)CALENDAR_ATTENDEE_CUTYPE_RESOURCE);
+       g_hash_table_insert(__hash_table_parameter_attendee_cutype, (gpointer)"ROOM", (gpointer)CALENDAR_ATTENDEE_CUTYPE_ROOM);
+       g_hash_table_insert(__hash_table_parameter_attendee_cutype, (gpointer)"UNKNOWN", (gpointer)CALENDAR_ATTENDEE_CUTYPE_UNKNOWN);
+}
+
+static int __cal_vcalendar_parse_get_parameter_attendee_cutype_index(char *p)
+{
+       return (int)g_hash_table_lookup(__hash_table_parameter_attendee_cutype, p);
+}
+
+static int __cal_vcalendar_parse_attendee_mailto(char *p, calendar_record_h attendee)
+{
+       ENTER();
+       if (NULL == p || NULL == attendee)
+       {
+               ERR("Invalid parameter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+       _cal_record_set_str(attendee, _calendar_attendee.email, p);
+       LEAVE();
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_attendee_cutype(calendar_record_h attendee, char *cursor)
+{
+       __cal_vcalendar_parse_init_table_parameter_attendee_cutype();
+       int cutype = __cal_vcalendar_parse_get_parameter_attendee_cutype_index(cursor);
+       _cal_record_set_int(attendee, _calendar_attendee.cutype, cutype);
+       return CALENDAR_ERROR_NONE;
+}
+static int __cal_vcalendar_parse_attendee_member(calendar_record_h attendee, char *cursor)
+{
+       _cal_record_set_str(attendee, _calendar_attendee.member, cursor);
+       return CALENDAR_ERROR_NONE;
+}
+static int __cal_vcalendar_parse_attendee_role(calendar_record_h attendee, char *cursor)
+{
+       __cal_vcalendar_parse_init_table_parameter_attendee_role();
+       int role = __cal_vcalendar_parse_get_parameter_attendee_role_index(cursor);
+       _cal_record_set_int(attendee, _calendar_attendee.role, role);
+       return CALENDAR_ERROR_NONE;
+}
+static int __cal_vcalendar_parse_attendee_partstat(calendar_record_h attendee, char *cursor)
+{
+       __cal_vcalendar_parse_init_table_parameter_attendee_partstat();
+       int stat = __cal_vcalendar_parse_get_parameter_attendee_partstat_index(cursor);
+       _cal_record_set_int(attendee, _calendar_attendee.status, stat);
+       return CALENDAR_ERROR_NONE;
+}
+static int __cal_vcalendar_parse_attendee_rsvp(calendar_record_h attendee, char *cursor)
+{
+       if (NULL == cursor || strlen(cursor) == 0)
+       {
+               ERR("Invalid paramter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (!strncmp(cursor, "TRUE", strlen("TRUE")))
+       {
+               _cal_record_set_int(attendee, _calendar_attendee.rsvp, 1);
+       }
+       else
+       {
+               _cal_record_set_int(attendee, _calendar_attendee.rsvp, 0);
+       }
+       return CALENDAR_ERROR_NONE;
+}
+static int __cal_vcalendar_parse_attendee_delto(calendar_record_h attendee, char *cursor)
+{
+       _cal_record_set_str(attendee, _calendar_attendee.delegatee_uri, cursor);
+       return CALENDAR_ERROR_NONE;
+}
+static int __cal_vcalendar_parse_attendee_delfrom(calendar_record_h attendee, char *cursor)
+{
+       _cal_record_set_str(attendee, _calendar_attendee.delegator_uri, cursor);
+       return CALENDAR_ERROR_NONE;
+}
+static int __cal_vcalendar_parse_attendee_sent_by(calendar_record_h attendee, char *cursor)
+{
+       return CALENDAR_ERROR_NONE;
+}
+static int __cal_vcalendar_parse_attendee_cn(calendar_record_h attendee, char *cursor)
+{
+       _cal_record_set_str(attendee, _calendar_attendee.name, cursor);
+       return CALENDAR_ERROR_NONE;
+}
+static int __cal_vcalendar_parse_attendee_dir(calendar_record_h attendee, char *cursor)
+{
+       return CALENDAR_ERROR_NONE;
+}
+
+static GHashTable *__hash_table_parameter_attendee_param = NULL;
+static void __cal_vcalendar_parse_init_table_parameter_attendee_param(void)
+{
+       if (__hash_table_parameter_attendee_param)
+               return;
+
+       __hash_table_parameter_attendee_param = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_parameter_attendee_param, (gpointer)"CUTYPE", (gpointer)(__cal_vcalendar_parse_attendee_cutype));
+       g_hash_table_insert(__hash_table_parameter_attendee_param, (gpointer)"MEMBER", (gpointer)(__cal_vcalendar_parse_attendee_member));
+       g_hash_table_insert(__hash_table_parameter_attendee_param, (gpointer)"ROLE", (gpointer)(__cal_vcalendar_parse_attendee_role));
+       g_hash_table_insert(__hash_table_parameter_attendee_param, (gpointer)"PARTSTAT", (gpointer)(__cal_vcalendar_parse_attendee_partstat));
+       g_hash_table_insert(__hash_table_parameter_attendee_param, (gpointer)"RSVP", (gpointer)(__cal_vcalendar_parse_attendee_rsvp));
+       g_hash_table_insert(__hash_table_parameter_attendee_param, (gpointer)"DELEGATED-TO", (gpointer)(__cal_vcalendar_parse_attendee_delto));
+       g_hash_table_insert(__hash_table_parameter_attendee_param, (gpointer)"DELEGATED-FROM", (gpointer)(__cal_vcalendar_parse_attendee_delfrom));
+       g_hash_table_insert(__hash_table_parameter_attendee_param, (gpointer)"SENT-BY", (gpointer)(__cal_vcalendar_parse_attendee_sent_by));
+       g_hash_table_insert(__hash_table_parameter_attendee_param, (gpointer)"CN", (gpointer)(__cal_vcalendar_parse_attendee_cn));
+       g_hash_table_insert(__hash_table_parameter_attendee_param, (gpointer)"DIR", (gpointer)(__cal_vcalendar_parse_attendee_dir));
+}
+
+typedef int (*func_parameter_attendee_param)(calendar_record_h event, char *cursor);
+static int __cal_vcalendar_parse_get_parameter_attendee_param_index(char *p, calendar_record_h event, char *cursor)
+{
+       func_parameter_attendee_param func = g_hash_table_lookup(__hash_table_parameter_attendee_param, p);
+       if (func)
+       {
+               func(event, cursor);
+       }
+       else
+       {
+               DBG("No func");
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_attendee_param(char *p, calendar_record_h attendee)
+{
+       int i;
+       int len = 0;
+       char **t;
+
+       if (NULL == p || NULL == attendee)
+       {
+               ERR("Invalid parameter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       DBG("attendee param[%s]", p);
+       t = g_strsplit(p, ";", -1);
+       if (NULL == t)
+       {
+               ERR("g_strsplit_set() failed");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       __cal_vcalendar_parse_init_table_parameter_attendee_param();
+       len = g_strv_length(t);
+       for (i = 0; i < len; i++)
+       {
+               char **s = g_strsplit(t[i], "=", 2);
+               if (NULL == s)
+               {
+                       ERR("g_strsplit() failed");
+                       break;
+               }
+
+               __cal_vcalendar_parse_get_parameter_attendee_param_index(s[0], attendee, s[1]);
+               g_strfreev(s);
+       }
+       g_strfreev(t);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_attendee(int type, calendar_list_h list, calendar_record_h event, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       // divide mailto firstly.
+       char **t = g_strsplit(p, ":mailto:", 2);
+       {
+               if (NULL == t)
+               {
+                       ERR("g_strsplit_set() failed");
+                       return CALENDAR_ERROR_OUT_OF_MEMORY;
+               }
+       }
+
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_record_h attendee = NULL;
+       ret = calendar_record_create(_calendar_attendee._uri, &attendee);
+       if (NULL == attendee)
+       {
+               ERR("Failed to create attedee(ret:%d)", ret);
+               g_strfreev(t);
+               return ret;
+       }
+       DBG("[%s][%s]", t[0], t[1]);
+       __cal_vcalendar_parse_attendee_param(t[0], attendee);
+       __cal_vcalendar_parse_attendee_mailto(t[1], attendee);
+
+       ret = calendar_record_add_child_record(event, _calendar_event.calendar_attendee, attendee);
+
+       g_strfreev(t);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_categories(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       int ret = CALENDAR_ERROR_NONE;
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = _cal_record_set_str(record, _calendar_event.categories, p);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               break;
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = _cal_record_set_str(record, _calendar_todo.categories, p);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_str() Failed(%d)", ret);
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_extended(int type, calendar_list_h list, calendar_record_h record, char *prop, char *cont)
+{
+       int ret;
+       calendar_record_h extended = NULL;
+
+       ret = calendar_record_create(_calendar_extended_property._uri, &extended);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_record_create() failed");
+               return ret;
+       }
+
+       DBG("key[%s]value[%s]", prop, cont);
+       ret = _cal_record_set_str(extended, _calendar_extended_property.key, prop);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_record_set_str() failed");
+               return ret;
+       }
+
+       int len = strlen(cont);
+       char *mod = calloc(len + 2, sizeof(char));
+       if (NULL == mod)
+       {
+               ERR("calloc() failed");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       snprintf(mod, len + 2, ":%s", cont);
+       ret = _cal_record_set_str(extended, _calendar_extended_property.value, mod);
+       if (mod) free(mod);
+
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_record_set_str() failed");
+               return ret;
+       }
+
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = calendar_record_add_child_record(record, _calendar_event.extended, extended);
+               if (CALENDAR_ERROR_NONE != ret)
+               {
+                       ERR("calendar_record_add_child_record() failed");
+                       return ret;
+               }
+               break;
+
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = calendar_record_add_child_record(record, _calendar_todo.extended, extended);
+               if (CALENDAR_ERROR_NONE != ret)
+               {
+                       ERR("calendar_record_add_child_record() failed");
+                       return ret;
+               }
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_exdate(int type, calendar_list_h list, calendar_record_h event, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       _cal_record_set_str(event, _calendar_event.exdate, p);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_x_allday(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       if (!strncmp(p , "UNSET", strlen("UNSET")))
+       {
+               DBG("X-ALLDAY is unset");
+               return CALENDAR_ERROR_NONE;
+       }
+
+       __g_is_allday = true;
+
+       if (NULL == __g_ucal_local)
+       {
+               DBG("__g_ucal_local is not set yet");
+               return CALENDAR_ERROR_NONE;
+       }
+
+       // re arrange
+       int ret = CALENDAR_ERROR_NONE;
+       int y = 0, m = 0, d = 0;
+       int h = 0, n = 0, s = 0;
+       calendar_time_s st = {0};
+       calendar_time_s et = {0};
+       calendar_time_s ut = {0};
+
+       switch (type)
+       {
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = calendar_record_get_caltime(record, _calendar_event.start_time, &st);
+               warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Failed(%d)", ret);
+               if (CALENDAR_TIME_UTIME == st.type)
+               {
+                       _cal_time_get_component_from_lli(__g_ucal_local, st.time.utime, &y, &m, &d, &h, &n, &s);
+                       st.type = CALENDAR_TIME_LOCALTIME;
+                       st.time.date.year = y;
+                       st.time.date.month = m;
+                       st.time.date.mday = d;
+                       st.time.date.hour = h;
+                       st.time.date.minute = n;
+                       st.time.date.second = s;
+                       ret = _cal_record_set_caltime(record, _calendar_event.start_time, st);
+                       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_caltime() Failed(%d)", ret);
+                       DBG("event start %02d/%02d/%02d %02d:%02d:%02d", y, m, d, h, n, s);
+               }
+
+               ret = calendar_record_get_caltime(record, _calendar_event.end_time, &et);
+               warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Failed(%d)", ret);
+               if (CALENDAR_TIME_UTIME == et.type)
+               {
+                       _cal_time_get_component_from_lli(__g_ucal_local, et.time.utime + 60, &y, &m, &d, &h, &n, &s); // 23:59:00 + 60
+                       et.type = CALENDAR_TIME_LOCALTIME;
+                       et.time.date.year = y;
+                       et.time.date.month = m;
+                       et.time.date.mday = d;
+                       et.time.date.hour = h;
+                       et.time.date.minute = n;
+                       et.time.date.second = s;
+                       ret = _cal_record_set_caltime(record, _calendar_event.end_time, et);
+                       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_caltime() Failed(%d)", ret);
+                       DBG("event end %02d/%02d/%02d %02d:%02d:%02d", y, m, d, h, n, s);
+               }
+               ret = calendar_record_get_caltime(record, _calendar_event.until_time, &ut);
+               warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Failed(%d)", ret);
+               if (CALENDAR_TIME_UTIME == ut.type)
+               {
+                       _cal_time_get_component_from_lli(__g_ucal_local, ut.time.utime, &y, &m, &d, &h, &n, &s);
+                       ut.type = CALENDAR_TIME_LOCALTIME;
+                       ut.time.date.year = y;
+                       ut.time.date.month = m;
+                       ut.time.date.mday = d;
+                       ut.time.date.hour = h;
+                       ut.time.date.minute = n;
+                       ut.time.date.second = s;
+                       ret = _cal_record_set_caltime(record, _calendar_event.until_time, ut);
+                       DBG("event until %02d/%02d/%02d %02d:%02d:%02d", y, m, d, h, n, s);
+               }
+               break;
+
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = calendar_record_get_caltime(record, _calendar_todo.start_time, &st);
+               warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Failed(%d)", ret);
+               if (CALENDAR_TIME_UTIME == st.type)
+               {
+                       _cal_time_get_component_from_lli(__g_ucal_local, st.time.utime, &y, &m, &d, &h, &n, &s);
+                       st.type = CALENDAR_TIME_LOCALTIME;
+                       st.time.date.year = y;
+                       st.time.date.month = m;
+                       st.time.date.mday = d;
+                       st.time.date.hour = h;
+                       st.time.date.minute = n;
+                       st.time.date.second = s;
+                       ret = _cal_record_set_caltime(record, _calendar_todo.start_time, st);
+                       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Failed(%d)", ret);
+                       DBG("todo start %02d %02d %02d", y, m, d);
+               }
+
+               ret = calendar_record_get_caltime(record, _calendar_todo.due_time, &et);
+               warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_get_caltime() Failed(%d)", ret);
+               if (CALENDAR_TIME_UTIME == et.type)
+               {
+                       _cal_time_get_component_from_lli(__g_ucal_local, et.time.utime + 60, &y, &m, &d, &h, &n, &s); // 23:59:00 + 60
+                       et.type = CALENDAR_TIME_LOCALTIME;
+                       et.time.date.year = y;
+                       et.time.date.month = m;
+                       et.time.date.mday = d;
+                       et.time.date.hour = h;
+                       et.time.date.minute = n;
+                       et.time.date.second = s;
+                       ret = _cal_record_set_caltime(record, _calendar_todo.due_time, et);
+                       warn_if(CALENDAR_ERROR_NONE != ret, "_cal_record_set_caltime() Failed(%d)", ret);
+                       DBG("todo due %02d %02d %02d", y, m, d);
+               }
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+/*
+       For ver 1.0 aalarm
+       alarmparts      = 0*3(strnosemi ";") strnosemi
+       ; runTime, snoozeTime, repeatCount, audioContent
+ */
+enum {
+       __AALARM_INVALID = 0,
+       __AALARM_RUNTIME,
+       __AALARM_TYPE,
+       __AALARM_VALUE,
+       __AALARM_SNOOZETIME,
+       __AALARM_REPEATCOUNT,
+       __AALARM_AUDIOCONTENT,
+};
+
+// aalarmparts: runTime, snoozeTime, repeatCount, audioContent
+// ex> TYPE=WAVE;VALUE=CONTENT-ID:19960903T060000;PT15M;4;audio_file
+static int __cal_vcalendar_parse_aalarm(int type, calendar_list_h list, calendar_record_h record, char *p)
+{
+       retv_if(p == NULL, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(strlen(p) == 0, CALENDAR_ERROR_NONE);
+
+       char **t = g_strsplit_set(p, ";:", -1);
+       if (NULL == t)
+       {
+               ERR("g_strsplit_set() failed");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_record_h alarm = NULL;
+       ret = calendar_record_create(_calendar_alarm._uri, &alarm);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_record_create() failed");
+               return ret;
+       }
+
+       int i;
+       int len = g_strv_length(t);
+       for (i = 0; i < len; i++)
+       {
+               DBG("[%s]", t[i]);
+               if (!strncmp(t[i], "TYPE=", strlen("TYPE="))) { // do nothing
+               } else if (!strncmp(t[i], "VALUE=", strlen("VALUE="))) { // do nothing
+               } else if (*t[i] >= '0' && *t[i] <= '9') {
+                       DBG("parse runtime");
+                       int tlen = 0;
+                       tlen = strlen(t[i]);
+
+                       if (tlen < 9) { // repeatCount
+                               int snooze_count = atoi(t[i]);
+                               DBG("repeat count(%d)", snooze_count);
+                               continue;
+                       }
+
+                       int y = 0, m = 0, d = 0;
+                       int h = 0, n = 0, s = 0;
+                       sscanf(t[i], "%04d%02d%02dT%02d%02d%02d", &y, &m, &d, &h, &n, &s);
+                       DBG(CAL_FORMAT_LOCAL_DATETIME, y, m, d, h, n, s);
+
+                       time_t tt_alarm = 0;
+                       struct tm tm_alarm = {0};
+                       tm_alarm.tm_year = y - 1900;
+                       tm_alarm.tm_mon = m - 1;
+                       tm_alarm.tm_mday = d;
+                       tm_alarm.tm_hour = h;
+                       tm_alarm.tm_min = n;
+                       tm_alarm.tm_sec = s;
+
+                       if (tlen == strlen("YYYYMMDDTHHMMSSZ")) { // utime
+                               tt_alarm = timegm(&tm_alarm);
+
+                       } else if (tlen == strlen("YYYYMMDDTHHMMSS")) { // localtime
+                               tt_alarm = timelocal(&tm_alarm);
+
+                       } else {
+                               ERR("Invalid type[%s]", t[i]);
+                               continue;
+                       }
+                       DBG("alarm (%ld)", tt_alarm);
+
+                       // check if alarm time is before of start(event), due(todo)
+                       calendar_time_s st = {0};
+                       if (VCALENDAR_TYPE_VEVENT == type) {
+                               ret = calendar_record_get_caltime(record, _calendar_event.start_time, &st);
+                               warn_if (CALENDAR_ERROR_NONE != ret, "Failed to get start");
+
+                       } else {
+                               ret = calendar_record_get_caltime(record, _calendar_todo.due_time, &st);
+                               warn_if (CALENDAR_ERROR_NONE != ret, "Failed to get due");
+
+                       }
+
+                       bool is_specific = true;
+                       time_t tt_diff = 1;
+                       if (CALENDAR_TIME_UTIME == st.type) {
+                               if (st.time.utime > (long long int)tt_alarm) {
+                                       is_specific = false;
+                                       tt_diff = (time_t)st.time.utime - tt_alarm;
+                                       DBG("before time, diff(%ld)", tt_diff);
+                               }
+
+                       } else {
+                               struct tm tm = {0};
+                               tm.tm_year = st.time.date.year - 1900;
+                               tm.tm_mon = st.time.date.month - 1;
+                               tm.tm_mday = st.time.date.mday;
+                               tm.tm_hour = st.time.date.hour;
+                               tm.tm_min = st.time.date.minute;
+                               tm.tm_sec = st.time.date.second;
+                               time_t tt = timelocal(&tm);
+                               if (tt > tt_alarm) {
+                                       is_specific = false;
+                                       tt_diff = tt - tt_alarm;
+                                       DBG("before time, diff(%ld)", tt_diff);
+                               }
+                       }
+
+                       // if this has second, set unit specific
+                       if (0 != (tt_diff % CALENDAR_ALARM_TIME_UNIT_MINUTE)) {
+                               DBG("time diff needs second, so set unit specific");
+                               is_specific = true;
+                       }
+
+                       // set to alarm
+                       if (true == is_specific) {
+                               _cal_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_SPECIFIC);
+                               calendar_time_s at = {0};
+                               if (CALENDAR_TIME_UTIME == st.type) {
+                                       at.type = CALENDAR_TIME_UTIME;
+                                       at.time.utime = (long long int)tt_alarm;
+                               } else {
+                                       at.type = CALENDAR_TIME_LOCALTIME;
+                                       at.time.date.year = y;
+                                       at.time.date.month = m;
+                                       at.time.date.mday = d;
+                                       at.time.date.hour = h;
+                                       at.time.date.minute = n;
+                                       at.time.date.second = s;
+                               }
+                               _cal_record_set_caltime(alarm, _calendar_alarm.alarm_time, at);
+
+                       } else {
+                               // determine unit
+                               if (0 == (tt_diff % CALENDAR_ALARM_TIME_UNIT_WEEK)) {
+                                       _cal_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_WEEK);
+                                       _cal_record_set_int(alarm, _calendar_alarm.tick, tt_diff / CALENDAR_ALARM_TIME_UNIT_WEEK);
+
+                               } else if (0 == (tt_diff % CALENDAR_ALARM_TIME_UNIT_DAY)) {
+                                       _cal_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_DAY);
+                                       _cal_record_set_int(alarm, _calendar_alarm.tick, tt_diff / CALENDAR_ALARM_TIME_UNIT_DAY);
+
+                               } else if (0 == (tt_diff % CALENDAR_ALARM_TIME_UNIT_HOUR)) {
+                                       _cal_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_HOUR);
+                                       _cal_record_set_int(alarm, _calendar_alarm.tick, tt_diff / CALENDAR_ALARM_TIME_UNIT_HOUR);
+
+                               } else if (0 == (tt_diff % CALENDAR_ALARM_TIME_UNIT_MINUTE)) {
+                                       _cal_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_MINUTE);
+                                       _cal_record_set_int(alarm, _calendar_alarm.tick, tt_diff / CALENDAR_ALARM_TIME_UNIT_MINUTE);
+
+                               } else {
+                                       ERR("Invalid");
+                               }
+                       }
+               } else {
+                       // snoozeTime, audioContent
+               }
+       }
+
+       if (VCALENDAR_TYPE_VEVENT == type) {
+               ret = calendar_record_add_child_record(record, _calendar_event.calendar_alarm, alarm);
+               retvm_if (CALENDAR_ERROR_NONE != ret, ret, "Failed to add alarm");
+       } else {
+               ret = calendar_record_add_child_record(record, _calendar_todo.calendar_alarm, alarm);
+               retvm_if (CALENDAR_ERROR_NONE != ret, ret, "Failed to add alarm");
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static GHashTable *__hash_table_vevent = NULL;
+static void __cal_vcalendar_parse_init_table_vevent(void)
+{
+       if (__hash_table_vevent)
+               return;
+
+       __hash_table_vevent = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"DTSTAMP", (gpointer)(__cal_vcalendar_parse_dtstamp));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"UID", (gpointer)(__cal_vcalendar_parse_uid));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"DTSTART", (gpointer)(__cal_vcalendar_parse_dtstart));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"CREATED", (gpointer)(__cal_vcalendar_parse_created));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"DCREATED", (gpointer)(__cal_vcalendar_parse_created)); // ver 1.0
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"DESCRIPTION", (gpointer)(__cal_vcalendar_parse_description));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"LAST-MOD", (gpointer)(__cal_vcalendar_parse_last_mod));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"LOCATION", (gpointer)(__cal_vcalendar_parse_location));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"PRIORITY", (gpointer)(__cal_vcalendar_parse_priority));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"STATUS", (gpointer)(__cal_vcalendar_parse_status));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"SUMMARY", (gpointer)(__cal_vcalendar_parse_summary));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"RRULE", (gpointer)(__cal_vcalendar_parse_rrule));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"DTEND", (gpointer)(__cal_vcalendar_parse_dtend));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"ATTENDEE", (gpointer)(__cal_vcalendar_parse_attendee));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"CATEGORIES", (gpointer)(__cal_vcalendar_parse_categories));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"AALARM", (gpointer)(__cal_vcalendar_parse_aalarm)); // for ver1.0
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"EXDATE", (gpointer)(__cal_vcalendar_parse_exdate));
+       g_hash_table_insert(__hash_table_vevent, (gpointer)"X-ALLDAY", (gpointer)(__cal_vcalendar_parse_x_allday)); // for ver1.0
+
+}
+
+typedef int (*func_vevent)(int type, calendar_list_h list, calendar_record_h event, char *cont);
+static void __cal_vcalendar_parse_get_vevent_index(int type, calendar_list_h list, calendar_record_h event, char *prop, char *cont)
+{
+       func_vevent func = g_hash_table_lookup(__hash_table_vevent, prop);
+       if (func)
+       {
+               func(type, list, event, cont);
+       }
+       else
+       {
+               if (!strncmp(prop, "X-", strlen("X-")))
+               {
+                       __cal_vcalendar_parse_extended(type, list, event, prop, cont);
+               }
+       }
+}
+
+static char *__search_extension_p(char *cursor, char **extension_p)
+{
+
+       if (NULL == cursor) return NULL;
+       while (*cursor == ' ') cursor++;
+       while (1) {
+               if (!strncmp(cursor, "END:VEVENT", strlen("END:VEVENT"))) return NULL;
+               if (!strncmp(cursor, "X-", strlen("X-"))) {
+                       DBG("found");
+                       if (extension_p) *extension_p = cursor;
+                       while (*cursor != '\n') {
+                               cursor++;
+                       }
+                       cursor++;
+                       return cursor;
+               } else {
+                       while (*cursor != '\n') {
+                               cursor++;
+                       }
+                       cursor++;
+                       continue;
+               }
+       }
+       return NULL;
+}
+
+char *__cal_vcalendar_parse_vevent(calendar_list_h list_sch, calendar_record_h *out_record, void *data)
+{
+       int ret;
+       int has_error = 1;
+       char *prop = NULL, *cont = NULL;
+       char *cursor = NULL;
+       calendar_record_h event = NULL;
+
+       retvm_if(NULL == out_record, NULL, "Invalid parameter(out_record) is NULL");
+       *out_record = NULL;
+
+       ret = calendar_record_create(_calendar_event._uri, &event);
+       retvm_if(CALENDAR_ERROR_NONE != ret, NULL, "calendar_record_create() failed(%d)", ret);
+
+       __g_is_allday = false; // init
+
+       // check previous component: X-ALLDAY for ver1.0, X-LUNAR
+       cursor = (char *)data;
+       char *extension_p = NULL;
+       while ((cursor = __search_extension_p(cursor, &extension_p))) {
+               if (!strncmp(extension_p, "X-ALLDAY", strlen("X-ALLDAY"))) {
+                       if (!strncmp(extension_p + strlen("X-ALLDAY:"), "SET", strlen("SET"))) {
+                               DBG("set allday");
+                               __g_is_allday = true;
+                       }
+               } else if (!strncmp(extension_p, "X-LUNAR", strlen("X-LUNAR"))) {
+                       if (!strncmp(extension_p + strlen("X-LUNAR:"), "SET", strlen("SET"))) {
+                               DBG("set lunar");
+                               ret = calendar_record_set_int(event, _calendar_event.calendar_system_type, CALENDAR_SYSTEM_EAST_ASIAN_LUNISOLAR);
+                               warn_if(CALENDAR_ERROR_NONE != ret, "set system_type is failed(%d)", ret);
+                       }
+               } else {
+
+               }
+       }
+
+       // start
+       __cal_vcalendar_parse_init_table_vevent();
+       cursor = (char *)data;
+       while ((cursor = _cal_vcalendar_parse_read_key_value(cursor, &prop, &cont))) {
+               if (!strncmp(cont, "VALARM", strlen("VALARM"))) {
+                       if (!strncmp(cont, "VALARM", strlen("VALARM"))) {
+                               cursor = _cal_vcalendar_parse_valarm(VCALENDAR_TYPE_VEVENT, event, cursor);
+                       } else {
+                               break;
+                       }
+               } else if (!strncmp(prop, "END", strlen("END"))) {
+                       if (!strncmp(cont, "VEVENT", strlen("VEVENT"))) {
+                               has_error = 0;
+                               break;
+                       }
+                       break;
+               } else {
+                       __cal_vcalendar_parse_get_vevent_index(CALENDAR_BOOK_TYPE_EVENT, list_sch, event, prop, cont);
+               }
+       }
+       __g_is_allday = false; // fini
+
+       if (has_error) {
+               DBG("Has error in vevent, so skip saving");
+               calendar_record_destroy(event, true);
+               return cursor;
+       }
+       *out_record = event;
+       return cursor;
+}
+
+static GHashTable *__hash_table_vtodo = NULL;
+static void __cal_vcalendar_parse_init_table_vtodo(void)
+{
+       if (__hash_table_vtodo)
+               return;
+
+       __hash_table_vtodo = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"DTSTAMP", (gpointer)(__cal_vcalendar_parse_dtstamp));
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"UID", (gpointer)(__cal_vcalendar_parse_uid));
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"COMPLETED", (gpointer)(__cal_vcalendar_parse_completed));
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"CREATED", (gpointer)(__cal_vcalendar_parse_created));
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"DCREATED", (gpointer)(__cal_vcalendar_parse_created)); // ver1.0
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"DESCRIPTION", (gpointer)(__cal_vcalendar_parse_description));
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"DTSTART", (gpointer)(__cal_vcalendar_parse_dtstart));
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"LAST-MOD", (gpointer)(__cal_vcalendar_parse_last_mod));
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"LOCATION", (gpointer)(__cal_vcalendar_parse_location));
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"PERCENT", (gpointer)(__cal_vcalendar_parse_percent));
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"PRIORITY", (gpointer)(__cal_vcalendar_parse_priority));
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"STATUS", (gpointer)(__cal_vcalendar_parse_status));
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"SUMMARY", (gpointer)(__cal_vcalendar_parse_summary));
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"DUE", (gpointer)(__cal_vcalendar_parse_due));
+       g_hash_table_insert(__hash_table_vtodo, (gpointer)"AALARM", (gpointer)(__cal_vcalendar_parse_aalarm)); // for ver1.0
+}
+
+typedef int (*func_vtodo)(int type, calendar_list_h list, calendar_record_h event, char *cont);
+static void __cal_vcalendar_parse_get_vtodo_index(int type, calendar_list_h list, calendar_record_h event, char *prop, char *cont)
+{
+       DBG("----");
+       func_vtodo func = g_hash_table_lookup(__hash_table_vtodo, prop);
+       if (func)
+       {
+               func(type, list, event, cont);
+       }
+       else
+       {
+               if (!strncmp(prop, "X-", strlen("X-")))
+               {
+                       __cal_vcalendar_parse_extended(type, list, event, prop, cont);
+               }
+       }
+}
+
+char *__cal_vcalendar_parse_vtodo(calendar_list_h list_sch, calendar_record_h *out_record, void *data)
+{
+       int ret;
+       int has_error = 1;
+       char *prop = NULL, *cont = NULL;
+       char *cursor = NULL;
+       calendar_record_h todo = NULL;
+
+       retvm_if(NULL == out_record, NULL, "Invalid parameter(out_record) is NULL");
+       *out_record = NULL;
+
+       ret = calendar_record_create(_calendar_todo._uri, &todo);
+       retvm_if(CALENDAR_ERROR_NONE != ret, NULL, "calendar_record_create() failed(%d)", ret);
+
+       __cal_vcalendar_parse_init_table_vtodo();
+       cursor = (char *)data;
+       while ((cursor = _cal_vcalendar_parse_read_key_value(cursor, &prop, &cont))) {
+               DBG("[%s] [%s]", prop, cont);
+               if (!strncmp(prop, "BEGIN", strlen("BEGIN"))) {
+                       if (!strncmp(cont, "VALARM", strlen("VALARM"))) {
+                               cursor = _cal_vcalendar_parse_valarm(VCALENDAR_TYPE_VTODO, todo, cursor);
+                       } else {
+                               break;
+                       }
+               } else if (!strncmp(prop, "END", strlen("END"))) {
+                       if (!strncmp(cont, "VTODO", strlen("VTODO"))) {
+                               has_error = 0;
+                               break;
+                       }
+                       break;
+               } else {
+                       DBG("[%s]", cont);
+                       __cal_vcalendar_parse_get_vtodo_index(CALENDAR_BOOK_TYPE_TODO, list_sch, todo, prop, cont);
+               }
+       }
+       if (has_error)
+       {
+
+               DBG("Has error in vtodo, so skip saving");
+               calendar_record_destroy(todo, true);
+               return cursor;
+       }
+       *out_record = todo;
+       return cursor;
+}
+
+static GHashTable *__hash_table_parameter_alarm_action = NULL;
+static void __cal_vcalendar_parse_init_table_parameter_alarm_action(void)
+{
+       if (__hash_table_parameter_alarm_action)
+               return;
+
+       __hash_table_parameter_alarm_action = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_parameter_alarm_action, (gpointer)"AUDIO", (gpointer)CALENDAR_ALARM_ACTION_AUDIO);
+       g_hash_table_insert(__hash_table_parameter_alarm_action, (gpointer)"DISPLAY", (gpointer)CALENDAR_ALARM_ACTION_DISPLAY);
+       g_hash_table_insert(__hash_table_parameter_alarm_action, (gpointer)"EMAIL", (gpointer)CALENDAR_ALARM_ACTION_EMAIL);
+}
+
+static int __cal_vcalendar_parse_get_parameter_alarm_action_index(char *p)
+{
+       return (int)g_hash_table_lookup(__hash_table_parameter_alarm_action, p);
+}
+
+static int __cal_vcalendar_parse_action(calendar_record_h record, calendar_record_h alarm, void *data)
+{
+       __cal_vcalendar_parse_init_table_parameter_alarm_action();
+       int action = __cal_vcalendar_parse_get_parameter_alarm_action_index((char *)data);
+       _cal_record_set_int(alarm, _calendar_alarm.action, action);
+       return CALENDAR_ERROR_NONE;
+}
+
+/*
+ * TRIGGER;RELATED=END:PT5M
+ * TRIGGER;VALUE=DATE-TIME:19980101T050000Z
+ * TRIGGER:19980403T120000
+ * TRIGGER:-P2D
+ * TRIGGER:P5M
+ * TRIGGER:-PT30M
+ */
+static void __parse_time_value(char *p, calendar_time_s *ct)
+{
+       retm_if (NULL == p, "Invalid parameter: p is NULL");
+
+       int y = 0, m = 0, d = 0;
+       int h = 0, n = 0, s = 0;
+       switch (strlen(p))
+       {
+       case 8: // YYYYMMDD
+               sscanf(p, "%04d%02d%02d", &y, &m, &d);
+               ct->type = CALENDAR_TIME_LOCALTIME;
+               ct->time.date.year = y;
+               ct->time.date.month = m;
+               ct->time.date.mday = d;
+               ct->time.date.hour = 0;
+               ct->time.date.minute = 0;
+               ct->time.date.second = 0;
+               break;
+
+       case 15: // YYYYMMDDTHHMMSS: localtime
+               sscanf(p, "%04d%02d%02dT%02d%02d%02d", &y, &m, &d, &h, &n, &s);
+               ct->type = CALENDAR_TIME_LOCALTIME;
+               ct->time.date.year = y;
+               ct->time.date.month = m;
+               ct->time.date.mday = d;
+               ct->time.date.hour = h;
+               ct->time.date.minute = n;
+               ct->time.date.second = s;
+               break;
+
+       case 16: // YYYYMMDDTHHMMSSZ: unixtime
+               sscanf(p, "%04d%02d%02dT%02d%02d%02dZ", &y, &m, &d, &h, &n, &s);
+               ct->type = CALENDAR_TIME_UTIME;
+               ct->time.utime = _cal_time_get_utime(__g_ucal_gmt, y, m, d, h, n, s);
+               break;
+
+       default:
+               ERR("Invalid parameter:[%s] unable to parse trigger", p);
+               break;
+       }
+}
+
+static void __parse_duration_value(char *p, int size, int *tick, int *unit)
+{
+       retm_if (NULL == p, "Invalid parameter: p is NULL");
+
+       int digit_len = 0;
+       int sign = 1;
+       int t = 0;
+       int u = 0;
+       char buf[8] = {0};
+
+       int i;
+       for (i = 0; i < size; i++) {
+               switch (p[i])
+               {
+               case '+':
+                       break;
+               case '-':
+                       sign = -1;
+                       break;
+               case 'P':
+                       break;
+               case 'T':
+                       break;
+               case 'W':
+                       u = CALENDAR_ALARM_TIME_UNIT_WEEK;
+                       snprintf(buf, digit_len + 1, "%s", p + i - digit_len);
+                       t = atoi(buf) * CALENDAR_ALARM_TIME_UNIT_WEEK;
+                       digit_len = 0;
+                       break;
+               case 'D':
+                       u = CALENDAR_ALARM_TIME_UNIT_DAY;
+                       snprintf(buf, digit_len + 1, "%s", p + i - digit_len);
+                       t += atoi(buf) * CALENDAR_ALARM_TIME_UNIT_DAY;
+                       digit_len = 0;
+                       break;
+               case 'H':
+                       u = CALENDAR_ALARM_TIME_UNIT_HOUR;
+                       snprintf(buf, digit_len + 1, "%s", p + i - digit_len);
+                       t += atoi(buf) * CALENDAR_ALARM_TIME_UNIT_HOUR;
+                       digit_len = 0;
+                       break;
+               case 'M':
+                       u = CALENDAR_ALARM_TIME_UNIT_MINUTE;
+                       snprintf(buf, digit_len + 1, "%s", p + i - digit_len);
+                       t += atoi(buf) * CALENDAR_ALARM_TIME_UNIT_MINUTE;
+                       digit_len = 0;
+                       break;
+               case 'S':
+                       u = CALENDAR_ALARM_TIME_UNIT_SPECIFIC;
+                       snprintf(buf, digit_len + 1, "%s", p + i - digit_len);
+                       t += atoi(buf) * CALENDAR_ALARM_TIME_UNIT_SPECIFIC;
+                       digit_len = 0;
+                       break;
+               default:
+                       if (p[i] >= '0' && p[i] <= '9') {
+                               digit_len++;
+                       } else {
+                               ERR("Invalid value");
+                       }
+                       break;
+               }
+       }
+       if (tick && 0 != u)
+               *tick = (sign * t) / u;
+       if (unit)
+               *unit = u;
+}
+
+static void __cal_vcalendar_parse_trigger(calendar_record_h record, calendar_record_h alarm, void *data)
+{
+       int ret = 0;
+       retm_if (NULL == record, "Invalid parameter: record is NULL");
+       retm_if(data == NULL, "p is NULL");
+       retm_if(strlen(data) == 0, "length is 0");
+
+       char **t = g_strsplit_set(data, ";:", -1);
+       retm_if (NULL == t, "g_strsplit_set() is failed");
+
+       int len = g_strv_length(t);
+       int related_value = 0; // -1: end, due / 1:start
+
+       char *uri = NULL;
+       calendar_record_get_uri_p(record, &uri);
+
+       int record_type = 0;
+       if (!strcmp(_calendar_event._uri, uri)) {
+               record_type = CALENDAR_BOOK_TYPE_EVENT;
+               related_value = 1;
+       } else if (!strcmp(_calendar_todo._uri, uri)) {
+               record_type = CALENDAR_BOOK_TYPE_TODO;
+               related_value = -1;
+       } else {
+               ERR("Invalid type");
+               g_strfreev(t);
+               return;
+       }
+
+       int i;
+       for (i = 0; i < len; i++) {
+               if (!strncmp("RELATED", t[i], strlen("RELATED"))) {
+                       if (!strncmp("END", t[i] + strlen("RELATED="), strlen("END"))) {
+                               related_value = -1;
+                       } else if (!strncmp("START", t[i] + strlen("RELATED="), strlen("START"))) {
+                               related_value = 1;
+                       } else {
+                               ERR("Invalid value[%s]", t[i]);
+                       }
+
+               } else if (!strncmp("VALUE", t[i], strlen("VALUE"))) {
+
+               } else {
+                       if (*t[i] >= '1' && *t[i] <= '9') {
+                               calendar_time_s ct = {0};
+                               __parse_time_value(t[i], &ct);
+                               _cal_record_set_caltime(alarm, _calendar_alarm.alarm_time, ct);
+                               _cal_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_SPECIFIC);
+
+                       } else {
+                               // handle duration value
+                               int tick, unit;
+                               __parse_duration_value(t[i], strlen(t[i]), &tick, &unit);
+                               DBG("tick(%d) unit(%d)", tick, unit);
+
+                               // setting tick, unit is used when 1.event from start 2.todo from due
+                               if (CALENDAR_BOOK_TYPE_EVENT == record_type) {
+                                       if (-1 != related_value) { // from start
+                                               if (unit != CALENDAR_ALARM_TIME_UNIT_SPECIFIC && tick < 0) {
+                                                       // specific means second, before alarm
+                                                       _cal_record_set_int(alarm, _calendar_alarm.tick, -1 * tick);
+                                                       _cal_record_set_int(alarm, _calendar_alarm.tick_unit, unit);
+                                                       DBG("event from start, set before alarm tick(%d) unit(%d)", -1 * tick, unit);
+
+                                               } else { // unit spec
+                                                       calendar_time_s ct = {0};
+                                                       ret = calendar_record_get_caltime(record, _calendar_event.start_time, &ct);
+                                                       if (CALENDAR_ERROR_NONE) {
+                                                               ERR("calendar_record_get_caltime() Fail(%d)", ret);
+                                                               break;
+                                                       }
+                                                       if (ct.type == CALENDAR_TIME_UTIME) {
+                                                               ct.time.utime += tick * unit;
+                                                               DBG("event from start, set after utime(%lld)", ct.time.utime);
+
+                                                       } else { // localtime
+                                                               long long int lli = _cal_time_get_utime(__g_ucal_gmt,
+                                                                               ct.time.date.year, ct.time.date.month, ct.time.date.mday,
+                                                                               ct.time.date.hour, ct.time.date.minute, ct.time.date.second);
+                                                               lli += tick * unit;
+                                                               _cal_time_get_component_from_lli(__g_ucal_gmt, lli,
+                                                                               &ct.time.date.year, &ct.time.date.month, &ct.time.date.mday,
+                                                                               &ct.time.date.hour, &ct.time.date.minute, &ct.time.date.second);
+                                                               DBG("event from start, set after localtime (%02d:%02d:%02d)",
+                                                                               ct.time.date.hour, ct.time.date.minute, ct.time.date.second);
+                                                       }
+                                                       _cal_record_set_caltime(alarm, _calendar_alarm.alarm_time, ct);
+                                                       _cal_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_SPECIFIC);
+                                               }
+
+                                       } else { // from end, so use spec
+                                               calendar_time_s ct = {0};
+                                               ret = calendar_record_get_caltime(record, _calendar_event.end_time, &ct);
+                                               if (CALENDAR_ERROR_NONE) {
+                                                       ERR("calendar_record_get_caltime() Fail(%d)", ret);
+                                                       break;
+                                               }
+
+                                               if (ct.type == CALENDAR_TIME_UTIME) {
+                                                       ct.time.utime += tick * unit;
+                                                       DBG("event from end, set after utime(%lld)", ct.time.utime);
+
+                                               } else {
+                                                       long long int lli = _cal_time_get_utime(__g_ucal_gmt,
+                                                                       ct.time.date.year, ct.time.date.month, ct.time.date.mday,
+                                                                       ct.time.date.hour, ct.time.date.minute, ct.time.date.second);
+                                                       lli += tick * unit;
+                                                       _cal_time_get_component_from_lli(__g_ucal_gmt, lli,
+                                                                       &ct.time.date.year, &ct.time.date.month, &ct.time.date.mday,
+                                                                       &ct.time.date.hour, &ct.time.date.minute, &ct.time.date.second);
+                                                       DBG("event from end, set after localtime (%02d:%02d:%02d)",
+                                                                       ct.time.date.hour, ct.time.date.minute, ct.time.date.second);
+                                               }
+                                               _cal_record_set_caltime(alarm, _calendar_alarm.alarm_time, ct);
+                                               _cal_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_SPECIFIC);
+                                       }
+                               } else { // todo
+                                       if (-1 == related_value) { // from end
+                                               if (unit != CALENDAR_ALARM_TIME_UNIT_SPECIFIC && tick < 0) {
+                                                       _cal_record_set_int(alarm, _calendar_alarm.tick, -1 * tick);
+                                                       _cal_record_set_int(alarm, _calendar_alarm.tick_unit, unit);
+                                                       DBG("todo from end, set before alarm tick(%d) unit(%d)", -1 * tick, unit);
+
+                                               } else { // unit spec
+                                                       calendar_time_s ct = {0};
+                                                       ret = calendar_record_get_caltime(record, _calendar_todo.due_time, &ct);
+                                                       if (CALENDAR_ERROR_NONE) {
+                                                               ERR("calendar_record_get_caltime() Fail(%d)", ret);
+                                                               break;
+                                                       }
+
+                                                       if (ct.type == CALENDAR_TIME_UTIME) {
+                                                               ct.time.utime += tick * unit;
+                                                               DBG("todo from end, set after utime(%lld)", ct.time.utime);
+
+                                                       } else {
+                                                               long long int lli = _cal_time_get_utime(__g_ucal_gmt,
+                                                                               ct.time.date.year, ct.time.date.month, ct.time.date.mday,
+                                                                               ct.time.date.hour, ct.time.date.minute, ct.time.date.second);
+                                                               lli += tick * unit;
+                                                               _cal_time_get_component_from_lli(__g_ucal_gmt, lli,
+                                                                               &ct.time.date.year, &ct.time.date.month, &ct.time.date.mday,
+                                                                               &ct.time.date.hour, &ct.time.date.minute, &ct.time.date.second);
+                                                               DBG("todo from end, set after localtime (%02d:%02d:%02d)",
+                                                                               ct.time.date.hour, ct.time.date.minute, ct.time.date.second);
+                                                       }
+                                                       _cal_record_set_caltime(alarm, _calendar_alarm.alarm_time, ct);
+                                                       _cal_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_SPECIFIC);
+                                               }
+
+                                       } else { // from start
+                                               ERR("In todo, setting alarm related start time is error, use event");
+
+                                       }
+                               }
+                       }
+               }
+       }
+       g_strfreev(t);
+}
+
+static int __cal_vcalendar_parse_repeat(calendar_record_h record, calendar_record_h alarm, void *data)
+{
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_alarm_attach(calendar_record_h record, calendar_record_h alarm, void *data)
+{
+       if (NULL == data || 0 == strlen(data))
+       {
+               ERR("Invalid paramter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       _cal_record_set_str(alarm, _calendar_alarm.attach, (char *)data);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_alarm_description(calendar_record_h record, calendar_record_h alarm, void *data)
+{
+       if (NULL == data || 0 == strlen(data))
+       {
+               ERR("Invalid paramter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       _cal_record_set_str(alarm, _calendar_alarm.description, (char *)data);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_alarm_summary(calendar_record_h record, calendar_record_h alarm, void *data)
+{
+       if (NULL == data || 0 == strlen(data))
+       {
+               ERR("Invalid paramter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       _cal_record_set_str(alarm, _calendar_alarm.summary, (char *)data);
+       return CALENDAR_ERROR_NONE;
+}
+
+static GHashTable *__hash_table_component_valarm = NULL;
+static void __cal_vcalendar_parse_init_table_component_valarm(void)
+{
+       if (__hash_table_component_valarm)
+               return;
+
+       __hash_table_component_valarm = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_component_valarm, (gpointer)"ACTION", (gpointer)(__cal_vcalendar_parse_action));
+       g_hash_table_insert(__hash_table_component_valarm, (gpointer)"TRIGGER", (gpointer)(__cal_vcalendar_parse_trigger));
+       g_hash_table_insert(__hash_table_component_valarm, (gpointer)"REPEAT", (gpointer)(__cal_vcalendar_parse_repeat));
+       //      g_hash_table_insert(__hash_table_component_valarm, (gpointer)"DURATION", (gpointer)(__cal_vcalendar_parse_duration_alarm)); // not support
+       g_hash_table_insert(__hash_table_component_valarm, (gpointer)"ATTACH", (gpointer)(__cal_vcalendar_parse_alarm_attach));
+       g_hash_table_insert(__hash_table_component_valarm, (gpointer)"DESCRIPTION", (gpointer)(__cal_vcalendar_parse_alarm_description));
+       g_hash_table_insert(__hash_table_component_valarm, (gpointer)"SUMMARY", (gpointer)(__cal_vcalendar_parse_alarm_summary));
+}
+
+typedef int (*func_component_valarm)(calendar_record_h record, calendar_record_h alarm, void *data);
+static int __cal_vcalendar_parse_get_component_valarm_index(calendar_record_h record, char *p, calendar_record_h alarm, void *cursor)
+{
+       func_component_valarm func = g_hash_table_lookup(__hash_table_component_valarm, p);
+       if (func)
+       {
+               func(record, alarm, cursor);
+       }
+       else
+       {
+               DBG("No func");
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+char *_cal_vcalendar_parse_valarm(int type, calendar_record_h record, void *data)
+{
+       ENTER();
+       int ret;
+       int has_error = 1;
+       char *prop = NULL, *cont = NULL;
+       char *cursor = (char *)data;
+       calendar_record_h alarm = NULL;
+
+       ret = calendar_record_create(_calendar_alarm._uri, &alarm);
+       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_create() Failed(%d)", ret);
+
+       __cal_vcalendar_parse_init_table_component_valarm();
+
+       while ((cursor = _cal_vcalendar_parse_read_key_value(cursor, &prop, &cont))) {
+               if (!strncmp(prop, "BEGIN", strlen("BEGIN"))) {
+                       break;
+
+               } else if (!strncmp(prop, "END", strlen("END"))) {
+                       if (!strncmp(cont, "VALARM", strlen("VALARM")))
+                       {
+                               has_error = 0;
+                               break;
+                       }
+                       break;
+               }
+               __cal_vcalendar_parse_get_component_valarm_index(record, prop, alarm, cont);
+       }
+       if (has_error)
+       {
+               DBG("Has error in timezone, so skip saving");
+               calendar_record_destroy(alarm, true);
+               return cursor;
+       }
+
+       switch (type) {
+       case VCALENDAR_TYPE_VEVENT:
+               ret = calendar_record_add_child_record(record, _calendar_event.calendar_alarm, alarm);
+               warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_add_child_record() Failed(%d)", ret);
+               break;
+       case VCALENDAR_TYPE_VTODO:
+               ret = calendar_record_add_child_record(record, _calendar_todo.calendar_alarm, alarm);
+               warn_if(CALENDAR_ERROR_NONE != ret, "calendar_record_add_child_record() Failed(%d)", ret);
+               break;
+       }
+       return cursor;
+}
+
+/*
+ * parse vtimezone
+ */
+enum {
+       VTIMEZONE_STD_DTSTART = 0x0,
+       VTIMEZONE_STD_TZOFFSETFROM,
+       VTIMEZONE_STD_TZOFFSETTO,
+       VTIMEZONE_STD_MAX,
+};
+
+static int __cal_vcalendar_parse_vtimezone_std_dtstart(calendar_record_h timezone, void *data)
+{
+       int y, m, d, h, n, s;
+       int nth = 0, wday = 0;
+       long long int utime;
+       char *p = (char *)data;
+
+       if (NULL == timezone)
+       {
+               ERR("Invalid parameter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       sscanf(p, "%04d%02d%02dT%02d%02d%02d", &y, &m, &d, &h, &n, &s);
+       utime = _cal_time_convert_itol(NULL, y, m, d, h, n, s);
+       _cal_time_ltoi2(NULL, utime, &nth, &wday);
+       DBG("timezone dtstart(%04d-%02d-%02d %02d:%02d:%02d", y, m, d, h, n, s);
+       DBG("timezone day of week(%d/%d)", nth, wday);
+       _cal_record_set_int(timezone, _calendar_timezone.standard_start_month, m);
+       _cal_record_set_int(timezone, _calendar_timezone.standard_start_position_of_week, nth);
+       _cal_record_set_int(timezone, _calendar_timezone.standard_start_day, wday);
+       _cal_record_set_int(timezone, _calendar_timezone.standard_start_hour, h);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_vtimezone_std_tzoffsetfrom(calendar_record_h timezone, void *data)
+{
+       return 0;
+}
+
+static int __cal_vcalendar_parse_vtimezone_std_tzoffsetto(calendar_record_h timezone, void *data)
+{
+       int h, m;
+       char *p = (char *)data;
+       char c;
+       cal_timezone_s *tz = (cal_timezone_s *)timezone;
+
+       if (NULL == timezone)
+       {
+               ERR("Invalid parameter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       sscanf(p, "%c%02d%02d", &c, &h, &m);
+       DBG("timezone standard offsetto(%c)(%02d)(%02d)", c, h, m);
+
+       int offset = h * 60 + m;
+       if (c == '-')
+       {
+               offset *= -1;
+       }
+       if (tz->day_light_bias)
+       {
+               // this means daylight is set before gmt offset
+               _cal_record_set_int(timezone, _calendar_timezone.day_light_bias,
+                               tz->day_light_bias - offset);
+       }
+       _cal_record_set_int(timezone, _calendar_timezone.tz_offset_from_gmt, offset);
+
+       if (NULL == __g_ucal_local)
+       {
+               // set ucal but not support min
+               char buf[256] = {0};
+               snprintf(buf, sizeof(buf), "Etc/GMT%c%d", c == '-' ? '+' : '-', h);
+               DBG("[%s]", buf);
+               __g_ucal_local = _cal_time_get_ucal(buf, 1); // set wkst sunday
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+struct _record_func _vtimezone_std[VTIMEZONE_STD_MAX] =
+{
+       {"DTSTART", __cal_vcalendar_parse_vtimezone_std_dtstart },
+       {"TZOFFSETFROM", __cal_vcalendar_parse_vtimezone_std_tzoffsetfrom },
+       {"TZOFFSETTO", __cal_vcalendar_parse_vtimezone_std_tzoffsetto }
+};
+
+char *_cal_vcalendar_parse_standard(calendar_record_h timezone, void *data)
+{
+       DBG("[%s]", __func__);
+       int i;
+       char *prop = NULL, *cont = NULL;
+       char *cursor = (char *)data;
+
+       while ((cursor = _cal_vcalendar_parse_read_key_value(cursor, &prop, &cont))) {
+               if (!strncmp(prop, "END", strlen("END"))) {
+                       break;
+               }
+
+               for (i = 0; i < VTIMEZONE_STD_MAX; i++)
+               {
+                       if (!strncmp(prop, _vtimezone_std[i].prop, strlen(_vtimezone_std[i].prop))) {
+                               _vtimezone_std[i].func(timezone, cont);
+                               break;
+                       }
+               }
+       }
+       return cursor;
+}
+
+enum {
+       VTIMEZONE_DST_DTSTART = 0x0,
+       VTIMEZONE_DST_TZOFFSETFROM,
+       VTIMEZONE_DST_TZOFFSETTO,
+       VTIMEZONE_DST_MAX,
+};
+
+static int __cal_vcalendar_parse_vtimezone_dst_dtstart(calendar_record_h timezone, void *data)
+{
+       int y, m, d, h, n, s;
+       int nth = 0, wday = 0;
+       long long int utime;
+       char *p = (char *)data;
+
+       if (NULL == timezone)
+       {
+               ERR("Invalid parameter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       sscanf(p, "%04d%02d%02dT%02d%02d%02d", &y, &m, &d, &h, &n, &s);
+       utime = _cal_time_convert_itol(NULL, y, m, d, h, n, s);
+       _cal_time_ltoi2(NULL, utime, &nth, &wday);
+       DBG("timezone daylight(%04d-%02d-%02d %02d:%02d:%02d", y, m, d, h, n, s);
+       DBG("timezone daylight day of week(%dth/%d)", nth, wday);
+       _cal_record_set_int(timezone, _calendar_timezone.day_light_start_month, m);
+       _cal_record_set_int(timezone, _calendar_timezone.day_light_start_position_of_week, nth);
+       _cal_record_set_int(timezone, _calendar_timezone.day_light_start_day, wday);
+       _cal_record_set_int(timezone, _calendar_timezone.day_light_start_hour, h);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_vcalendar_parse_vtimezone_dst_tzoffsetfrom(calendar_record_h timezone, void *data)
+{
+       return 0;
+}
+
+static int __cal_vcalendar_parse_vtimezone_dst_tzoffsetto(calendar_record_h timezone, void *data)
+{
+       int h, m;
+       char *p = (char *)data;
+       char c;
+       cal_timezone_s *tz = (cal_timezone_s *)timezone;
+
+       if (NULL == timezone)
+       {
+               ERR("Invalid parameter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       sscanf(p, "%c%02d%02d", &c, &h, &m);
+       DBG("timezone offsetto(%c)(%02d)(%02d)", c, h, m);
+       if (c == '-')
+       {
+               h *= -1;
+       }
+       _cal_record_set_int(timezone, _calendar_timezone.day_light_bias,
+                       (h * 60 + m) - tz->tz_offset_from_gmt);
+       return CALENDAR_ERROR_NONE;
+}
+
+struct _record_func _vtimezone_dst[VTIMEZONE_STD_MAX] =
+{
+       {"DTSTART", __cal_vcalendar_parse_vtimezone_dst_dtstart },
+       {"TZOFFSETFROM", __cal_vcalendar_parse_vtimezone_dst_tzoffsetfrom },
+       {"TZOFFSETTO", __cal_vcalendar_parse_vtimezone_dst_tzoffsetto }
+};
+
+char *_cal_vcalendar_parse_daylight(calendar_record_h timezone, void *data)
+{
+       ENTER();
+       int i;
+       char *prop = NULL, *cont = NULL;
+       char *cursor = (char *)data;
+
+       while ((cursor = _cal_vcalendar_parse_read_key_value(cursor, &prop, &cont))) {
+               if (!strncmp(prop, "END", strlen("END"))) {
+                       break;
+               }
+
+               for (i = 0; i < VTIMEZONE_DST_MAX; i++)
+               {
+                       if (!strncmp(prop, _vtimezone_dst[i].prop, strlen(_vtimezone_dst[i].prop))) {
+                               _vtimezone_dst[i].func(timezone, cont);
+                               break;
+                       }
+               }
+       }
+       LEAVE();
+       return cursor;
+}
+
+char *__cal_vcalendar_parse_vtimezone(calendar_list_h list_sch, calendar_record_h *out_record, void *data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       int has_error = 1;
+       char *prop = NULL, *cont = NULL;
+       char *cursor = (char *)data;
+       calendar_record_h timezone = NULL;
+
+       retvm_if(NULL == out_record, NULL, "Invalid parameter(out_record) is NULL");
+       *out_record = NULL;
+
+       ret = calendar_record_create(_calendar_timezone._uri, &timezone);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_record_create() failed");
+               return NULL;
+       }
+
+       while ((cursor = _cal_vcalendar_parse_read_key_value(cursor, &prop, &cont)))
+       {
+               if (!strncmp(prop, "TZID", strlen("TZID")))
+               {
+                       if (__g_tzid) {
+                               free(__g_tzid);
+                               __g_tzid = strdup(cont);
+                       }
+                       _cal_record_set_str(timezone, _calendar_timezone.standard_name, cont);
+                       _cal_record_set_str(timezone, _calendar_timezone.day_light_name, cont);
+                       DBG("timezone[%s]", cont);
+               }
+               else if (!strncmp(prop, "BEGIN", strlen("BEGIN")))
+               {
+                       if (!strncmp(cont, "STANDARD", strlen("STANDARD")))
+                       {
+                               cursor = _cal_vcalendar_parse_standard(timezone, cursor);
+                       }
+                       else if (!strncmp(cont, "DAYLIGHT", strlen("DAYLIGHT")))
+                       {
+                               cursor = _cal_vcalendar_parse_daylight(timezone, cursor);
+                       }
+                       else
+                       {
+                               DBG("Error");
+                       }
+               }
+               else if (!strncmp(prop, "END", strlen("END")))
+               {
+                       if (!strncmp(cont, "VTIMEZONE", strlen("VTIMEZONE")))
+                       {
+                               has_error = 0;
+                               break;
+                       }
+                       else
+                       {
+                               DBG("Error");
+                       }
+               }
+               else
+               {
+                       DBG("Error");
+               }
+       }
+       if (has_error)
+       {
+               DBG("Has error in timezone, so skip saving");
+               calendar_record_destroy(timezone, true);
+               return cursor;
+       }
+
+       *out_record = timezone;
+       return cursor;
+}
+
+int __cal_vcalendar_parse_begin_vcalendar(void)
+{
+       __g_version = 2; // set default version 2.0
+       if (NULL == __g_ucal_gmt)
+       {
+               __g_ucal_gmt = _cal_time_get_ucal(CAL_TZID_GMT, -1);
+       }
+       return 0;
+}
+
+char *__cal_vcalendar_parse_end_vcalendar(calendar_list_h list_sch, calendar_record_h *out_record, void *data)
+{
+       ENTER();
+       retvm_if(NULL == out_record, NULL, "Invalid parameter(out_record) is NULL");
+       LEAVE();
+       return NULL;
+}
+
+void __cal_vcalendar_parse_fini(void)
+{
+       ENTER();
+       if (__g_ucal_gmt)
+       {
+               ucal_close(__g_ucal_gmt);
+               __g_ucal_gmt = NULL;
+       }
+       if (__g_tzid)
+       {
+               free(__g_tzid);
+               __g_tzid = NULL;
+       }
+       if (__g_ucal_local)
+       {
+               ucal_close(__g_ucal_local);
+               __g_ucal_local = NULL;
+       }
+       LEAVE();
+}
+
+static GHashTable *__hash_table_component = NULL;
+static void __cal_vcalendar_parse_init_table_component(void)
+{
+       if (__hash_table_component)
+               return;
+
+       __hash_table_component = g_hash_table_new(g_str_hash, g_str_equal);
+       g_hash_table_insert(__hash_table_component, (gpointer)"VEVENT", (gpointer)(__cal_vcalendar_parse_vevent));
+       g_hash_table_insert(__hash_table_component, (gpointer)"VTODO", (gpointer)(__cal_vcalendar_parse_vtodo));
+       g_hash_table_insert(__hash_table_component, (gpointer)"VTIMEZONE", (gpointer)(__cal_vcalendar_parse_vtimezone));
+       g_hash_table_insert(__hash_table_component, (gpointer)"VCALENDAR", (gpointer)(__cal_vcalendar_parse_end_vcalendar));
+}
+
+typedef char *(*func_component)(calendar_list_h list_sch, calendar_record_h *out_record, void *data);
+static char *__cal_vcalendar_parse_get_component_index(char *p, calendar_list_h list, calendar_record_h *out_record, char *cursor)
+{
+       retvm_if (NULL == p, NULL, "invalid parameter: p is NULL");
+
+       func_component func = g_hash_table_lookup(__hash_table_component, p);
+       if (func) {
+               return func(list, out_record, cursor);
+       }
+       else {
+               DBG("No func");
+               return NULL;
+       }
+}
+
+/* TZ:+05
+ * TZ:
+ * TZ:+5
+ * TZ:5:30
+ * TZ:+05:30
+ */
+static void __parse_tz(const char *tz, int *h, int *m)
+{
+       retm_if(NULL == tz, "Invalid parameter: tz is NULL");
+
+       char **t = g_strsplit(tz, ":", -1);
+       retm_if(NULL == t, "g_strsplit() is NULL");
+
+       int sign = 0;
+       if (*t[0] == '-') sign = -1;
+       else if (*t[0] == '+') sign = 1;
+       else sign = 0;
+
+       if (0 == strlen(t[0])) {
+               ERR("No hour");
+               g_strfreev(t);
+               return;
+       }
+
+       char buf[8] = {0};
+       if (sign) {
+               snprintf(buf, strlen(t[0]), "%s", t[0] + 1);
+       } else {
+               sign = 1;
+               snprintf(buf, strlen(t[0]) + 1, "%s", t[0]);
+       }
+       if (h) *h = sign * atoi(buf);
+
+       if (1 == g_strv_length(t)) {
+               if (m) *m = 0;
+               g_strfreev(t);
+               return;
+       }
+
+       snprintf(buf, strlen(t[1]) + 1, "%s", t[1]);
+       if (m) *m = atoi(buf);
+
+       g_strfreev(t);
+}
+
+int _cal_vcalendar_parse_vcalendar_object(char *vcalendar_object, calendar_list_h list, vcalendar_foreach_s *foreach_data)
+{
+       DBG("[%s]", __func__);
+       calendar_error_e ret = CALENDAR_ERROR_NONE;
+       char *prop = NULL, *cont = NULL;
+       char *cursor = vcalendar_object;
+
+       retvm_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: list is NULL");
+
+       _cal_vcalendar_parse_unfolding(vcalendar_object);
+       __cal_vcalendar_parse_begin_vcalendar();
+
+       while ((cursor = _cal_vcalendar_parse_read_key_value(cursor, &prop, &cont))) {
+               if (prop == NULL || cont == NULL) {
+                       ERR("Failed to parse");
+                       ret = CALENDAR_ERROR_INVALID_PARAMETER;
+                       break;
+               }
+
+               if (!strncmp(prop, "VERSION", strlen("VERSION"))) { // check version
+                       if (!strncmp(cont, "1.0", strlen("1.0"))) {
+                               __g_version = 1;
+                       }
+                       continue;
+               }
+               if (!strncmp(prop, "TZ", strlen("TZ"))) // TZ:+05:30
+               {
+                       int h = 0, m = 0;
+                       __parse_tz(cont, &h, &m);
+
+                       char buf[32] = {0};
+                       if (0 == m) {
+                               snprintf(buf, sizeof(buf), "Etc/GMT%s%d", h < 0 ? "+" : "-", h);
+                       } else {
+                               _cal_time_get_registered_tzid_with_offset(h * 3600 + m * 60, buf, sizeof(buf));
+                       }
+                       DBG("set tzid [%s]", buf);
+
+                       __g_tzid= strdup(buf);
+                       __g_ucal_local = _cal_time_get_ucal(__g_tzid, -1);
+                       continue;
+               }
+
+               if (!strncmp(prop, "BEGIN", strlen("BEGIN")))
+                       break;
+
+               else if (!strncmp(prop, "END", strlen("END")))
+                       break;
+       }
+
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("parse failed(%d)", ret);
+               return ret;
+       }
+
+       __cal_vcalendar_parse_init_table_component();
+
+       int count = 0;
+       do {
+               calendar_record_h record = NULL;
+               cursor = __cal_vcalendar_parse_get_component_index(cont, list, &record, cursor);
+               if (record) {
+                       ret = calendar_list_add(list, record);
+                       warn_if(CALENDAR_ERROR_NONE != ret, "calendar_list_add() Failed(%d)", ret);
+                       if (foreach_data) {
+                               foreach_data->ret = foreach_data->callback(record, foreach_data->user_data);
+                               if (false == foreach_data->ret)
+                                       break;
+                       }
+               }
+               if (NULL == cursor)
+                       break;
+               count++;
+       } while ((cursor = _cal_vcalendar_parse_read_key_value(cursor, &prop, &cont)));
+
+       __cal_vcalendar_parse_fini();
+
+       warn_if(0 == count, "No record");
+       return ret;
+}
+
diff --git a/common/cal_vcalendar_parse.h b/common/cal_vcalendar_parse.h
new file mode 100644 (file)
index 0000000..0d4d6c6
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_VCALENDAR_PARSE_H__
+#define __CALENDAR_SVC_VCALENDAR_PARSE_H__
+
+#include "calendar_vcalendar.h"
+
+typedef struct {
+       calendar_vcalendar_parse_cb callback;
+       void *user_data;
+       bool ret;
+} vcalendar_foreach_s;
+
+char* _cal_vcalendar_parse_remove_space(char *src);
+int _cal_vcalendar_parse_unfolding(char *stream);
+char* _cal_vcalendar_parse_read_line(char *stream, char **line);
+char* _cal_vcalendar_parse_read_key_value(char *stream, char **prop, char **cont);
+int _cal_vcalendar_parse_vcalendar_object(char *vcalendar_object_stream, calendar_list_h list, vcalendar_foreach_s *foreach_data);
+
+#endif // __CALENDAR_SVC_VCALENDAR_PARSE_H__
diff --git a/common/cal_view.c b/common/cal_view.c
new file mode 100644 (file)
index 0000000..eebd9b8
--- /dev/null
@@ -0,0 +1,1159 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib.h>
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_mutex.h"
+
+// !! TODO : please check ids number
+API const _calendar_book_property_ids   _calendar_book =
+{
+       ._uri = CALENDAR_VIEW_CALENDAR,
+       .id = CAL_PROPERTY_CALENDAR_ID,
+       .uid = CAL_PROPERTY_CALENDAR_UID,
+       .name = CAL_PROPERTY_CALENDAR_NAME,
+       .description = CAL_PROPERTY_CALENDAR_DESCRIPTION,
+       .color = CAL_PROPERTY_CALENDAR_COLOR,
+       .location = CAL_PROPERTY_CALENDAR_LOCATION,
+       .visibility = CAL_PROPERTY_CALENDAR_VISIBILITY,
+       .sync_event = CAL_PROPERTY_CALENDAR_SYNC_EVENT,
+       .account_id = CAL_PROPERTY_CALENDAR_ACCOUNT_ID,
+       .store_type = CAL_PROPERTY_CALENDAR_STORE_TYPE,
+       .sync_data1 = CAL_PROPERTY_CALENDAR_SYNC_DATA1,
+       .sync_data2 = CAL_PROPERTY_CALENDAR_SYNC_DATA2,
+       .sync_data3 = CAL_PROPERTY_CALENDAR_SYNC_DATA3,
+       .sync_data4 = CAL_PROPERTY_CALENDAR_SYNC_DATA4,
+       .mode = CAL_PROPERTY_CALENDAR_MODE
+};
+
+API const _calendar_event_property_ids   _calendar_event =
+{
+       ._uri = CALENDAR_VIEW_EVENT,
+       .id = CAL_PROPERTY_EVENT_ID,
+       .calendar_book_id = CAL_PROPERTY_EVENT_CALENDAR_ID,
+       .summary = CAL_PROPERTY_EVENT_SUMMARY,
+       .description = CAL_PROPERTY_EVENT_DESCRIPTION,
+       .location = CAL_PROPERTY_EVENT_LOCATION,
+       .categories = CAL_PROPERTY_EVENT_CATEGORIES,
+       .exdate = CAL_PROPERTY_EVENT_EXDATE,
+       .event_status = CAL_PROPERTY_EVENT_EVENT_STATUS,
+       .priority = CAL_PROPERTY_EVENT_PRIORITY,
+       .timezone = CAL_PROPERTY_EVENT_TIMEZONE,
+       .person_id = CAL_PROPERTY_EVENT_CONTACT_ID,
+       .busy_status = CAL_PROPERTY_EVENT_BUSY_STATUS,
+       .sensitivity = CAL_PROPERTY_EVENT_SENSITIVITY,
+       .uid = CAL_PROPERTY_EVENT_UID,
+       .organizer_name = CAL_PROPERTY_EVENT_ORGANIZER_NAME,
+       .organizer_email = CAL_PROPERTY_EVENT_ORGANIZER_EMAIL,
+       .meeting_status = CAL_PROPERTY_EVENT_MEETING_STATUS,
+       .original_event_id = CAL_PROPERTY_EVENT_ORIGINAL_EVENT_ID,
+       .latitude = CAL_PROPERTY_EVENT_LATITUDE,
+       .longitude = CAL_PROPERTY_EVENT_LONGITUDE,
+       .email_id = CAL_PROPERTY_EVENT_EMAIL_ID,
+       .created_time = CAL_PROPERTY_EVENT_CREATED_TIME,
+       .last_modified_time = CAL_PROPERTY_EVENT_LAST_MODIFIED_TIME,
+       .is_deleted = CAL_PROPERTY_EVENT_IS_DELETED,
+       .freq = CAL_PROPERTY_EVENT_FREQ,
+       .range_type = CAL_PROPERTY_EVENT_RANGE_TYPE,
+       .until_time = CAL_PROPERTY_EVENT_UNTIL,
+       .count = CAL_PROPERTY_EVENT_COUNT,
+       .interval = CAL_PROPERTY_EVENT_INTERVAL,
+       .bysecond = CAL_PROPERTY_EVENT_BYSECOND,
+       .byminute = CAL_PROPERTY_EVENT_BYMINUTE,
+       .byhour = CAL_PROPERTY_EVENT_BYHOUR,
+       .byday = CAL_PROPERTY_EVENT_BYDAY,
+       .bymonthday = CAL_PROPERTY_EVENT_BYMONTHDAY,
+       .byyearday = CAL_PROPERTY_EVENT_BYYEARDAY,
+       .byweekno = CAL_PROPERTY_EVENT_BYWEEKNO,
+       .bymonth = CAL_PROPERTY_EVENT_BYMONTH,
+       .bysetpos = CAL_PROPERTY_EVENT_BYSETPOS,
+       .wkst = CAL_PROPERTY_EVENT_WKST,
+       .recurrence_id = CAL_PROPERTY_EVENT_RECURRENCE_ID,
+       .rdate = CAL_PROPERTY_EVENT_RDATE,
+       .has_attendee = CAL_PROPERTY_EVENT_HAS_ATTENDEE,
+       .has_alarm = CAL_PROPERTY_EVENT_HAS_ALARM,
+       .calendar_system_type = CAL_PROPERTY_EVENT_CALENDAR_SYSTEM_TYPE,
+       .sync_data1 = CAL_PROPERTY_EVENT_SYNC_DATA1,
+       .sync_data2 = CAL_PROPERTY_EVENT_SYNC_DATA2,
+       .sync_data3 = CAL_PROPERTY_EVENT_SYNC_DATA3,
+       .sync_data4 = CAL_PROPERTY_EVENT_SYNC_DATA4,
+       .start_time = CAL_PROPERTY_EVENT_START,
+       .start_tzid = CAL_PROPERTY_EVENT_START_TZID,
+       .end_time = CAL_PROPERTY_EVENT_END,
+       .end_tzid = CAL_PROPERTY_EVENT_END_TZID,
+       .calendar_alarm = CAL_PROPERTY_EVENT_CALENDAR_ALARM,
+       .calendar_attendee = CAL_PROPERTY_EVENT_CALENDAR_ATTENDEE,
+       .exception = CAL_PROPERTY_EVENT_EXCEPTION,
+       .extended = CAL_PROPERTY_EVENT_EXTENDED,
+       .is_allday = CAL_PROPERTY_EVENT_IS_ALLDAY
+};
+
+API const _calendar_todo_property_ids   _calendar_todo =
+{
+       ._uri = CALENDAR_VIEW_TODO,
+       .id = CAL_PROPERTY_TODO_ID,
+       .calendar_book_id = CAL_PROPERTY_TODO_CALENDAR_ID,
+       .summary = CAL_PROPERTY_TODO_SUMMARY,
+       .description = CAL_PROPERTY_TODO_DESCRIPTION,
+       .location = CAL_PROPERTY_TODO_LOCATION,
+       .categories = CAL_PROPERTY_TODO_CATEGORIES,
+       .todo_status = CAL_PROPERTY_TODO_TODO_STATUS,
+       .priority = CAL_PROPERTY_TODO_PRIORITY,
+       .sensitivity = CAL_PROPERTY_TODO_SENSITIVITY,
+       .uid = CAL_PROPERTY_TODO_UID,
+       .latitude = CAL_PROPERTY_TODO_LATITUDE,
+       .longitude = CAL_PROPERTY_TODO_LONGITUDE,
+       .created_time = CAL_PROPERTY_TODO_CREATED_TIME,
+       .last_modified_time = CAL_PROPERTY_TODO_LAST_MODIFIED_TIME,
+       .completed_time = CAL_PROPERTY_TODO_COMPLETED_TIME,
+       .progress = CAL_PROPERTY_TODO_PROGRESS,
+       .is_deleted = CAL_PROPERTY_TODO_IS_DELETED,
+       .freq = CAL_PROPERTY_TODO_FREQ,
+       .range_type = CAL_PROPERTY_TODO_RANGE_TYPE,
+       .until_time = CAL_PROPERTY_TODO_UNTIL,
+       .count = CAL_PROPERTY_TODO_COUNT,
+       .interval = CAL_PROPERTY_TODO_INTERVAL,
+       .bysecond = CAL_PROPERTY_TODO_BYSECOND,
+       .byminute = CAL_PROPERTY_TODO_BYMINUTE,
+       .byhour = CAL_PROPERTY_TODO_BYHOUR,
+       .byday = CAL_PROPERTY_TODO_BYDAY,
+       .bymonthday = CAL_PROPERTY_TODO_BYMONTHDAY,
+       .byyearday = CAL_PROPERTY_TODO_BYYEARDAY,
+       .byweekno = CAL_PROPERTY_TODO_BYWEEKNO,
+       .bymonth = CAL_PROPERTY_TODO_BYMONTH,
+       .bysetpos = CAL_PROPERTY_TODO_BYSETPOS,
+       .wkst = CAL_PROPERTY_TODO_WKST,
+       .has_alarm = CAL_PROPERTY_TODO_HAS_ALARM,
+       .sync_data1 = CAL_PROPERTY_TODO_SYNC_DATA1,
+       .sync_data2 = CAL_PROPERTY_TODO_SYNC_DATA2,
+       .sync_data3 = CAL_PROPERTY_TODO_SYNC_DATA3,
+       .sync_data4 = CAL_PROPERTY_TODO_SYNC_DATA4,
+       .start_time = CAL_PROPERTY_TODO_START,
+       .start_tzid = CAL_PROPERTY_TODO_START_TZID,
+       .due_time = CAL_PROPERTY_TODO_DUE,
+       .due_tzid = CAL_PROPERTY_TODO_DUE_TZID,
+       .calendar_alarm = CAL_PROPERTY_TODO_CALENDAR_ALARM,
+       .organizer_name = CAL_PROPERTY_TODO_ORGANIZER_NAME,
+       .organizer_email = CAL_PROPERTY_TODO_ORGANIZER_EMAIL,
+       .has_attendee = CAL_PROPERTY_TODO_HAS_ATTENDEE,
+       .calendar_attendee = CAL_PROPERTY_TODO_CALENDAR_ATTENDEE,
+       .extended = CAL_PROPERTY_TODO_EXTENDED,
+       .is_allday = CAL_PROPERTY_TODO_IS_ALLDAY
+};
+
+API const _calendar_timezone_property_ids   _calendar_timezone =
+{
+       ._uri = CALENDAR_VIEW_TIMEZONE,
+       .id = CAL_PROPERTY_TIMEZONE_ID,
+       .calendar_book_id = CAL_PROPERTY_TIMEZONE_CALENDAR_ID,
+       .tz_offset_from_gmt = CAL_PROPERTY_TIMEZONE_TZ_OFFSET_FROM_GMT,
+       .standard_name = CAL_PROPERTY_TIMEZONE_STANDARD_NAME,
+       .standard_start_month = CAL_PROPERTY_TIMEZONE_STD_START_MONTH,
+       .standard_start_position_of_week = CAL_PROPERTY_TIMEZONE_STD_START_POSITION_OF_WEEK,
+       .standard_start_day = CAL_PROPERTY_TIMEZONE_STD_START_DAY,
+       .standard_start_hour = CAL_PROPERTY_TIMEZONE_STD_START_HOUR,
+       .standard_bias = CAL_PROPERTY_TIMEZONE_STANDARD_BIAS,
+       .day_light_name = CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME,
+       .day_light_start_month = CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_MONTH,
+       .day_light_start_position_of_week = CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_POSITION_OF_WEEK,
+       .day_light_start_day = CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_DAY,
+       .day_light_start_hour = CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_HOUR,
+       .day_light_bias = CAL_PROPERTY_TIMEZONE_DAY_LIGHT_BIAS
+};
+
+API const _calendar_attendee_property_ids   _calendar_attendee =
+{
+       ._uri = CALENDAR_VIEW_ATTENDEE,
+       .parent_id = CAL_PROPERTY_ATTENDEE_PARENT_ID,
+       .number = CAL_PROPERTY_ATTENDEE_NUMBER,
+       .cutype = CAL_PROPERTY_ATTENDEE_CUTYPE,
+       .person_id = CAL_PROPERTY_ATTENDEE_CT_INDEX,
+       .uid = CAL_PROPERTY_ATTENDEE_UID,
+       .group = CAL_PROPERTY_ATTENDEE_GROUP,
+       .email = CAL_PROPERTY_ATTENDEE_EMAIL,
+       .role = CAL_PROPERTY_ATTENDEE_ROLE,
+       .status = CAL_PROPERTY_ATTENDEE_STATUS,
+       .rsvp = CAL_PROPERTY_ATTENDEE_RSVP,
+       .delegatee_uri = CAL_PROPERTY_ATTENDEE_DELEGATEE_URI,
+       .delegator_uri = CAL_PROPERTY_ATTENDEE_DELEGATOR_URI,
+       .name = CAL_PROPERTY_ATTENDEE_NAME,
+       .member = CAL_PROPERTY_ATTENDEE_MEMBER
+};
+
+API const _calendar_alarm_property_ids   _calendar_alarm =
+{
+       ._uri = CALENDAR_VIEW_ALARM,
+       .parent_id = CAL_PROPERTY_ALARM_PARENT_ID,
+       .tick = CAL_PROPERTY_ALARM_TICK,
+       .tick_unit = CAL_PROPERTY_ALARM_TICK_UNIT,
+       .description = CAL_PROPERTY_ALARM_DESCRIPTION,
+       .summary = CAL_PROPERTY_ALARM_SUMMARY,
+       .action = CAL_PROPERTY_ALARM_ACTION,
+       .attach = CAL_PROPERTY_ALARM_ATTACH,
+       .alarm_time = CAL_PROPERTY_ALARM_ALARM,
+};
+
+API const _calendar_updated_info_property_ids   _calendar_updated_info =
+{
+       ._uri = CALENDAR_VIEW_UPDATED_INFO,
+       .id = CAL_PROPERTY_UPDATED_INFO_ID,
+       .calendar_book_id = CAL_PROPERTY_UPDATED_INFO_CALENDAR_ID,
+       .modified_status = CAL_PROPERTY_UPDATED_INFO_TYPE,
+       .version = CAL_PROPERTY_UPDATED_INFO_VERSION
+};
+
+API const _calendar_event_calendar_book_property_ids   _calendar_event_calendar_book =
+{
+       ._uri = CALENDAR_VIEW_EVENT_CALENDAR,
+       .event_id = CAL_PROPERTY_EVENT_ID,
+       .calendar_book_id = CAL_PROPERTY_EVENT_CALENDAR_ID,
+       .summary = CAL_PROPERTY_EVENT_SUMMARY,
+       .description = CAL_PROPERTY_EVENT_DESCRIPTION,
+       .location = CAL_PROPERTY_EVENT_LOCATION,
+       .categories = CAL_PROPERTY_EVENT_CATEGORIES,
+       .exdate = CAL_PROPERTY_EVENT_EXDATE,
+       .event_status = CAL_PROPERTY_EVENT_EVENT_STATUS,
+       .priority = CAL_PROPERTY_EVENT_PRIORITY,
+       .timezone = CAL_PROPERTY_EVENT_TIMEZONE,
+       .person_id = CAL_PROPERTY_EVENT_CONTACT_ID,
+       .busy_status = CAL_PROPERTY_EVENT_BUSY_STATUS,
+       .sensitivity = CAL_PROPERTY_EVENT_SENSITIVITY,
+       .uid = CAL_PROPERTY_EVENT_UID,
+       .organizer_name = CAL_PROPERTY_EVENT_ORGANIZER_NAME,
+       .organizer_email = CAL_PROPERTY_EVENT_ORGANIZER_EMAIL,
+       .meeting_status = CAL_PROPERTY_EVENT_MEETING_STATUS,
+       .original_event_id = CAL_PROPERTY_EVENT_ORIGINAL_EVENT_ID,
+       .latitude = CAL_PROPERTY_EVENT_LATITUDE,
+       .longitude = CAL_PROPERTY_EVENT_LONGITUDE,
+       .email_id = CAL_PROPERTY_EVENT_EMAIL_ID,
+       .created_time = CAL_PROPERTY_EVENT_CREATED_TIME,
+       .last_modified_time = CAL_PROPERTY_EVENT_LAST_MODIFIED_TIME,
+       .freq = CAL_PROPERTY_EVENT_FREQ,
+       .range_type = CAL_PROPERTY_EVENT_RANGE_TYPE,
+       .until_time = CAL_PROPERTY_EVENT_UNTIL,
+       .count = CAL_PROPERTY_EVENT_COUNT,
+       .interval = CAL_PROPERTY_EVENT_INTERVAL,
+       .bysecond = CAL_PROPERTY_EVENT_BYSECOND,
+       .byminute = CAL_PROPERTY_EVENT_BYMINUTE,
+       .byhour = CAL_PROPERTY_EVENT_BYHOUR,
+       .byday = CAL_PROPERTY_EVENT_BYDAY,
+       .bymonthday = CAL_PROPERTY_EVENT_BYMONTHDAY,
+       .byyearday = CAL_PROPERTY_EVENT_BYYEARDAY,
+       .byweekno = CAL_PROPERTY_EVENT_BYWEEKNO,
+       .bymonth = CAL_PROPERTY_EVENT_BYMONTH,
+       .bysetpos = CAL_PROPERTY_EVENT_BYSETPOS,
+       .wkst = CAL_PROPERTY_EVENT_WKST,
+       .recurrence_id = CAL_PROPERTY_EVENT_RECURRENCE_ID,
+       .rdate = CAL_PROPERTY_EVENT_RDATE,
+       .has_attendee = CAL_PROPERTY_EVENT_HAS_ATTENDEE,
+       .has_alarm = CAL_PROPERTY_EVENT_HAS_ALARM,
+       .calendar_system_type = CAL_PROPERTY_EVENT_CALENDAR_SYSTEM_TYPE,
+       .sync_data1 = CAL_PROPERTY_EVENT_SYNC_DATA1,
+       .sync_data2 = CAL_PROPERTY_EVENT_SYNC_DATA2,
+       .sync_data3 = CAL_PROPERTY_EVENT_SYNC_DATA3,
+       .sync_data4 = CAL_PROPERTY_EVENT_SYNC_DATA4,
+       .start_time = CAL_PROPERTY_EVENT_START,
+       .start_tzid = CAL_PROPERTY_EVENT_START_TZID,
+       .end_time = CAL_PROPERTY_EVENT_END,
+       .end_tzid = CAL_PROPERTY_EVENT_END_TZID,
+       .is_allday = CAL_PROPERTY_EVENT_IS_ALLDAY,
+       .calendar_book_visibility = CAL_PROPERTY_CALENDAR_VISIBILITY | CAL_PROPERTY_FLAGS_FILTER,
+       .calendar_book_account_id = CAL_PROPERTY_CALENDAR_ACCOUNT_ID | CAL_PROPERTY_FLAGS_FILTER
+};
+
+API const _calendar_todo_calendar_book_property_ids   _calendar_todo_calendar_book =
+{
+       ._uri = CALENDAR_VIEW_TODO_CALENDAR,
+       .todo_id = CAL_PROPERTY_TODO_ID,
+       .calendar_book_id = CAL_PROPERTY_TODO_CALENDAR_ID,
+       .summary = CAL_PROPERTY_TODO_SUMMARY,
+       .description = CAL_PROPERTY_TODO_DESCRIPTION,
+       .location = CAL_PROPERTY_TODO_LOCATION,
+       .categories = CAL_PROPERTY_TODO_CATEGORIES,
+       .todo_status = CAL_PROPERTY_TODO_TODO_STATUS,
+       .priority = CAL_PROPERTY_TODO_PRIORITY,
+       .sensitivity = CAL_PROPERTY_TODO_SENSITIVITY,
+       .uid = CAL_PROPERTY_TODO_UID,
+       .latitude = CAL_PROPERTY_TODO_LATITUDE,
+       .longitude = CAL_PROPERTY_TODO_LONGITUDE,
+       .created_time = CAL_PROPERTY_TODO_CREATED_TIME,
+       .last_modified_time = CAL_PROPERTY_TODO_LAST_MODIFIED_TIME,
+       .completed_time = CAL_PROPERTY_TODO_COMPLETED_TIME,
+       .progress = CAL_PROPERTY_TODO_PROGRESS,
+       .freq = CAL_PROPERTY_TODO_FREQ,
+       .range_type = CAL_PROPERTY_TODO_RANGE_TYPE,
+       .until_time = CAL_PROPERTY_TODO_UNTIL,
+       .count = CAL_PROPERTY_TODO_COUNT,
+       .interval = CAL_PROPERTY_TODO_INTERVAL,
+       .bysecond = CAL_PROPERTY_TODO_BYSECOND,
+       .byminute = CAL_PROPERTY_TODO_BYMINUTE,
+       .byhour = CAL_PROPERTY_TODO_BYHOUR,
+       .byday = CAL_PROPERTY_TODO_BYDAY,
+       .bymonthday = CAL_PROPERTY_TODO_BYMONTHDAY,
+       .byyearday = CAL_PROPERTY_TODO_BYYEARDAY,
+       .byweekno = CAL_PROPERTY_TODO_BYWEEKNO,
+       .bymonth = CAL_PROPERTY_TODO_BYMONTH,
+       .bysetpos = CAL_PROPERTY_TODO_BYSETPOS,
+       .wkst = CAL_PROPERTY_TODO_WKST,
+       .has_alarm = CAL_PROPERTY_TODO_HAS_ALARM,
+       .sync_data1 = CAL_PROPERTY_TODO_SYNC_DATA1,
+       .sync_data2 = CAL_PROPERTY_TODO_SYNC_DATA2,
+       .sync_data3 = CAL_PROPERTY_TODO_SYNC_DATA3,
+       .sync_data4 = CAL_PROPERTY_TODO_SYNC_DATA4,
+       .start_time = CAL_PROPERTY_TODO_START,
+       .start_tzid = CAL_PROPERTY_TODO_START_TZID,
+       .due_time = CAL_PROPERTY_TODO_DUE,
+       .due_tzid = CAL_PROPERTY_TODO_DUE_TZID,
+       .organizer_name = CAL_PROPERTY_TODO_ORGANIZER_NAME,
+       .organizer_email = CAL_PROPERTY_TODO_ORGANIZER_EMAIL,
+       .has_attendee = CAL_PROPERTY_TODO_HAS_ATTENDEE,
+       .is_allday = CAL_PROPERTY_TODO_IS_ALLDAY,
+       .calendar_book_visibility = CAL_PROPERTY_CALENDAR_VISIBILITY | CAL_PROPERTY_FLAGS_FILTER,
+       .calendar_book_account_id = CAL_PROPERTY_CALENDAR_ACCOUNT_ID | CAL_PROPERTY_FLAGS_FILTER
+};
+
+API const _calendar_event_calendar_book_attendee_property_ids   _calendar_event_calendar_book_attendee =
+{
+       ._uri = CALENDAR_VIEW_EVENT_CALENDAR_ATTENDEE,
+       .event_id = CAL_PROPERTY_EVENT_ID,
+       .calendar_book_id = CAL_PROPERTY_EVENT_CALENDAR_ID,
+       .summary = CAL_PROPERTY_EVENT_SUMMARY,
+       .description = CAL_PROPERTY_EVENT_DESCRIPTION,
+       .location = CAL_PROPERTY_EVENT_LOCATION,
+       .categories = CAL_PROPERTY_EVENT_CATEGORIES,
+       .exdate = CAL_PROPERTY_EVENT_EXDATE,
+       .event_status = CAL_PROPERTY_EVENT_EVENT_STATUS,
+       .priority = CAL_PROPERTY_EVENT_PRIORITY,
+       .timezone = CAL_PROPERTY_EVENT_TIMEZONE,
+       .person_id = CAL_PROPERTY_EVENT_CONTACT_ID,
+       .busy_status = CAL_PROPERTY_EVENT_BUSY_STATUS,
+       .sensitivity = CAL_PROPERTY_EVENT_SENSITIVITY,
+       .uid = CAL_PROPERTY_EVENT_UID,
+       .organizer_name = CAL_PROPERTY_EVENT_ORGANIZER_NAME,
+       .organizer_email = CAL_PROPERTY_EVENT_ORGANIZER_EMAIL,
+       .meeting_status = CAL_PROPERTY_EVENT_MEETING_STATUS,
+       .original_event_id = CAL_PROPERTY_EVENT_ORIGINAL_EVENT_ID,
+       .latitude = CAL_PROPERTY_EVENT_LATITUDE,
+       .longitude = CAL_PROPERTY_EVENT_LONGITUDE,
+       .email_id = CAL_PROPERTY_EVENT_EMAIL_ID,
+       .created_time = CAL_PROPERTY_EVENT_CREATED_TIME,
+       .last_modified_time = CAL_PROPERTY_EVENT_LAST_MODIFIED_TIME,
+       .freq = CAL_PROPERTY_EVENT_FREQ,
+       .range_type = CAL_PROPERTY_EVENT_RANGE_TYPE,
+       .until_time = CAL_PROPERTY_EVENT_UNTIL,
+       .count = CAL_PROPERTY_EVENT_COUNT,
+       .interval = CAL_PROPERTY_EVENT_INTERVAL,
+       .bysecond = CAL_PROPERTY_EVENT_BYSECOND,
+       .byminute = CAL_PROPERTY_EVENT_BYMINUTE,
+       .byhour = CAL_PROPERTY_EVENT_BYHOUR,
+       .byday = CAL_PROPERTY_EVENT_BYDAY,
+       .bymonthday = CAL_PROPERTY_EVENT_BYMONTHDAY,
+       .byyearday = CAL_PROPERTY_EVENT_BYYEARDAY,
+       .byweekno = CAL_PROPERTY_EVENT_BYWEEKNO,
+       .bymonth = CAL_PROPERTY_EVENT_BYMONTH,
+       .bysetpos = CAL_PROPERTY_EVENT_BYSETPOS,
+       .wkst = CAL_PROPERTY_EVENT_WKST,
+       .recurrence_id = CAL_PROPERTY_EVENT_RECURRENCE_ID,
+       .rdate = CAL_PROPERTY_EVENT_RDATE,
+       .has_attendee = CAL_PROPERTY_EVENT_HAS_ATTENDEE,
+       .has_alarm = CAL_PROPERTY_EVENT_HAS_ALARM,
+       .calendar_system_type = CAL_PROPERTY_EVENT_CALENDAR_SYSTEM_TYPE,
+       .sync_data1 = CAL_PROPERTY_EVENT_SYNC_DATA1,
+       .sync_data2 = CAL_PROPERTY_EVENT_SYNC_DATA2,
+       .sync_data3 = CAL_PROPERTY_EVENT_SYNC_DATA3,
+       .sync_data4 = CAL_PROPERTY_EVENT_SYNC_DATA4,
+       .start_time = CAL_PROPERTY_EVENT_START,
+       .start_tzid = CAL_PROPERTY_EVENT_START_TZID,
+       .end_time = CAL_PROPERTY_EVENT_END,
+       .end_tzid = CAL_PROPERTY_EVENT_END_TZID,
+       .is_allday = CAL_PROPERTY_EVENT_IS_ALLDAY,
+       .calendar_book_visibility = CAL_PROPERTY_CALENDAR_VISIBILITY | CAL_PROPERTY_FLAGS_FILTER,
+       .calendar_book_account_id = CAL_PROPERTY_CALENDAR_ACCOUNT_ID | CAL_PROPERTY_FLAGS_FILTER,
+       .attendee_email = CAL_PROPERTY_ATTENDEE_EMAIL | CAL_PROPERTY_FLAGS_FILTER,
+       .attendee_name = CAL_PROPERTY_ATTENDEE_NAME | CAL_PROPERTY_FLAGS_FILTER,
+       .attendee_member = CAL_PROPERTY_ATTENDEE_MEMBER | CAL_PROPERTY_FLAGS_FILTER
+};
+
+API const _calendar_instance_utime_calendar_book_property_ids   _calendar_instance_utime_calendar_book =
+{
+       ._uri = CALENDAR_VIEW_INSTANCE_UTIME_CALENDAR,
+       .event_id = CAL_PROPERTY_INSTANCE_NORMAL_EVENT_ID,
+       .start_time = CAL_PROPERTY_INSTANCE_NORMAL_START,
+       .end_time = CAL_PROPERTY_INSTANCE_NORMAL_END,
+       .summary = CAL_PROPERTY_INSTANCE_NORMAL_SUMMARY,
+       .location = CAL_PROPERTY_INSTANCE_NORMAL_LOCATION,
+       .calendar_book_id = CAL_PROPERTY_INSTANCE_NORMAL_CALENDAR_ID,
+       .description = CAL_PROPERTY_INSTANCE_NORMAL_DESCRIPTION,
+       .busy_status = CAL_PROPERTY_INSTANCE_NORMAL_BUSY_STATUS,
+       .event_status = CAL_PROPERTY_INSTANCE_NORMAL_EVENT_STATUS,
+       .priority = CAL_PROPERTY_INSTANCE_NORMAL_PRIORITY,
+       .sensitivity = CAL_PROPERTY_INSTANCE_NORMAL_SENSITIVITY,
+       .has_rrule = CAL_PROPERTY_INSTANCE_NORMAL_HAS_RRULE,
+       .latitude = CAL_PROPERTY_INSTANCE_NORMAL_LATITUDE,
+       .longitude = CAL_PROPERTY_INSTANCE_NORMAL_LONGITUDE,
+       .has_alarm = CAL_PROPERTY_INSTANCE_NORMAL_HAS_ALARM,
+       .original_event_id = CAL_PROPERTY_INSTANCE_NORMAL_ORIGINAL_EVENT_ID,
+       .calendar_book_visibility = CAL_PROPERTY_CALENDAR_VISIBILITY | CAL_PROPERTY_FLAGS_FILTER,
+       .calendar_book_account_id = CAL_PROPERTY_CALENDAR_ACCOUNT_ID | CAL_PROPERTY_FLAGS_FILTER,
+       .last_modified_time = CAL_PROPERTY_INSTANCE_NORMAL_LAST_MODIFIED_TIME,
+       .sync_data1 = CAL_PROPERTY_INSTANCE_NORMAL_SYNC_DATA1
+};
+
+API const _calendar_instance_localtime_calendar_book_property_ids   _calendar_instance_localtime_calendar_book =
+{
+       ._uri = CALENDAR_VIEW_INSTANCE_LOCALTIME_CALENDAR,
+       .event_id = CAL_PROPERTY_INSTANCE_ALLDAY_EVENT_ID,
+       .start_time = CAL_PROPERTY_INSTANCE_ALLDAY_START,
+       .end_time = CAL_PROPERTY_INSTANCE_ALLDAY_END,
+       .summary = CAL_PROPERTY_INSTANCE_ALLDAY_SUMMARY,
+       .location = CAL_PROPERTY_INSTANCE_ALLDAY_LOCATION,
+       .calendar_book_id = CAL_PROPERTY_INSTANCE_ALLDAY_CALENDAR_ID,
+       .description = CAL_PROPERTY_INSTANCE_ALLDAY_DESCRIPTION,
+       .busy_status = CAL_PROPERTY_INSTANCE_ALLDAY_BUSY_STATUS,
+       .event_status = CAL_PROPERTY_INSTANCE_ALLDAY_EVENT_STATUS,
+       .priority = CAL_PROPERTY_INSTANCE_ALLDAY_PRIORITY,
+       .sensitivity = CAL_PROPERTY_INSTANCE_ALLDAY_SENSITIVITY,
+       .has_rrule = CAL_PROPERTY_INSTANCE_ALLDAY_HAS_RRULE,
+       .latitude = CAL_PROPERTY_INSTANCE_ALLDAY_LATITUDE,
+       .longitude = CAL_PROPERTY_INSTANCE_ALLDAY_LONGITUDE,
+       .has_alarm = CAL_PROPERTY_INSTANCE_ALLDAY_HAS_ALARM,
+       .original_event_id = CAL_PROPERTY_INSTANCE_ALLDAY_ORIGINAL_EVENT_ID,
+       .calendar_book_visibility = CAL_PROPERTY_CALENDAR_VISIBILITY | CAL_PROPERTY_FLAGS_FILTER,
+       .calendar_book_account_id = CAL_PROPERTY_CALENDAR_ACCOUNT_ID | CAL_PROPERTY_FLAGS_FILTER,
+       .last_modified_time = CAL_PROPERTY_INSTANCE_ALLDAY_LAST_MODIFIED_TIME,
+       .sync_data1 = CAL_PROPERTY_INSTANCE_ALLDAY_SYNC_DATA1,
+       .is_allday = CAL_PROPERTY_INSTANCE_ALLDAY_IS_ALLDAY
+};
+
+API const _calendar_instance_utime_calendar_book_extended_property_ids   _calendar_instance_utime_calendar_book_extended =
+{
+       ._uri = CALENDAR_VIEW_INSTANCE_UTIME_CALENDAR_EXTENDED,
+       .event_id = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_EVENT_ID,
+       .start_time = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_START,
+       .end_time = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_END,
+       .summary = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SUMMARY,
+       .location = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LOCATION,
+       .calendar_book_id = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_CALENDAR_ID,
+       .description = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_DESCRIPTION,
+       .busy_status = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_BUSY_STATUS,
+       .event_status = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_EVENT_STATUS,
+       .priority = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_PRIORITY,
+       .sensitivity = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SENSITIVITY,
+       .has_rrule = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_RRULE,
+       .latitude = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LATITUDE,
+       .longitude = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LONGITUDE,
+       .has_alarm = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_ALARM,
+       .original_event_id = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_ORIGINAL_EVENT_ID,
+       .calendar_book_visibility = CAL_PROPERTY_CALENDAR_VISIBILITY | CAL_PROPERTY_FLAGS_FILTER,
+       .calendar_book_account_id = CAL_PROPERTY_CALENDAR_ACCOUNT_ID | CAL_PROPERTY_FLAGS_FILTER,
+       .last_modified_time = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LAST_MODIFIED_TIME,
+       .sync_data1 = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA1,
+       .organizer_name = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_ORGANIZER_NAME,
+       .categories = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_CATEGORIES,
+       .has_attendee = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_ATTENDEE,
+       .sync_data2 = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA2,
+       .sync_data3 = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA3,
+       .sync_data4 = CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA4
+};
+
+API const _calendar_instance_localtime_calendar_book_extended_property_ids   _calendar_instance_localtime_calendar_book_extended =
+{
+       ._uri = CALENDAR_VIEW_INSTANCE_LOCALTIME_CALENDAR_EXTENDED,
+       .event_id = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_EVENT_ID,
+       .start_time = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_START,
+       .end_time = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_END,
+       .summary = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SUMMARY,
+       .location = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LOCATION,
+       .calendar_book_id = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_CALENDAR_ID,
+       .description = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_DESCRIPTION,
+       .busy_status = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_BUSY_STATUS,
+       .event_status = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_EVENT_STATUS,
+       .priority = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_PRIORITY,
+       .sensitivity = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SENSITIVITY,
+       .has_rrule = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_RRULE,
+       .latitude = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LATITUDE,
+       .longitude = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LONGITUDE,
+       .has_alarm = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_ALARM,
+       .original_event_id = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_ORIGINAL_EVENT_ID,
+       .calendar_book_visibility = CAL_PROPERTY_CALENDAR_VISIBILITY | CAL_PROPERTY_FLAGS_FILTER,
+       .calendar_book_account_id = CAL_PROPERTY_CALENDAR_ACCOUNT_ID | CAL_PROPERTY_FLAGS_FILTER,
+       .last_modified_time = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LAST_MODIFIED_TIME,
+       .sync_data1 = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA1,
+       .organizer_name= CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_ORGANIZER_NAME,
+       .categories = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_CATEGORIES,
+       .has_attendee = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_ATTENDEE,
+       .sync_data2 = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA2,
+       .sync_data3 = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA3,
+       .sync_data4 = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA4,
+       .is_allday = CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_IS_ALLDAY
+};
+
+API const _calendar_extended_property_property_ids   _calendar_extended_property =
+{
+       ._uri = CALENDAR_VIEW_EXTENDED,
+       .id = CAL_PROPERTY_EXTENDED_ID,
+       .record_id = CAL_PROPERTY_EXTENDED_RECORD_ID,
+       .record_type = CAL_PROPERTY_EXTENDED_RECORD_TYPE,
+       .key = CAL_PROPERTY_EXTENDED_KEY,
+       .value = CAL_PROPERTY_EXTENDED_VALUE
+};
+
+//////////////////////
+// cal_property_info_s
+
+const cal_property_info_s  __property_calendar_book[] = {
+       {CAL_PROPERTY_CALENDAR_ID           ,       "id"},
+       {CAL_PROPERTY_CALENDAR_UID          ,       "uid"},
+       {CAL_PROPERTY_CALENDAR_NAME         ,       "name"},
+       {CAL_PROPERTY_CALENDAR_DESCRIPTION  ,       "description"},
+       {CAL_PROPERTY_CALENDAR_COLOR        ,       "color"},
+       {CAL_PROPERTY_CALENDAR_LOCATION     ,       "location"},
+       {CAL_PROPERTY_CALENDAR_VISIBILITY   ,       "visibility"},
+       {CAL_PROPERTY_CALENDAR_SYNC_EVENT   ,       "sync_event"},
+       {CAL_PROPERTY_CALENDAR_ACCOUNT_ID   ,       "account_id"},
+       {CAL_PROPERTY_CALENDAR_STORE_TYPE   ,       "store_type"},
+       {CAL_PROPERTY_CALENDAR_SYNC_DATA1   ,       "sync_data1"},
+       {CAL_PROPERTY_CALENDAR_SYNC_DATA2   ,       "sync_data2"},
+       {CAL_PROPERTY_CALENDAR_SYNC_DATA3   ,       "sync_data3"},
+       {CAL_PROPERTY_CALENDAR_SYNC_DATA4   ,       "sync_data4"},
+       {CAL_PROPERTY_CALENDAR_MODE,                "mode"},
+};
+
+const cal_property_info_s   __property_event[] =
+{
+       {CAL_PROPERTY_EVENT_ID,                     "id"},
+       {CAL_PROPERTY_EVENT_CALENDAR_ID,            "calendar_id"},
+       {CAL_PROPERTY_EVENT_SUMMARY,                "summary"},
+       {CAL_PROPERTY_EVENT_DESCRIPTION,            "description"},
+       {CAL_PROPERTY_EVENT_LOCATION,               "location"},
+       {CAL_PROPERTY_EVENT_CATEGORIES,             "categories"},
+       {CAL_PROPERTY_EVENT_EXDATE,                 "exdate"},
+       {CAL_PROPERTY_EVENT_EVENT_STATUS,           "task_status"},
+       {CAL_PROPERTY_EVENT_PRIORITY,               "priority"},
+       {CAL_PROPERTY_EVENT_TIMEZONE,               "timezone"},
+       {CAL_PROPERTY_EVENT_CONTACT_ID,             "contact_id"},
+       {CAL_PROPERTY_EVENT_BUSY_STATUS,            "busy_status"},
+       {CAL_PROPERTY_EVENT_SENSITIVITY,            "sensitivity"},
+       {CAL_PROPERTY_EVENT_UID,                    "uid"},
+       {CAL_PROPERTY_EVENT_ORGANIZER_NAME,         "organizer_name"},
+       {CAL_PROPERTY_EVENT_ORGANIZER_EMAIL,        "organizer_email"},
+       {CAL_PROPERTY_EVENT_MEETING_STATUS,         "meeting_status"},
+       {CAL_PROPERTY_EVENT_ORIGINAL_EVENT_ID,      "original_event_id"},
+       {CAL_PROPERTY_EVENT_LATITUDE,               "latitude"},
+       {CAL_PROPERTY_EVENT_LONGITUDE,              "longitude"},
+       {CAL_PROPERTY_EVENT_EMAIL_ID,               "email_id"},
+       {CAL_PROPERTY_EVENT_CREATED_TIME,           "created_time"},
+       {CAL_PROPERTY_EVENT_LAST_MODIFIED_TIME,     "last_mod"},
+       {CAL_PROPERTY_EVENT_IS_DELETED,             "is_deleted"},
+       {CAL_PROPERTY_EVENT_FREQ,                   "freq"},
+       {CAL_PROPERTY_EVENT_RANGE_TYPE,             "range_type"},
+       {CAL_PROPERTY_EVENT_UNTIL,                  "until_type, until_utime, until_datetime"},
+       {CAL_PROPERTY_EVENT_COUNT,                  "count"},
+       {CAL_PROPERTY_EVENT_INTERVAL,               "interval"},
+       {CAL_PROPERTY_EVENT_BYSECOND,               "bysecond"},
+       {CAL_PROPERTY_EVENT_BYMINUTE,               "byminute"},
+       {CAL_PROPERTY_EVENT_BYHOUR,                 "byhour"},
+       {CAL_PROPERTY_EVENT_BYDAY,                  "byday"},
+       {CAL_PROPERTY_EVENT_BYMONTHDAY,             "bymonthday"},
+       {CAL_PROPERTY_EVENT_BYYEARDAY,              "byyearday"},
+       {CAL_PROPERTY_EVENT_BYWEEKNO,               "byweekno"},
+       {CAL_PROPERTY_EVENT_BYMONTH,                "bymonth"},
+       {CAL_PROPERTY_EVENT_BYSETPOS,               "bysetpos"},
+       {CAL_PROPERTY_EVENT_WKST,                   "wkst"},
+       {CAL_PROPERTY_EVENT_RECURRENCE_ID,          "recurrence_id"},
+       {CAL_PROPERTY_EVENT_RDATE,                  "rdate"},
+       {CAL_PROPERTY_EVENT_HAS_ATTENDEE,           "has_attendee"},
+       {CAL_PROPERTY_EVENT_HAS_ALARM,              "has_alarm"},
+       {CAL_PROPERTY_EVENT_SYNC_DATA1,             "sync_data1"},
+       {CAL_PROPERTY_EVENT_SYNC_DATA2,             "sync_data2"},
+       {CAL_PROPERTY_EVENT_SYNC_DATA3,             "sync_data3"},
+       {CAL_PROPERTY_EVENT_SYNC_DATA4,             "sync_data4"},
+       {CAL_PROPERTY_EVENT_START,                  "dtstart_type, dtstart_utime, dtstart_datetime"},
+       {CAL_PROPERTY_EVENT_END,                    "dtend_type, dtend_utime, dtend_datetime"},
+       {CAL_PROPERTY_EVENT_CALENDAR_ALARM,         NULL},
+       {CAL_PROPERTY_EVENT_CALENDAR_ATTENDEE,      NULL},
+       {CAL_PROPERTY_EVENT_CALENDAR_SYSTEM_TYPE,   "system_type"},
+       {CAL_PROPERTY_EVENT_START_TZID,             "dtstart_tzid"},
+       {CAL_PROPERTY_EVENT_END_TZID,               "dtend_tzid"},
+       {CAL_PROPERTY_EVENT_EXCEPTION,              NULL},
+       {CAL_PROPERTY_EVENT_EXTENDED,               NULL},
+       {CAL_PROPERTY_EVENT_IS_ALLDAY,              "is_allday"},
+};
+
+const cal_property_info_s   __property_todo[] =
+{
+       {CAL_PROPERTY_TODO_ID,                      "id"},
+       {CAL_PROPERTY_TODO_CALENDAR_ID,             "calendar_id"},
+       {CAL_PROPERTY_TODO_SUMMARY,                 "summary"},
+       {CAL_PROPERTY_TODO_DESCRIPTION,             "description"},
+       {CAL_PROPERTY_TODO_LOCATION,                "location"},
+       {CAL_PROPERTY_TODO_CATEGORIES,              "categories"},
+       {CAL_PROPERTY_TODO_TODO_STATUS,             "task_status"},
+       {CAL_PROPERTY_TODO_PRIORITY,                "priority"},
+       {CAL_PROPERTY_TODO_SENSITIVITY,             "sensitivity"},
+       {CAL_PROPERTY_TODO_UID,                     "uid"},
+       {CAL_PROPERTY_TODO_LATITUDE,                "latitude"},
+       {CAL_PROPERTY_TODO_LONGITUDE,               "longitude"},
+       {CAL_PROPERTY_TODO_PROGRESS,                "progress"},
+       {CAL_PROPERTY_TODO_CREATED_TIME,            "created_time"},
+       {CAL_PROPERTY_TODO_LAST_MODIFIED_TIME,      "last_mod"},
+       {CAL_PROPERTY_TODO_COMPLETED_TIME,          "completed_time"},
+       {CAL_PROPERTY_TODO_IS_DELETED,              "is_deleted"},
+       {CAL_PROPERTY_TODO_FREQ,                    "freq"},
+       {CAL_PROPERTY_TODO_RANGE_TYPE,              "range_type"},
+       {CAL_PROPERTY_TODO_UNTIL,                   "until_type, until_utime, until_datetime"},
+       {CAL_PROPERTY_TODO_COUNT,                   "count"},
+       {CAL_PROPERTY_TODO_INTERVAL,                "interval"},
+       {CAL_PROPERTY_TODO_BYSECOND,                "bysecond"},
+       {CAL_PROPERTY_TODO_BYMINUTE,                "byminute"},
+       {CAL_PROPERTY_TODO_BYHOUR,                  "byhour"},
+       {CAL_PROPERTY_TODO_BYDAY,                   "byday"},
+       {CAL_PROPERTY_TODO_BYMONTHDAY,              "bymonthday"},
+       {CAL_PROPERTY_TODO_BYYEARDAY,               "byyearday"},
+       {CAL_PROPERTY_TODO_BYWEEKNO,                "byweekno"},
+       {CAL_PROPERTY_TODO_BYMONTH,                 "bymonth"},
+       {CAL_PROPERTY_TODO_BYSETPOS,                "bysetpos"},
+       {CAL_PROPERTY_TODO_WKST,                    "wkst"},
+       {CAL_PROPERTY_TODO_HAS_ALARM,               "has_alarm"},
+       {CAL_PROPERTY_TODO_SYNC_DATA1,              "sync_data1"},
+       {CAL_PROPERTY_TODO_SYNC_DATA2,              "sync_data2"},
+       {CAL_PROPERTY_TODO_SYNC_DATA3,              "sync_data3"},
+       {CAL_PROPERTY_TODO_SYNC_DATA4,              "sync_data4"},
+       {CAL_PROPERTY_TODO_START,                   "dtstart_type, dtstart_utime, dtstart_datetime"},
+       {CAL_PROPERTY_TODO_DUE,                     "dtend_type, dtend_utime, dtend_datetime"},
+       {CAL_PROPERTY_TODO_CALENDAR_ALARM,          NULL},
+       {CAL_PROPERTY_TODO_START_TZID,              "dtstart_tzid"},
+       {CAL_PROPERTY_TODO_DUE_TZID,                "dtend_tzid"},
+       {CAL_PROPERTY_TODO_ORGANIZER_NAME,          "organizer_name"},
+       {CAL_PROPERTY_TODO_ORGANIZER_EMAIL,         "organizer_email"},
+       {CAL_PROPERTY_TODO_HAS_ATTENDEE,            "has_attendee"},
+       {CAL_PROPERTY_TODO_CALENDAR_ATTENDEE,       NULL},
+       {CAL_PROPERTY_TODO_EXTENDED,                NULL},
+       {CAL_PROPERTY_TODO_IS_ALLDAY,               "dtend_type"},
+};
+
+const cal_property_info_s   __property_timezone[] =
+{
+       {CAL_PROPERTY_TIMEZONE_ID,                                  "id"},
+       {CAL_PROPERTY_TIMEZONE_TZ_OFFSET_FROM_GMT,                  "tz_offset_from_gmt"},
+       {CAL_PROPERTY_TIMEZONE_STANDARD_NAME,                       "standard_name"},
+       {CAL_PROPERTY_TIMEZONE_STD_START_MONTH,                     "std_start_month"},
+       {CAL_PROPERTY_TIMEZONE_STD_START_POSITION_OF_WEEK,          "std_start_position_of_week"},
+       {CAL_PROPERTY_TIMEZONE_STD_START_DAY,                       "std_start_day"},
+       {CAL_PROPERTY_TIMEZONE_STD_START_HOUR,                      "std_start_hour"},
+       {CAL_PROPERTY_TIMEZONE_STANDARD_BIAS,                       "standard_bias"},
+       {CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME,                      "day_light_name"},
+       {CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_MONTH,               "day_light_start_month"},
+       {CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_POSITION_OF_WEEK,    "day_light_start_position_of_week"},
+       {CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_DAY,                 "day_light_start_day"},
+       {CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_HOUR,                "day_light_start_hour"},
+       {CAL_PROPERTY_TIMEZONE_DAY_LIGHT_BIAS,                      "day_light_bias"},
+       {CAL_PROPERTY_TIMEZONE_CALENDAR_ID,                         "calendar_id"},
+};
+
+const cal_property_info_s   __property_attendee[] =
+{
+       {CAL_PROPERTY_ATTENDEE_NUMBER,              "attendee_number"},
+       {CAL_PROPERTY_ATTENDEE_CUTYPE,              "attendee_cutype"},
+       {CAL_PROPERTY_ATTENDEE_CT_INDEX,            "attendee_ct_index"},
+       {CAL_PROPERTY_ATTENDEE_UID,                 "attendee_uid"},
+       {CAL_PROPERTY_ATTENDEE_GROUP,               "attendee_group"},
+       {CAL_PROPERTY_ATTENDEE_EMAIL,               "attendee_email"},
+       {CAL_PROPERTY_ATTENDEE_ROLE,                "attendee_role"},
+       {CAL_PROPERTY_ATTENDEE_STATUS,              "attendee_status"},
+       {CAL_PROPERTY_ATTENDEE_RSVP,                "attendee_rsvp"},
+       {CAL_PROPERTY_ATTENDEE_DELEGATEE_URI,       "attendee_delegatee_uri"},
+       {CAL_PROPERTY_ATTENDEE_DELEGATOR_URI,       "attendee_delegator_uri"},
+       {CAL_PROPERTY_ATTENDEE_NAME,                "attendee_name"},
+       {CAL_PROPERTY_ATTENDEE_MEMBER,              "attendee_member"},
+       {CAL_PROPERTY_ATTENDEE_PARENT_ID,           "event_id"},
+};
+
+const cal_property_info_s   __property_alarm[] =
+{
+       {CAL_PROPERTY_ALARM_TICK,               "remind_tick"},
+       {CAL_PROPERTY_ALARM_TICK_UNIT,          "remind_tick_unit"},
+       {CAL_PROPERTY_ALARM_DESCRIPTION,        "alarm_description"},
+       {CAL_PROPERTY_ALARM_PARENT_ID,                  "event_id"},
+       {CAL_PROPERTY_ALARM_SUMMARY,            "alarm_summary"},
+       {CAL_PROPERTY_ALARM_ACTION,             "alarm_action"},
+       {CAL_PROPERTY_ALARM_ATTACH,             "alarm_attach"},
+       {CAL_PROPERTY_ALARM_ALARM,              "alarm_type, alarm_utime, alarm_datetime"},
+};
+
+const cal_property_info_s   __property_updated_info[] =
+{
+       {CAL_PROPERTY_UPDATED_INFO_ID,                  "id"},
+       {CAL_PROPERTY_UPDATED_INFO_CALENDAR_ID,         "calendar_id"},
+       {CAL_PROPERTY_UPDATED_INFO_TYPE,                "type"},
+       {CAL_PROPERTY_UPDATED_INFO_VERSION,             "ver"},
+};
+
+const cal_property_info_s   __property_search_event_calendar[] =
+{
+       {CAL_PROPERTY_EVENT_ID,                     "id"},
+       {CAL_PROPERTY_EVENT_CALENDAR_ID,            "calendar_id"},
+       {CAL_PROPERTY_EVENT_SUMMARY,                "summary"},
+       {CAL_PROPERTY_EVENT_DESCRIPTION,            "description"},
+       {CAL_PROPERTY_EVENT_LOCATION,               "location"},
+       {CAL_PROPERTY_EVENT_CATEGORIES,             "categories"},
+       {CAL_PROPERTY_EVENT_EXDATE,                 "exdate"},
+       {CAL_PROPERTY_EVENT_EVENT_STATUS,           "task_status"},
+       {CAL_PROPERTY_EVENT_PRIORITY,               "priority"},
+       {CAL_PROPERTY_EVENT_TIMEZONE,               "timezone"},
+       {CAL_PROPERTY_EVENT_CONTACT_ID,             "contact_id"},
+       {CAL_PROPERTY_EVENT_BUSY_STATUS,            "busy_status"},
+       {CAL_PROPERTY_EVENT_SENSITIVITY,            "sensitivity"},
+       {CAL_PROPERTY_EVENT_UID,                    "uid"},
+       {CAL_PROPERTY_EVENT_ORGANIZER_NAME,         "organizer_name"},
+       {CAL_PROPERTY_EVENT_ORGANIZER_EMAIL,        "organizer_email"},
+       {CAL_PROPERTY_EVENT_MEETING_STATUS,         "meeting_status"},
+       {CAL_PROPERTY_EVENT_ORIGINAL_EVENT_ID,      "original_event_id"},
+       {CAL_PROPERTY_EVENT_LATITUDE,               "latitude"},
+       {CAL_PROPERTY_EVENT_LONGITUDE,              "longitude"},
+       {CAL_PROPERTY_EVENT_EMAIL_ID,               "email_id"},
+       {CAL_PROPERTY_EVENT_CREATED_TIME,           "created_time"},
+       {CAL_PROPERTY_EVENT_LAST_MODIFIED_TIME,     "last_mod"},
+       {CAL_PROPERTY_EVENT_FREQ,                   "freq"},
+       {CAL_PROPERTY_EVENT_RANGE_TYPE,             "range_type"},
+       {CAL_PROPERTY_EVENT_UNTIL,                  "until_type, until_utime, until_datetime"},
+       {CAL_PROPERTY_EVENT_COUNT,                  "count"},
+       {CAL_PROPERTY_EVENT_INTERVAL,               "interval"},
+       {CAL_PROPERTY_EVENT_BYSECOND,               "bysecond"},
+       {CAL_PROPERTY_EVENT_BYMINUTE,               "byminute"},
+       {CAL_PROPERTY_EVENT_BYHOUR,                 "byhour"},
+       {CAL_PROPERTY_EVENT_BYDAY,                  "byday"},
+       {CAL_PROPERTY_EVENT_BYMONTHDAY,             "bymonthday"},
+       {CAL_PROPERTY_EVENT_BYYEARDAY,              "byyearday"},
+       {CAL_PROPERTY_EVENT_BYWEEKNO,               "byweekno"},
+       {CAL_PROPERTY_EVENT_BYMONTH,                "bymonth"},
+       {CAL_PROPERTY_EVENT_BYSETPOS,               "bysetpos"},
+       {CAL_PROPERTY_EVENT_WKST,                   "wkst"},
+       {CAL_PROPERTY_EVENT_RECURRENCE_ID,          "recurrence_id"},
+       {CAL_PROPERTY_EVENT_RDATE,                  "rdate"},
+       {CAL_PROPERTY_EVENT_HAS_ATTENDEE,           "has_attendee"},
+       {CAL_PROPERTY_EVENT_HAS_ALARM,              "has_alarm"},
+       {CAL_PROPERTY_EVENT_SYNC_DATA1,             "sync_data1"},
+       {CAL_PROPERTY_EVENT_SYNC_DATA2,             "sync_data2"},
+       {CAL_PROPERTY_EVENT_SYNC_DATA3,             "sync_data3"},
+       {CAL_PROPERTY_EVENT_SYNC_DATA4,             "sync_data4"},
+       {CAL_PROPERTY_EVENT_START,                  "dtstart_type, dtstart_utime, dtstart_datetime"},
+       {CAL_PROPERTY_EVENT_END,                    "dtend_type, dtend_utime, dtend_datetime"},
+       {CAL_PROPERTY_EVENT_CALENDAR_SYSTEM_TYPE,   "system_type"},
+       {CAL_PROPERTY_EVENT_START_TZID,             "dtstart_tzid"},
+       {CAL_PROPERTY_EVENT_END_TZID,               "dtend_tzid"},
+       {CAL_PROPERTY_EVENT_IS_ALLDAY,              "is_allday"},
+       {(CAL_PROPERTY_CALENDAR_VISIBILITY|CAL_PROPERTY_FLAGS_FILTER),       "visibility"},
+       {(CAL_PROPERTY_CALENDAR_ACCOUNT_ID|CAL_PROPERTY_FLAGS_FILTER),       "account_id"},
+};
+
+const cal_property_info_s   __property_search_todo_calendar[] =
+{
+       {CAL_PROPERTY_TODO_ID,                      "id"},
+       {CAL_PROPERTY_TODO_CALENDAR_ID,             "calendar_id"},
+       {CAL_PROPERTY_TODO_SUMMARY,                 "summary"},
+       {CAL_PROPERTY_TODO_DESCRIPTION,             "description"},
+       {CAL_PROPERTY_TODO_LOCATION,                "location"},
+       {CAL_PROPERTY_TODO_CATEGORIES,              "categories"},
+       {CAL_PROPERTY_TODO_TODO_STATUS,             "task_status"},
+       {CAL_PROPERTY_TODO_PRIORITY,                "priority"},
+       {CAL_PROPERTY_TODO_SENSITIVITY,             "sensitivity"},
+       {CAL_PROPERTY_TODO_UID,                     "uid"},
+       {CAL_PROPERTY_TODO_LATITUDE,                "latitude"},
+       {CAL_PROPERTY_TODO_LONGITUDE,               "longitude"},
+       {CAL_PROPERTY_TODO_PROGRESS,                "progress"},
+       {CAL_PROPERTY_TODO_CREATED_TIME,            "created_time"},
+       {CAL_PROPERTY_TODO_LAST_MODIFIED_TIME,      "last_mod"},
+       {CAL_PROPERTY_TODO_COMPLETED_TIME,          "completed_time"},
+       {CAL_PROPERTY_TODO_FREQ,                    "freq"},
+       {CAL_PROPERTY_TODO_RANGE_TYPE,              "range_type"},
+       {CAL_PROPERTY_TODO_UNTIL,                   "until_type, until_utime, until_datetime"},
+       {CAL_PROPERTY_TODO_COUNT,                   "count"},
+       {CAL_PROPERTY_TODO_INTERVAL,                "interval"},
+       {CAL_PROPERTY_TODO_BYSECOND,                "bysecond"},
+       {CAL_PROPERTY_TODO_BYMINUTE,                "byminute"},
+       {CAL_PROPERTY_TODO_BYHOUR,                  "byhour"},
+       {CAL_PROPERTY_TODO_BYDAY,                   "byday"},
+       {CAL_PROPERTY_TODO_BYMONTHDAY,              "bymonthday"},
+       {CAL_PROPERTY_TODO_BYYEARDAY,               "byyearday"},
+       {CAL_PROPERTY_TODO_BYWEEKNO,                "byweekno"},
+       {CAL_PROPERTY_TODO_BYMONTH,                 "bymonth"},
+       {CAL_PROPERTY_TODO_BYSETPOS,                "bysetpos"},
+       {CAL_PROPERTY_TODO_WKST,                    "wkst"},
+       {CAL_PROPERTY_TODO_HAS_ALARM,               "has_alarm"},
+       {CAL_PROPERTY_TODO_SYNC_DATA1,              "sync_data1"},
+       {CAL_PROPERTY_TODO_SYNC_DATA2,              "sync_data2"},
+       {CAL_PROPERTY_TODO_SYNC_DATA3,              "sync_data3"},
+       {CAL_PROPERTY_TODO_SYNC_DATA4,              "sync_data4"},
+       {CAL_PROPERTY_TODO_START,                   "dtstart_type, dtstart_utime, dtstart_datetime"},
+       {CAL_PROPERTY_TODO_DUE,                     "dtend_type, dtend_utime, dtend_datetime"},
+       {CAL_PROPERTY_TODO_START_TZID,              "dtstart_tzid"},
+       {CAL_PROPERTY_TODO_DUE_TZID,                "dtend_tzid"},
+       {CAL_PROPERTY_TODO_ORGANIZER_NAME,          "organizer_name"},
+       {CAL_PROPERTY_TODO_ORGANIZER_EMAIL,         "organizer_email"},
+       {CAL_PROPERTY_TODO_HAS_ATTENDEE,            "has_attendee"},
+       {CAL_PROPERTY_TODO_IS_ALLDAY,               "dtend_type"},
+       {(CAL_PROPERTY_CALENDAR_VISIBILITY|CAL_PROPERTY_FLAGS_FILTER),       "visibility"},
+       {(CAL_PROPERTY_CALENDAR_ACCOUNT_ID|CAL_PROPERTY_FLAGS_FILTER),       "account_id"},
+};
+
+const cal_property_info_s   __property_search_event_calendar_attendee[] =
+{
+       {CAL_PROPERTY_EVENT_ID,                     "id"},
+       {CAL_PROPERTY_EVENT_CALENDAR_ID,            "calendar_id"},
+       {CAL_PROPERTY_EVENT_SUMMARY,                "summary"},
+       {CAL_PROPERTY_EVENT_DESCRIPTION,            "description"},
+       {CAL_PROPERTY_EVENT_LOCATION,               "location"},
+       {CAL_PROPERTY_EVENT_CATEGORIES,             "categories"},
+       {CAL_PROPERTY_EVENT_EXDATE,                 "exdate"},
+       {CAL_PROPERTY_EVENT_EVENT_STATUS,           "task_status"},
+       {CAL_PROPERTY_EVENT_PRIORITY,               "priority"},
+       {CAL_PROPERTY_EVENT_TIMEZONE,               "timezone"},
+       {CAL_PROPERTY_EVENT_CONTACT_ID,             "contact_id"},
+       {CAL_PROPERTY_EVENT_BUSY_STATUS,            "busy_status"},
+       {CAL_PROPERTY_EVENT_SENSITIVITY,            "sensitivity"},
+       {CAL_PROPERTY_EVENT_UID,                    "uid"},
+       {CAL_PROPERTY_EVENT_ORGANIZER_NAME,         "organizer_name"},
+       {CAL_PROPERTY_EVENT_ORGANIZER_EMAIL,        "organizer_email"},
+       {CAL_PROPERTY_EVENT_MEETING_STATUS,         "meeting_status"},
+       {CAL_PROPERTY_EVENT_ORIGINAL_EVENT_ID,      "original_event_id"},
+       {CAL_PROPERTY_EVENT_LATITUDE,               "latitude"},
+       {CAL_PROPERTY_EVENT_LONGITUDE,              "longitude"},
+       {CAL_PROPERTY_EVENT_EMAIL_ID,               "email_id"},
+       {CAL_PROPERTY_EVENT_CREATED_TIME,           "created_time"},
+       {CAL_PROPERTY_EVENT_LAST_MODIFIED_TIME,     "last_mod"},
+       {CAL_PROPERTY_EVENT_FREQ,                   "freq"},
+       {CAL_PROPERTY_EVENT_RANGE_TYPE,             "range_type"},
+       {CAL_PROPERTY_EVENT_UNTIL,                  "until_type, until_utime, until_datetime"},
+       {CAL_PROPERTY_EVENT_COUNT,                  "count"},
+       {CAL_PROPERTY_EVENT_INTERVAL,               "interval"},
+       {CAL_PROPERTY_EVENT_BYSECOND,               "bysecond"},
+       {CAL_PROPERTY_EVENT_BYMINUTE,               "byminute"},
+       {CAL_PROPERTY_EVENT_BYHOUR,                 "byhour"},
+       {CAL_PROPERTY_EVENT_BYDAY,                  "byday"},
+       {CAL_PROPERTY_EVENT_BYMONTHDAY,             "bymonthday"},
+       {CAL_PROPERTY_EVENT_BYYEARDAY,              "byyearday"},
+       {CAL_PROPERTY_EVENT_BYWEEKNO,               "byweekno"},
+       {CAL_PROPERTY_EVENT_BYMONTH,                "bymonth"},
+       {CAL_PROPERTY_EVENT_BYSETPOS,               "bysetpos"},
+       {CAL_PROPERTY_EVENT_WKST,                   "wkst"},
+       {CAL_PROPERTY_EVENT_RECURRENCE_ID,          "recurrence_id"},
+       {CAL_PROPERTY_EVENT_RDATE,                  "rdate"},
+       {CAL_PROPERTY_EVENT_HAS_ATTENDEE,           "has_attendee"},
+       {CAL_PROPERTY_EVENT_HAS_ALARM,              "has_alarm"},
+       {CAL_PROPERTY_EVENT_SYNC_DATA1,             "sync_data1"},
+       {CAL_PROPERTY_EVENT_SYNC_DATA2,             "sync_data2"},
+       {CAL_PROPERTY_EVENT_SYNC_DATA3,             "sync_data3"},
+       {CAL_PROPERTY_EVENT_SYNC_DATA4,             "sync_data4"},
+       {CAL_PROPERTY_EVENT_START,                  "dtstart_type, dtstart_utime, dtstart_datetime"},
+       {CAL_PROPERTY_EVENT_END,                    "dtend_type, dtend_utime, dtend_datetime"},
+       {CAL_PROPERTY_EVENT_CALENDAR_SYSTEM_TYPE,   "system_type"},
+       {CAL_PROPERTY_EVENT_START_TZID,             "dtstart_tzid"},
+       {CAL_PROPERTY_EVENT_END_TZID,               "dtend_tzid"},
+       {CAL_PROPERTY_EVENT_IS_ALLDAY,              "is_allay"},
+       {(CAL_PROPERTY_CALENDAR_VISIBILITY|CAL_PROPERTY_FLAGS_FILTER),       "visibility"},
+       {(CAL_PROPERTY_CALENDAR_ACCOUNT_ID|CAL_PROPERTY_FLAGS_FILTER),       "account_id"},
+       {(CAL_PROPERTY_ATTENDEE_EMAIL|CAL_PROPERTY_FLAGS_FILTER),            "attendee_email"},
+       {(CAL_PROPERTY_ATTENDEE_NAME|CAL_PROPERTY_FLAGS_FILTER),             "attendee_name"},
+       {(CAL_PROPERTY_ATTENDEE_MEMBER|CAL_PROPERTY_FLAGS_FILTER),           "attendee_member"},
+};
+
+const cal_property_info_s   __property_search_instance_utime_calendar[] =
+{
+       {CAL_PROPERTY_INSTANCE_NORMAL_EVENT_ID,             "event_id"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_START,                "dtstart_type, dtstart_utime, dtstart_datetime"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_END,                  "dtend_type, dtend_utime, dtend_datetime"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_SUMMARY,              "summary"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_LOCATION,             "location"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_CALENDAR_ID,          "calendar_id"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_DESCRIPTION,          "description"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_BUSY_STATUS,          "busy_status"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EVENT_STATUS,         "task_status"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_PRIORITY,             "priority"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_SENSITIVITY,          "sensitivity"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_HAS_RRULE,             "rrule_id"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_LATITUDE,             "latitude"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_LONGITUDE,            "longitude"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_HAS_ALARM,            "has_alarm"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_ORIGINAL_EVENT_ID,    "original_event_id"},
+       {(CAL_PROPERTY_CALENDAR_VISIBILITY|CAL_PROPERTY_FLAGS_FILTER),       "visibility"},
+       {(CAL_PROPERTY_CALENDAR_ACCOUNT_ID|CAL_PROPERTY_FLAGS_FILTER),       "account_id"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_LAST_MODIFIED_TIME,   "last_mod"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_SYNC_DATA1,   "sync_data1"},
+};
+
+const cal_property_info_s   __property_search_instance_localtime_calendar[] =
+{
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EVENT_ID,             "event_id"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_START,                "dtstart_type, dtstart_utime, dtstart_datetime"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_END,                  "dtend_type, dtend_utime, dtend_datetime"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_SUMMARY,              "summary"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_LOCATION,             "location"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_CALENDAR_ID,          "calendar_id"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_DESCRIPTION,          "description"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_BUSY_STATUS,          "busy_status"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EVENT_STATUS,         "task_status"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_PRIORITY,             "priority"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_SENSITIVITY,          "sensitivity"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_HAS_RRULE,             "rrule_id"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_LATITUDE,             "latitude"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_LONGITUDE,            "longitude"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_HAS_ALARM,            "has_alarm"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_ORIGINAL_EVENT_ID,    "original_event_id"},
+       {(CAL_PROPERTY_CALENDAR_VISIBILITY|CAL_PROPERTY_FLAGS_FILTER),       "visibility"},
+       {(CAL_PROPERTY_CALENDAR_ACCOUNT_ID|CAL_PROPERTY_FLAGS_FILTER),       "account_id"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_LAST_MODIFIED_TIME,   "last_mod"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_SYNC_DATA1,   "sync_data1"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_IS_ALLDAY,   "is_allday"},
+};
+
+const cal_property_info_s   __property_search_instance_utime_calendar_extended[] =
+{
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_EVENT_ID,             "event_id"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_START,                "dtstart_type, dtstart_utime, dtstart_datetime"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_END,                  "dtend_type, dtend_utime, dtend_datetime"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SUMMARY,              "summary"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LOCATION,             "location"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_CALENDAR_ID,          "calendar_id"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_DESCRIPTION,          "description"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_BUSY_STATUS,          "busy_status"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_EVENT_STATUS,         "task_status"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_PRIORITY,             "priority"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SENSITIVITY,          "sensitivity"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_RRULE,            "rrule_id"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LATITUDE,             "latitude"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LONGITUDE,            "longitude"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_ALARM,            "has_alarm"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_ORIGINAL_EVENT_ID,    "original_event_id"},
+       {(CAL_PROPERTY_CALENDAR_VISIBILITY|CAL_PROPERTY_FLAGS_FILTER),       "visibility"},
+       {(CAL_PROPERTY_CALENDAR_ACCOUNT_ID|CAL_PROPERTY_FLAGS_FILTER),       "account_id"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LAST_MODIFIED_TIME,   "last_mod"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA1,   "sync_data1"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_ORGANIZER_NAME,   "organizer_name"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_CATEGORIES,   "categories"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_ATTENDEE,   "has_attendee"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA2,   "sync_data2"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA3,   "sync_data3"},
+       {CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA4,   "sync_data4"},
+};
+
+
+const cal_property_info_s   __property_search_instance_localtime_calendar_extended[] =
+{
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_EVENT_ID,             "event_id"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_START,                "dtstart_type, dtstart_utime, dtstart_datetime"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_END,                  "dtend_type, dtend_utime, dtend_datetime"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SUMMARY,              "summary"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LOCATION,             "location"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_CALENDAR_ID,          "calendar_id"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_DESCRIPTION,          "description"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_BUSY_STATUS,          "busy_status"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_EVENT_STATUS,         "task_status"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_PRIORITY,             "priority"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SENSITIVITY,          "sensitivity"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_RRULE,            "rrule_id"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LATITUDE,             "latitude"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LONGITUDE,            "longitude"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_ALARM,            "has_alarm"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_ORIGINAL_EVENT_ID,    "original_event_id"},
+       {(CAL_PROPERTY_CALENDAR_VISIBILITY|CAL_PROPERTY_FLAGS_FILTER),       "visibility"},
+       {(CAL_PROPERTY_CALENDAR_ACCOUNT_ID|CAL_PROPERTY_FLAGS_FILTER),       "account_id"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LAST_MODIFIED_TIME,   "last_mod"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA1,   "sync_data1"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_ORGANIZER_NAME,   "organizer_name"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_CATEGORIES,   "categories"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_ATTENDEE,   "has_attendee"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA2,   "sync_data2"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA3,   "sync_data3"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA4,   "sync_data4"},
+       {CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_IS_ALLDAY,    "is_allday"},
+};
+
+const cal_property_info_s   __property_extended[] =
+{
+       {CAL_PROPERTY_EXTENDED_ID,              "id"},
+       {CAL_PROPERTY_EXTENDED_RECORD_ID,       "record_id"},
+       {CAL_PROPERTY_EXTENDED_RECORD_TYPE,     "record_type"},
+       {CAL_PROPERTY_EXTENDED_KEY,             "key"},
+       {CAL_PROPERTY_EXTENDED_VALUE,           "value"},
+};
+
+typedef struct {
+       char *view_uri;
+       cal_record_type_e type;
+       cal_property_info_s *properties;
+       int property_count;
+}cal_view_uri_info_s;
+
+#define PTR_COUNT(X)    (void*)(X), sizeof(X)/sizeof(cal_property_info_s)
+
+
+static const cal_view_uri_info_s __tables[] = {
+       {CALENDAR_VIEW_CALENDAR,        CAL_RECORD_TYPE_CALENDAR,           PTR_COUNT(__property_calendar_book) },
+       {CALENDAR_VIEW_EVENT,           CAL_RECORD_TYPE_EVENT,              PTR_COUNT(__property_event) },
+       {CALENDAR_VIEW_TODO,            CAL_RECORD_TYPE_TODO,               PTR_COUNT(__property_todo) },
+       {CALENDAR_VIEW_TIMEZONE,        CAL_RECORD_TYPE_TIMEZONE,           PTR_COUNT(__property_timezone) },
+       {CALENDAR_VIEW_ATTENDEE,        CAL_RECORD_TYPE_ATTENDEE,           PTR_COUNT(__property_attendee) },
+       {CALENDAR_VIEW_ALARM,           CAL_RECORD_TYPE_ALARM,              PTR_COUNT(__property_alarm) },
+       {CALENDAR_VIEW_UPDATED_INFO,    CAL_RECORD_TYPE_UPDATED_INFO,       PTR_COUNT(__property_updated_info) },
+       {CALENDAR_VIEW_EVENT_CALENDAR,  CAL_RECORD_TYPE_SEARCH,             PTR_COUNT(__property_search_event_calendar) },
+       {CALENDAR_VIEW_TODO_CALENDAR,   CAL_RECORD_TYPE_SEARCH,             PTR_COUNT(__property_search_todo_calendar ) },
+       {CALENDAR_VIEW_EVENT_CALENDAR_ATTENDEE,  CAL_RECORD_TYPE_SEARCH,    PTR_COUNT(__property_search_event_calendar_attendee) },
+       {CALENDAR_VIEW_INSTANCE_UTIME_CALENDAR, CAL_RECORD_TYPE_INSTANCE_NORMAL, PTR_COUNT(__property_search_instance_utime_calendar) },
+       {CALENDAR_VIEW_INSTANCE_LOCALTIME_CALENDAR, CAL_RECORD_TYPE_INSTANCE_ALLDAY, PTR_COUNT(__property_search_instance_localtime_calendar) },
+       {CALENDAR_VIEW_INSTANCE_UTIME_CALENDAR_EXTENDED, CAL_RECORD_TYPE_INSTANCE_NORMAL_EXTENDED, PTR_COUNT(__property_search_instance_utime_calendar_extended) },
+       {CALENDAR_VIEW_INSTANCE_LOCALTIME_CALENDAR_EXTENDED, CAL_RECORD_TYPE_INSTANCE_ALLDAY_EXTENDED, PTR_COUNT(__property_search_instance_localtime_calendar_extended) },
+       {CALENDAR_VIEW_EXTENDED, CAL_RECORD_TYPE_EXTENDED, PTR_COUNT(__property_extended) },
+};
+
+//////////////////////
+
+static bool cal_uri_property_flag = false;
+static GHashTable *cal_uri_property_hash = NULL;
+#ifdef CAL_IPC_CLIENT
+static int calendar_view_count = 0;
+#endif
+
+void _cal_view_initialize(void)
+{
+       bool bmutex = false;
+
+#ifdef CAL_IPC_CLIENT
+       _cal_mutex_lock(CAL_MUTEX_PROPERTY_HASH);
+       calendar_view_count++;
+       _cal_mutex_unlock(CAL_MUTEX_PROPERTY_HASH);
+#endif
+
+       if (cal_uri_property_flag == false)
+       {
+               _cal_mutex_lock(CAL_MUTEX_PROPERTY_HASH);
+               bmutex = true;
+       }
+
+       if ( cal_uri_property_hash == NULL)
+       {
+               cal_uri_property_hash = g_hash_table_new(g_str_hash, g_str_equal);
+               if (cal_uri_property_hash)
+               {
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_CALENDAR, GINT_TO_POINTER(&(__tables[0])) );
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_EVENT, GINT_TO_POINTER(&(__tables[1])) );
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_TODO, GINT_TO_POINTER(&(__tables[2])) );
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_TIMEZONE, GINT_TO_POINTER(&(__tables[3])));
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_ATTENDEE, GINT_TO_POINTER(&(__tables[4])));
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_ALARM, GINT_TO_POINTER(&(__tables[5])));
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_UPDATED_INFO, GINT_TO_POINTER(&(__tables[6])));
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_EVENT_CALENDAR, GINT_TO_POINTER(&(__tables[7])));
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_TODO_CALENDAR, GINT_TO_POINTER(&(__tables[8])));
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_EVENT_CALENDAR_ATTENDEE, GINT_TO_POINTER(&(__tables[9])));
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_INSTANCE_UTIME_CALENDAR, GINT_TO_POINTER(&(__tables[10])));
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_INSTANCE_LOCALTIME_CALENDAR, GINT_TO_POINTER(&(__tables[11])));
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_INSTANCE_UTIME_CALENDAR_EXTENDED, GINT_TO_POINTER(&(__tables[12])));
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_INSTANCE_LOCALTIME_CALENDAR_EXTENDED, GINT_TO_POINTER(&(__tables[13])));
+                       g_hash_table_insert(cal_uri_property_hash, CALENDAR_VIEW_EXTENDED, GINT_TO_POINTER(&(__tables[14])));
+               }
+       }
+
+       if (bmutex == true)
+       {
+               cal_uri_property_flag = true;
+               _cal_mutex_unlock(CAL_MUTEX_PROPERTY_HASH);
+       }
+
+       return ;
+}
+
+cal_record_type_e _cal_view_get_type(const char *view_uri)
+{
+       cal_view_uri_info_s* view_uri_info = NULL;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+
+       if(cal_uri_property_hash){
+               view_uri_info = g_hash_table_lookup(cal_uri_property_hash, view_uri);
+               if( view_uri_info ) {
+                       type = view_uri_info->type;
+                       //CAL_DBG("%s:%d",view_uri,type);
+               }
+               else
+               {
+                       ERR("g_hash_table_lookup() failed");
+               }
+       }
+       else
+       {
+               ERR("Unable to get cal_uri_property_hash");
+       }
+
+       return type;
+}
+
+void _cal_view_finalize(void)
+{
+#ifdef CAL_IPC_CLIENT
+       _cal_mutex_lock(CAL_MUTEX_PROPERTY_HASH);
+       if (calendar_view_count <= 0)
+       {
+               _cal_mutex_unlock(CAL_MUTEX_PROPERTY_HASH);
+               return ;
+       }
+       calendar_view_count--;
+
+       if (calendar_view_count == 0)
+       {
+               if (cal_uri_property_hash != NULL) {
+                       g_hash_table_destroy(cal_uri_property_hash);
+                       cal_uri_property_hash = NULL;
+               }
+       }
+       _cal_mutex_unlock(CAL_MUTEX_PROPERTY_HASH);
+#endif
+}
+
+const cal_property_info_s* _cal_view_get_property_info(const char *view_uri, int *count)
+{
+       cal_property_info_s* tmp = NULL;
+       cal_view_uri_info_s* view_uri_info = NULL;
+
+       if(cal_uri_property_hash){
+               view_uri_info = g_hash_table_lookup(cal_uri_property_hash, view_uri);
+               if( view_uri_info ) {
+                       tmp = view_uri_info->properties;
+                       *count = view_uri_info->property_count;
+               }
+       }
+
+       return tmp;
+}
+
+const char* _cal_view_get_uri(const char *view_uri)
+{
+       cal_view_uri_info_s* view_uri_info = NULL;
+
+       if(cal_uri_property_hash){
+               view_uri_info = g_hash_table_lookup(cal_uri_property_hash, view_uri);
+               if( view_uri_info ) {
+                       return view_uri_info->view_uri;
+               }
+       }
+
+       return NULL;
+}
diff --git a/common/cal_view.h b/common/cal_view.h
new file mode 100644 (file)
index 0000000..16091b4
--- /dev/null
@@ -0,0 +1,358 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __CALENDAR_SVC_VIEW_H__
+#define __CALENDAR_SVC_VIEW_H__
+
+#include "calendar_view.h"
+
+// db record view // get, get_list, insert, update, delete, filter
+#define CALENDAR_VIEW_CALENDAR              "tizen.calendar_view.calendar"
+#define CALENDAR_VIEW_EVENT                 "tizen.calendar_view.event"
+#define CALENDAR_VIEW_TODO                  "tizen.calendar_view.todo"
+#define CALENDAR_VIEW_TIMEZONE              "tizen.calendar_view.timezone"
+// child view
+#define CALENDAR_VIEW_ATTENDEE              "tizen.calendar_view.attendee"
+#define CALENDAR_VIEW_ALARM                 "tizen.calendar_view.alarm"
+
+// updated info  // get_list
+#define CALENDAR_VIEW_UPDATED_INFO          "tizen.calendar_view.updated_info"
+
+// extended_table
+#define CALENDAR_VIEW_EXTENDED              "tizen,calendar_view.extended_property"
+
+// only for query (filter)
+#define CALENDAR_VIEW_EVENT_CALENDAR             "tizen.calendar_view.event/calendar"
+#define CALENDAR_VIEW_TODO_CALENDAR              "tizen.calendar_view.todo/calendar"
+#define CALENDAR_VIEW_EVENT_CALENDAR_ATTENDEE    "tizen.calendar_view.event/calendar/attendee"
+#define CALENDAR_VIEW_INSTANCE_UTIME_CALENDAR   "tizen.calendar_view.instance_utime/calendar"
+#define CALENDAR_VIEW_INSTANCE_LOCALTIME_CALENDAR   "tizen.calendar_view.instance_localtime/calendar"
+#define CALENDAR_VIEW_INSTANCE_UTIME_CALENDAR_EXTENDED   "tizen.calendar_view.extended/instance_utime/calendar"
+#define CALENDAR_VIEW_INSTANCE_LOCALTIME_CALENDAR_EXTENDED   "tizen.calendar_view.extended/instance_localtime/calendar"
+
+// for type check         // data_type mask 0x000FF000
+#define CAL_PROPERTY_DATA_TYPE_MASK             0x000FF000
+#define CAL_PROPERTY_DATA_TYPE_INT              0x00001000
+#define CAL_PROPERTY_DATA_TYPE_STR              0x00002000
+#define CAL_PROPERTY_DATA_TYPE_DOUBLE           0x00003000
+#define CAL_PROPERTY_DATA_TYPE_LLI              0x00004000
+#define CAL_PROPERTY_DATA_TYPE_CALTIME          0x00005000
+#define CAL_PROPERTY_DATA_TYPE_REC              0x00006000
+#define CAL_PROPERTY_CHECK_DATA_TYPE(property_id,data_type) \
+       ((property_id&CAL_PROPERTY_DATA_TYPE_MASK) == data_type ? true : false)
+// for property                             //  0xFF000000
+#define CAL_PROPERTY_MASK                       0xFF000000
+#define CAL_PROPERTY_CALENDAR                   0x01000000
+#define CAL_PROPERTY_EVENT                      0x02000000
+#define CAL_PROPERTY_TODO                       0x03000000
+#define CAL_PROPERTY_TIMEZONE                   0x04000000
+#define CAL_PROPERTY_ATTENDEE                   0x05000000
+#define CAL_PROPERTY_ALARM                      0x06000000
+#define CAL_PROPERTY_INSTANCE_NORMAL            0x07000000
+#define CAL_PROPERTY_INSTANCE_ALLDAY            0x08000000
+#define CAL_PROPERTY_UPDATED_INFO               0x09000000
+#define CAL_PROPERTY_EXTENDED                   0x0A000000
+#define CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED   0x0B000000
+#define CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED   0x0C000000
+#define CAL_PROPERTY_CHECK(property_id,data_type) \
+       ((property_id&CAL_PROPERTY_MASK) == data_type ? true : false)
+
+#define CAL_PROPERTY_FLAGS_MASK                 0x00F00000
+#define CAL_PROPERTY_FLAGS_FILTER               0x00100000
+#define CAL_PROPERTY_FLAGS_PROJECTION           0x00200000
+#define CAL_PROPERTY_FLAGS_READ_ONLY            0x00300000
+#define CAL_PROPERTY_CHECK_FLAGS(property_id,data_type) \
+       ((property_id&CAL_PROPERTY_FLAGS_MASK) == data_type ? true : false)
+
+typedef enum {
+       CAL_PROPERTY_CALENDAR_ID                = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY),
+       CAL_PROPERTY_CALENDAR_UID               = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_STR) +1,
+       CAL_PROPERTY_CALENDAR_NAME              = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_STR) +2,
+       CAL_PROPERTY_CALENDAR_DESCRIPTION       = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_STR) +3,
+       CAL_PROPERTY_CALENDAR_COLOR             = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_STR) +4,
+       CAL_PROPERTY_CALENDAR_LOCATION          = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_STR) +5,
+       CAL_PROPERTY_CALENDAR_VISIBILITY        = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_INT) +6,
+       CAL_PROPERTY_CALENDAR_SYNC_EVENT        = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_INT) +7,
+       CAL_PROPERTY_CALENDAR_ACCOUNT_ID        = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_INT) +8,
+       CAL_PROPERTY_CALENDAR_STORE_TYPE        = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_INT) +9,
+       CAL_PROPERTY_CALENDAR_SYNC_DATA1        = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_STR) +10,
+       CAL_PROPERTY_CALENDAR_SYNC_DATA2        = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_STR) +11,
+       CAL_PROPERTY_CALENDAR_SYNC_DATA3        = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_STR) +12,
+       CAL_PROPERTY_CALENDAR_SYNC_DATA4        = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_STR) +13,
+       CAL_PROPERTY_CALENDAR_MODE              = (CAL_PROPERTY_CALENDAR|CAL_PROPERTY_DATA_TYPE_INT) +14,
+
+       CAL_PROPERTY_EVENT_ID                   = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY),
+       CAL_PROPERTY_EVENT_CALENDAR_ID          = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +1,
+       CAL_PROPERTY_EVENT_SUMMARY              = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +2,
+       CAL_PROPERTY_EVENT_DESCRIPTION          = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +3,
+       CAL_PROPERTY_EVENT_LOCATION             = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +4,
+       CAL_PROPERTY_EVENT_CATEGORIES           = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +5,
+       CAL_PROPERTY_EVENT_EXDATE               = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +6,
+       CAL_PROPERTY_EVENT_EVENT_STATUS         = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +7,
+       CAL_PROPERTY_EVENT_PRIORITY             = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +8,
+       CAL_PROPERTY_EVENT_TIMEZONE             = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +9,
+       CAL_PROPERTY_EVENT_CONTACT_ID           = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +10,
+       CAL_PROPERTY_EVENT_BUSY_STATUS          = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +11,
+       CAL_PROPERTY_EVENT_SENSITIVITY          = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +12,
+       CAL_PROPERTY_EVENT_UID                  = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +13,
+       CAL_PROPERTY_EVENT_ORGANIZER_NAME       = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +14,
+       CAL_PROPERTY_EVENT_ORGANIZER_EMAIL      = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +15,
+       CAL_PROPERTY_EVENT_MEETING_STATUS       = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +16,
+       CAL_PROPERTY_EVENT_ORIGINAL_EVENT_ID    = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +17,
+       CAL_PROPERTY_EVENT_LATITUDE             = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_DOUBLE) +18,
+       CAL_PROPERTY_EVENT_LONGITUDE            = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_DOUBLE) +19,
+       CAL_PROPERTY_EVENT_EMAIL_ID             = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +20,
+       CAL_PROPERTY_EVENT_CREATED_TIME         = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_LLI) +21,
+       CAL_PROPERTY_EVENT_LAST_MODIFIED_TIME   = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_LLI|CAL_PROPERTY_FLAGS_READ_ONLY) +22,
+       CAL_PROPERTY_EVENT_IS_DELETED           = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY) +23,
+       CAL_PROPERTY_EVENT_FREQ                 = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +24,
+       CAL_PROPERTY_EVENT_RANGE_TYPE           = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +25,
+       CAL_PROPERTY_EVENT_UNTIL                = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_CALTIME) +26,
+       CAL_PROPERTY_EVENT_COUNT                = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +27,
+       CAL_PROPERTY_EVENT_INTERVAL             = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +28,
+       CAL_PROPERTY_EVENT_BYSECOND             = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +29,
+       CAL_PROPERTY_EVENT_BYMINUTE             = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +30,
+       CAL_PROPERTY_EVENT_BYHOUR               = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +31,
+       CAL_PROPERTY_EVENT_BYDAY                = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +32,
+       CAL_PROPERTY_EVENT_BYMONTHDAY           = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +33,
+       CAL_PROPERTY_EVENT_BYYEARDAY            = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +34,
+       CAL_PROPERTY_EVENT_BYWEEKNO             = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +35,
+       CAL_PROPERTY_EVENT_BYMONTH              = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +36,
+       CAL_PROPERTY_EVENT_BYSETPOS             = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +37,
+       CAL_PROPERTY_EVENT_WKST                 = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +38,
+       CAL_PROPERTY_EVENT_RECURRENCE_ID        = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +39,
+       CAL_PROPERTY_EVENT_RDATE                = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +40,
+       CAL_PROPERTY_EVENT_HAS_ATTENDEE         = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY) +41,
+       CAL_PROPERTY_EVENT_HAS_ALARM            = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY) +42,
+       CAL_PROPERTY_EVENT_SYNC_DATA1           = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +43,
+       CAL_PROPERTY_EVENT_SYNC_DATA2           = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +44,
+       CAL_PROPERTY_EVENT_SYNC_DATA3           = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +45,
+       CAL_PROPERTY_EVENT_SYNC_DATA4           = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +46,
+       CAL_PROPERTY_EVENT_START                = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_CALTIME) +47,
+       CAL_PROPERTY_EVENT_END                  = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_CALTIME) +48,
+       CAL_PROPERTY_EVENT_CALENDAR_ALARM       = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_REC) +49,
+       CAL_PROPERTY_EVENT_CALENDAR_ATTENDEE    = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_REC) +50,
+       CAL_PROPERTY_EVENT_CALENDAR_SYSTEM_TYPE = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT) +51,
+       CAL_PROPERTY_EVENT_START_TZID           = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +52,
+       CAL_PROPERTY_EVENT_END_TZID             = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_STR) +53,
+       CAL_PROPERTY_EVENT_EXCEPTION            = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_REC) +54,
+       CAL_PROPERTY_EVENT_EXTENDED             = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_REC) +55,
+       CAL_PROPERTY_EVENT_IS_ALLDAY            = (CAL_PROPERTY_EVENT|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY) +56,
+
+       CAL_PROPERTY_TODO_ID                    =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY),
+       CAL_PROPERTY_TODO_CALENDAR_ID           =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT) +1,
+       CAL_PROPERTY_TODO_SUMMARY               =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +2,
+       CAL_PROPERTY_TODO_DESCRIPTION           =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +3,
+       CAL_PROPERTY_TODO_LOCATION              =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +4,
+       CAL_PROPERTY_TODO_CATEGORIES            =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +5,
+       CAL_PROPERTY_TODO_TODO_STATUS           =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT) +6,
+       CAL_PROPERTY_TODO_PRIORITY              =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT) +7,
+       CAL_PROPERTY_TODO_SENSITIVITY           =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT) +8,
+       CAL_PROPERTY_TODO_UID                   =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +9,
+       CAL_PROPERTY_TODO_LATITUDE              =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_DOUBLE) +10,
+       CAL_PROPERTY_TODO_LONGITUDE             =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_DOUBLE) +11,
+       CAL_PROPERTY_TODO_PROGRESS              =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT) +12,
+       CAL_PROPERTY_TODO_CREATED_TIME          =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_LLI) +13,
+       CAL_PROPERTY_TODO_LAST_MODIFIED_TIME    =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_LLI|CAL_PROPERTY_FLAGS_READ_ONLY) +14,
+       CAL_PROPERTY_TODO_COMPLETED_TIME        =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_LLI) +15,
+       CAL_PROPERTY_TODO_IS_DELETED            =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY) +16,
+       CAL_PROPERTY_TODO_FREQ                  =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT) +17,
+       CAL_PROPERTY_TODO_RANGE_TYPE            =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT) +18,
+       CAL_PROPERTY_TODO_UNTIL                 =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_CALTIME) +19,
+       CAL_PROPERTY_TODO_COUNT                 =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT) +20,
+       CAL_PROPERTY_TODO_INTERVAL              =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT) +21,
+       CAL_PROPERTY_TODO_BYSECOND              =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +22,
+       CAL_PROPERTY_TODO_BYMINUTE              =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +23,
+       CAL_PROPERTY_TODO_BYHOUR                =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +24,
+       CAL_PROPERTY_TODO_BYDAY                 =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +25,
+       CAL_PROPERTY_TODO_BYMONTHDAY            =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +26,
+       CAL_PROPERTY_TODO_BYYEARDAY             =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +27,
+       CAL_PROPERTY_TODO_BYWEEKNO              =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +28,
+       CAL_PROPERTY_TODO_BYMONTH               =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +29,
+       CAL_PROPERTY_TODO_BYSETPOS              =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +30,
+       CAL_PROPERTY_TODO_WKST                  =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT) +31,
+       CAL_PROPERTY_TODO_HAS_ALARM             =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY) +32,
+       CAL_PROPERTY_TODO_SYNC_DATA1            =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +33,
+       CAL_PROPERTY_TODO_SYNC_DATA2            =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +34,
+       CAL_PROPERTY_TODO_SYNC_DATA3            =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +35,
+       CAL_PROPERTY_TODO_SYNC_DATA4            =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +36,
+       CAL_PROPERTY_TODO_START                 =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_CALTIME) +37,
+       CAL_PROPERTY_TODO_DUE                   =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_CALTIME) +38,
+       CAL_PROPERTY_TODO_CALENDAR_ALARM        =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_REC) +39,
+       CAL_PROPERTY_TODO_START_TZID            =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +40,
+       CAL_PROPERTY_TODO_DUE_TZID              =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +41,
+       CAL_PROPERTY_TODO_ORGANIZER_NAME        =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +42,
+       CAL_PROPERTY_TODO_ORGANIZER_EMAIL       =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_STR) +43,
+       CAL_PROPERTY_TODO_HAS_ATTENDEE          =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY) +44,
+       CAL_PROPERTY_TODO_CALENDAR_ATTENDEE     =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_REC) +45,
+       CAL_PROPERTY_TODO_EXTENDED              =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_REC) +46,
+       CAL_PROPERTY_TODO_IS_ALLDAY             =(CAL_PROPERTY_TODO|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY) +47,
+
+       CAL_PROPERTY_TIMEZONE_ID                                =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY),
+       CAL_PROPERTY_TIMEZONE_TZ_OFFSET_FROM_GMT                =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_INT)+1,
+       CAL_PROPERTY_TIMEZONE_STANDARD_NAME                     =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_STR)+2,
+       CAL_PROPERTY_TIMEZONE_STD_START_MONTH                   =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_INT)+3,
+       CAL_PROPERTY_TIMEZONE_STD_START_POSITION_OF_WEEK        =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_INT)+4,
+       CAL_PROPERTY_TIMEZONE_STD_START_DAY                     =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_INT)+5,
+       CAL_PROPERTY_TIMEZONE_STD_START_HOUR                    =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_INT)+6,
+       CAL_PROPERTY_TIMEZONE_STANDARD_BIAS                     =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_INT)+7,
+       CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME                    =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_STR)+8,
+       CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_MONTH             =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_INT)+9,
+       CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_POSITION_OF_WEEK  =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_INT)+10,
+       CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_DAY               =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_INT)+11,
+       CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_HOUR              =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_INT)+12,
+       CAL_PROPERTY_TIMEZONE_DAY_LIGHT_BIAS                    =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_INT)+13,
+       CAL_PROPERTY_TIMEZONE_CALENDAR_ID                       =(CAL_PROPERTY_TIMEZONE|CAL_PROPERTY_DATA_TYPE_INT)+14,
+
+       CAL_PROPERTY_ATTENDEE_NUMBER            =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_STR),
+       CAL_PROPERTY_ATTENDEE_CUTYPE            =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_INT)+1,
+       CAL_PROPERTY_ATTENDEE_CT_INDEX          =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_INT)+2,
+       CAL_PROPERTY_ATTENDEE_UID               =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_STR)+3,
+       CAL_PROPERTY_ATTENDEE_GROUP             =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_STR)+4,
+       CAL_PROPERTY_ATTENDEE_EMAIL             =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_STR)+5,
+       CAL_PROPERTY_ATTENDEE_ROLE              =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_INT)+6,
+       CAL_PROPERTY_ATTENDEE_STATUS            =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_INT)+7,
+       CAL_PROPERTY_ATTENDEE_RSVP              =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_INT)+8,
+       CAL_PROPERTY_ATTENDEE_DELEGATEE_URI     =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_STR)+9,
+       CAL_PROPERTY_ATTENDEE_DELEGATOR_URI     =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_STR)+10,
+       CAL_PROPERTY_ATTENDEE_NAME              =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_STR)+11,
+       CAL_PROPERTY_ATTENDEE_MEMBER            =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_STR)+12,
+       CAL_PROPERTY_ATTENDEE_PARENT_ID         =(CAL_PROPERTY_ATTENDEE|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY)+13,
+
+       CAL_PROPERTY_ALARM_TICK                 =(CAL_PROPERTY_ALARM|CAL_PROPERTY_DATA_TYPE_INT),
+       CAL_PROPERTY_ALARM_TICK_UNIT            =(CAL_PROPERTY_ALARM|CAL_PROPERTY_DATA_TYPE_INT)+1,
+       CAL_PROPERTY_ALARM_DESCRIPTION          =(CAL_PROPERTY_ALARM|CAL_PROPERTY_DATA_TYPE_STR)+2,
+       CAL_PROPERTY_ALARM_PARENT_ID                    =(CAL_PROPERTY_ALARM|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY)+3,
+       CAL_PROPERTY_ALARM_SUMMARY              =(CAL_PROPERTY_ALARM|CAL_PROPERTY_DATA_TYPE_STR)+4,
+       CAL_PROPERTY_ALARM_ACTION               =(CAL_PROPERTY_ALARM|CAL_PROPERTY_DATA_TYPE_INT)+5,
+       CAL_PROPERTY_ALARM_ATTACH               =(CAL_PROPERTY_ALARM|CAL_PROPERTY_DATA_TYPE_STR)+6,
+       CAL_PROPERTY_ALARM_ALARM                =(CAL_PROPERTY_ALARM|CAL_PROPERTY_DATA_TYPE_CALTIME)+7,
+
+       CAL_PROPERTY_INSTANCE_NORMAL_EVENT_ID       =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_INT),
+       CAL_PROPERTY_INSTANCE_NORMAL_START          =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_CALTIME) +1,
+       CAL_PROPERTY_INSTANCE_NORMAL_END            =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_CALTIME) +2,
+       CAL_PROPERTY_INSTANCE_NORMAL_SUMMARY        =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_STR)+3,
+       CAL_PROPERTY_INSTANCE_NORMAL_LOCATION       =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_STR)+4,
+       CAL_PROPERTY_INSTANCE_NORMAL_CALENDAR_ID    =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_INT)+5,
+       CAL_PROPERTY_INSTANCE_NORMAL_DESCRIPTION    =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_STR)+6,
+       CAL_PROPERTY_INSTANCE_NORMAL_BUSY_STATUS    =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_INT)+7,
+       CAL_PROPERTY_INSTANCE_NORMAL_EVENT_STATUS   =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_INT)+8,
+       CAL_PROPERTY_INSTANCE_NORMAL_PRIORITY       =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_INT)+9,
+       CAL_PROPERTY_INSTANCE_NORMAL_SENSITIVITY    =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_INT)+10,
+       CAL_PROPERTY_INSTANCE_NORMAL_HAS_RRULE      =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_INT)+11,
+       CAL_PROPERTY_INSTANCE_NORMAL_LATITUDE       =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_DOUBLE)+12,
+       CAL_PROPERTY_INSTANCE_NORMAL_LONGITUDE      =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_DOUBLE)+13,
+       CAL_PROPERTY_INSTANCE_NORMAL_HAS_ALARM      =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_INT)+14,
+       CAL_PROPERTY_INSTANCE_NORMAL_ORIGINAL_EVENT_ID  =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_INT)+15,
+       CAL_PROPERTY_INSTANCE_NORMAL_LAST_MODIFIED_TIME =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_LLI)+16,
+       CAL_PROPERTY_INSTANCE_NORMAL_SYNC_DATA1     =(CAL_PROPERTY_INSTANCE_NORMAL|CAL_PROPERTY_DATA_TYPE_STR)+17,
+
+       CAL_PROPERTY_INSTANCE_ALLDAY_EVENT_ID       =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_INT),
+       CAL_PROPERTY_INSTANCE_ALLDAY_START          =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_CALTIME) +1,
+       CAL_PROPERTY_INSTANCE_ALLDAY_END            =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_CALTIME) +2,
+       CAL_PROPERTY_INSTANCE_ALLDAY_SUMMARY        =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_STR)+3,
+       CAL_PROPERTY_INSTANCE_ALLDAY_LOCATION       =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_STR)+4,
+       CAL_PROPERTY_INSTANCE_ALLDAY_CALENDAR_ID    =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_INT)+5,
+       CAL_PROPERTY_INSTANCE_ALLDAY_DESCRIPTION    =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_STR)+6,
+       CAL_PROPERTY_INSTANCE_ALLDAY_BUSY_STATUS    =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_INT)+7,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EVENT_STATUS   =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_INT)+8,
+       CAL_PROPERTY_INSTANCE_ALLDAY_PRIORITY       =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_INT)+9,
+       CAL_PROPERTY_INSTANCE_ALLDAY_SENSITIVITY    =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_INT)+10,
+       CAL_PROPERTY_INSTANCE_ALLDAY_HAS_RRULE      =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_INT)+11,
+       CAL_PROPERTY_INSTANCE_ALLDAY_LATITUDE       =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_DOUBLE)+12,
+       CAL_PROPERTY_INSTANCE_ALLDAY_LONGITUDE      =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_DOUBLE)+13,
+       CAL_PROPERTY_INSTANCE_ALLDAY_HAS_ALARM      =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_INT)+14,
+       CAL_PROPERTY_INSTANCE_ALLDAY_ORIGINAL_EVENT_ID  =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_INT)+15,
+       CAL_PROPERTY_INSTANCE_ALLDAY_LAST_MODIFIED_TIME =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_LLI)+16,
+       CAL_PROPERTY_INSTANCE_ALLDAY_SYNC_DATA1     =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_STR)+17,
+       CAL_PROPERTY_INSTANCE_ALLDAY_IS_ALLDAY      =(CAL_PROPERTY_INSTANCE_ALLDAY|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY)+18,
+
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_EVENT_ID       =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT),
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_START          =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_CALTIME) +1,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_END            =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_CALTIME) +2,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SUMMARY        =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+3,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LOCATION       =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+4,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_CALENDAR_ID    =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+5,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_DESCRIPTION    =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+6,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_BUSY_STATUS    =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+7,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_EVENT_STATUS   =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+8,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_PRIORITY       =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+9,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SENSITIVITY    =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+10,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_RRULE      =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+11,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LATITUDE       =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_DOUBLE)+12,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LONGITUDE      =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_DOUBLE)+13,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_ALARM      =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+14,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_ORIGINAL_EVENT_ID  =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+15,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LAST_MODIFIED_TIME =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_LLI)+16,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA1     =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+17,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_ORGANIZER_NAME =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+18,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_CATEGORIES     =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+19,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_ATTENDEE   =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+20,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA2     =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+21,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA3     =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+22,
+       CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA4     =(CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+23,
+
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_EVENT_ID       =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT),
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_START          =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_CALTIME) +1,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_END            =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_CALTIME) +2,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SUMMARY        =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+3,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LOCATION       =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+4,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_CALENDAR_ID    =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+5,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_DESCRIPTION    =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+6,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_BUSY_STATUS    =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+7,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_EVENT_STATUS   =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+8,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_PRIORITY       =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+9,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SENSITIVITY    =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+10,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_RRULE      =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+11,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LATITUDE       =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_DOUBLE)+12,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LONGITUDE      =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_DOUBLE)+13,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_ALARM      =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+14,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_ORIGINAL_EVENT_ID  =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+15,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LAST_MODIFIED_TIME =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_LLI)+16,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA1     =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+17,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_ORGANIZER_NAME =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+18,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_CATEGORIES     =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+19,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_ATTENDEE   =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+20,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA2     =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+21,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA3     =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+22,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA4     =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+23,
+       CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_IS_ALLDAY      =(CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY)+24,
+
+
+       CAL_PROPERTY_UPDATED_INFO_ID                =(CAL_PROPERTY_UPDATED_INFO|CAL_PROPERTY_DATA_TYPE_INT),
+       CAL_PROPERTY_UPDATED_INFO_CALENDAR_ID       =(CAL_PROPERTY_UPDATED_INFO|CAL_PROPERTY_DATA_TYPE_INT)+1,
+       CAL_PROPERTY_UPDATED_INFO_TYPE              =(CAL_PROPERTY_UPDATED_INFO|CAL_PROPERTY_DATA_TYPE_INT)+2,
+       CAL_PROPERTY_UPDATED_INFO_VERSION           =(CAL_PROPERTY_UPDATED_INFO|CAL_PROPERTY_DATA_TYPE_INT)+3,
+
+       CAL_PROPERTY_EXTENDED_ID                    =(CAL_PROPERTY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT|CAL_PROPERTY_FLAGS_READ_ONLY),
+       CAL_PROPERTY_EXTENDED_RECORD_ID             =(CAL_PROPERTY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+1,
+       CAL_PROPERTY_EXTENDED_RECORD_TYPE           =(CAL_PROPERTY_EXTENDED|CAL_PROPERTY_DATA_TYPE_INT)+2,
+       CAL_PROPERTY_EXTENDED_KEY                   =(CAL_PROPERTY_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+3,
+       CAL_PROPERTY_EXTENDED_VALUE                 =(CAL_PROPERTY_EXTENDED|CAL_PROPERTY_DATA_TYPE_STR)+4,
+
+} cal_property_ids_e;
+
+void _cal_view_initialize(void);
+cal_record_type_e _cal_view_get_type(const char *view_uri);
+void _cal_view_finalize(void);
+
+const cal_property_info_s* _cal_view_get_property_info(const char *view_uri, int *count);
+
+const char* _cal_view_get_uri(const char *view_uri);
+
+#endif /* __CALENDAR_SVC_VIEW_H__ */
diff --git a/common/ipc/cal_ipc.h b/common/ipc/cal_ipc.h
new file mode 100644 (file)
index 0000000..49cf24c
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CAL_IPC_H__
+#define __CAL_IPC_H__
+
+#define CAL_IPC_SERVICE                             "cal_svc_ipc"
+#define CAL_IPC_SOCKET_PATH                         "/tmp/."CAL_IPC_SERVICE
+#define CAL_IPC_SOCKET_PATH_FOR_SUBSCRIPTION        "/tmp/."CAL_IPC_SERVICE"_for_subscription"
+#define CAL_IPC_MODULE                              "cal_ipc_module"
+#define CAL_IPC_MODULE_FOR_SUBSCRIPTION             CAL_IPC_MODULE"_for_subscription"
+
+#define CAL_IPC_SERVER_CONNECT                      "connect"
+#define CAL_IPC_SERVER_DISCONNECT                   "disconnect"
+#define CAL_IPC_SERVER_CHECK_PERMISSION                                "check_permission"
+
+#define CAL_IPC_SERVER_DB_INSERT_RECORD             "insert_record"
+#define CAL_IPC_SERVER_DB_GET_RECORD                "get_record"
+#define CAL_IPC_SERVER_DB_UPDATE_RECORD             "update_record"
+#define CAL_IPC_SERVER_DB_DELETE_RECORD             "delete_record"
+#define CAL_IPC_SERVER_DB_GET_ALL_RECORDS           "get_all_records"
+#define CAL_IPC_SERVER_DB_GET_RECORDS_WITH_QUERY    "get_records_with_query"
+#define CAL_IPC_SERVER_DB_CLEAN_AFTER_SYNC          "clean_after_sync"
+#define CAL_IPC_SERVER_DB_GET_COUNT                 "get_count"
+#define CAL_IPC_SERVER_DB_GET_COUNT_WITH_QUERY      "get_count_with_query"
+#define CAL_IPC_SERVER_DB_INSERT_RECORDS            "insert_records"
+#define CAL_IPC_SERVER_DB_UPDATE_RECORDS            "update_records"
+#define CAL_IPC_SERVER_DB_DELETE_RECORDS            "delete_records"
+#define CAL_IPC_SERVER_DB_CHANGES_BY_VERSION        "changes_by_version"
+#define CAL_IPC_SERVER_DB_GET_CURRENT_VERSION       "get_current_version"
+#define CAL_IPC_SERVER_DB_INSERT_VCALENDARS         "insert_vcalendars"
+#define CAL_IPC_SERVER_DB_REPLACE_VCALENDARS        "replace_vcalendars"
+#define CAL_IPC_SERVER_DB_REPLACE_RECORD            "replace_record"
+#define CAL_IPC_SERVER_DB_REPLACE_RECORDS           "replace_records"
+#define CAL_IPC_SERVER_DB_CHANGES_EXCEPTION         "changes_exception"
+
+#ifdef CAL_MEMORY_TEST
+#define CAL_IPC_SERVER_DESTROY                      "destroy"
+#endif // #ifdef CAL_MEMORY_TEST
+#endif /*__CAL_IPC_H__*/
diff --git a/common/ipc/cal_ipc_marshal.c b/common/ipc/cal_ipc_marshal.c
new file mode 100644 (file)
index 0000000..fdf2ae6
--- /dev/null
@@ -0,0 +1,1121 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h> //calloc
+#include <string.h>
+
+#include "calendar_query.h"
+#include "calendar_filter.h"
+#include "calendar_list.h"
+
+#include "cal_ipc_marshal.h"
+#include "cal_record.h"
+#include "cal_internal.h"
+#include "cal_view.h"
+
+extern cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_calendar_plugin_cb;
+extern cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_event_plugin_cb;
+extern cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_todo_plugin_cb;
+extern cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_alarm_plugin_cb;
+extern cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_attendee_plugin_cb;
+extern cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_timezone_plugin_cb;
+extern cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_updated_info_plugin_cb;
+extern cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_instance_normal_plugin_cb;
+extern cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_instance_normal_extended_plugin_cb;
+extern cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_instance_allday_plugin_cb;
+extern cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_instance_allday_extended_plugin_cb;
+extern cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_search_plugin_cb;
+extern cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_extended_plugin_cb;
+
+static cal_ipc_marshal_record_plugin_cb_s* __cal_ipc_marshal_get_plugin_cb(cal_record_type_e type);
+
+static int __cal_ipc_unmarshal_composite_filter(const pims_ipc_data_h ipc_data, cal_composite_filter_s* filter);
+static int __cal_ipc_marshal_composite_filter(const cal_composite_filter_s* filter, pims_ipc_data_h ipc_data);
+static int __cal_ipc_unmarshal_attribute_filter(const pims_ipc_data_h ipc_data, const cal_filter_type_e filter_type, cal_attribute_filter_s* filter);
+static int __cal_ipc_marshal_attribute_filter(const cal_attribute_filter_s* filter, pims_ipc_data_h ipc_data);
+
+static cal_ipc_marshal_record_plugin_cb_s* __cal_ipc_marshal_get_plugin_cb(cal_record_type_e type)
+{
+       switch (type)
+       {
+       case CAL_RECORD_TYPE_CALENDAR:
+               return (&_cal_ipc_record_calendar_plugin_cb);
+       case CAL_RECORD_TYPE_EVENT:
+               return (&_cal_ipc_record_event_plugin_cb);
+       case CAL_RECORD_TYPE_TODO:
+               return (&_cal_ipc_record_todo_plugin_cb);
+       case CAL_RECORD_TYPE_ALARM:
+               return (&_cal_ipc_record_alarm_plugin_cb);
+       case CAL_RECORD_TYPE_ATTENDEE:
+               return (&_cal_ipc_record_attendee_plugin_cb);
+       case CAL_RECORD_TYPE_TIMEZONE:
+               return (&_cal_ipc_record_timezone_plugin_cb);
+       case CAL_RECORD_TYPE_INSTANCE_NORMAL:
+               return (&_cal_ipc_record_instance_normal_plugin_cb);
+       case CAL_RECORD_TYPE_INSTANCE_ALLDAY:
+               return (&_cal_ipc_record_instance_allday_plugin_cb);
+       case CAL_RECORD_TYPE_INSTANCE_NORMAL_EXTENDED:
+               return (&_cal_ipc_record_instance_normal_extended_plugin_cb);
+       case CAL_RECORD_TYPE_INSTANCE_ALLDAY_EXTENDED:
+               return (&_cal_ipc_record_instance_allday_extended_plugin_cb);
+       case CAL_RECORD_TYPE_UPDATED_INFO:
+               return (&_cal_ipc_record_updated_info_plugin_cb);
+       case CAL_RECORD_TYPE_SEARCH:
+               return (&_cal_ipc_record_search_plugin_cb);
+       case CAL_RECORD_TYPE_EXTENDED:
+               return (&_cal_ipc_record_extended_plugin_cb);
+       default:
+               return NULL;
+       }
+}
+
+static void __cal_ipc_unmarshal_composite_filter_free(cal_composite_filter_s* filter)
+{
+       if (filter->filters) {
+               GSList *cursor = NULL;
+               for(cursor=filter->filters;cursor;cursor=cursor->next) {
+                       cal_filter_s *src = (cal_filter_s*)cursor->data;
+                       if (src->filter_type == CAL_FILTER_COMPOSITE)
+                               __cal_ipc_unmarshal_composite_filter_free((cal_composite_filter_s *)src);
+                       else {
+                               cal_attribute_filter_s *attr = (cal_attribute_filter_s *)src;
+                               if (attr->filter_type == CAL_FILTER_STR)
+                                       free(attr->value.s);
+                       }
+                       free(src);
+               }
+               g_slist_free(filter->filters);
+       }
+
+       if (filter->filter_ops) {
+               g_slist_free(filter->filter_ops);
+       }
+
+       free(filter->view_uri);
+}
+
+static int __cal_ipc_unmarshal_composite_filter(const pims_ipc_data_h ipc_data, cal_composite_filter_s* filter)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       unsigned int size = 0;
+       char* str = NULL;
+       int count =0, i=0;
+       cal_filter_type_e filter_type = CAL_FILTER_COMPOSITE;
+       calendar_filter_operator_e op = CALENDAR_FILTER_OPERATOR_AND;
+
+       retvm_if(filter==NULL, CALENDAR_ERROR_INVALID_PARAMETER, "filter is NULL");
+
+       filter->filter_type = CAL_FILTER_COMPOSITE;
+
+       // view_uri
+       str = (char*)pims_ipc_data_get(ipc_data,&size);
+       CAL_FREE(filter->view_uri);
+       filter->view_uri = str ? strdup(str) : NULL;
+
+       // filters
+       if (_cal_ipc_unmarshal_int(ipc_data,&count) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       for(i=0;i<count;i++) {
+               if (_cal_ipc_unmarshal_int(ipc_data,(int*)&filter_type) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_unmarshal fail");
+                       ret = CALENDAR_ERROR_INVALID_PARAMETER;
+                       goto ERROR_RETURN;
+               }
+               if (filter_type == CAL_FILTER_COMPOSITE) {
+                       cal_composite_filter_s* com_filter = NULL;
+                       com_filter = (cal_composite_filter_s*)calloc(1,sizeof(cal_composite_filter_s));
+                       if (com_filter == NULL) {
+                               ERR("malloc fail");
+                               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                               goto ERROR_RETURN;
+                       }
+                       if (__cal_ipc_unmarshal_composite_filter(ipc_data, com_filter) != CALENDAR_ERROR_NONE) {
+                               ERR("_cal_ipc_unmarshal fail");
+                               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+                               CAL_FREE(com_filter);
+                               goto ERROR_RETURN;
+                       }
+                       filter->filters = g_slist_append(filter->filters,com_filter);
+               }
+               else {
+                       cal_attribute_filter_s* attr_filter = NULL;
+                       attr_filter = (cal_attribute_filter_s*)calloc(1,sizeof(cal_attribute_filter_s));
+                       if (attr_filter == NULL) {
+                               ERR("malloc fail");
+                               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                               goto ERROR_RETURN;
+                       }
+                       if (__cal_ipc_unmarshal_attribute_filter(ipc_data, filter_type, attr_filter) != CALENDAR_ERROR_NONE) {
+                               ERR("_cal_ipc_unmarshal fail");
+                               ret =  CALENDAR_ERROR_INVALID_PARAMETER;
+                               CAL_FREE(attr_filter);
+                               goto ERROR_RETURN;
+                       }
+                       filter->filters = g_slist_append(filter->filters,attr_filter);
+               }
+       }
+
+       // filters
+       if (_cal_ipc_unmarshal_int(ipc_data,&count) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               ret =  CALENDAR_ERROR_INVALID_PARAMETER;
+               goto ERROR_RETURN;
+       }
+
+       for(i=0;i<count;i++) {
+               if (_cal_ipc_unmarshal_int(ipc_data,(int*)&op) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_unmarshal fail");
+                       ret =  CALENDAR_ERROR_INVALID_PARAMETER;
+                       goto ERROR_RETURN;
+               }
+               filter->filter_ops = g_slist_append(filter->filter_ops, (void*)op);
+       }
+
+       // properties //property_count
+       filter->properties = (cal_property_info_s *)_cal_view_get_property_info(filter->view_uri, &filter->property_count);
+
+       return CALENDAR_ERROR_NONE;
+
+ERROR_RETURN:
+
+       __cal_ipc_unmarshal_composite_filter_free(filter);
+
+       return ret;
+}
+
+static int __cal_ipc_marshal_composite_filter(const cal_composite_filter_s* filter, pims_ipc_data_h ipc_data)
+{
+       if (_cal_ipc_marshal_int((filter->filter_type),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       // view_uri
+       int length = strlen(filter->view_uri);
+       if (pims_ipc_data_put(ipc_data,(void*)filter->view_uri,length+1) < 0) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       // filter->filters
+       if (filter->filters) {
+               int count = g_slist_length(filter->filters);
+               GSList *cursor = filter->filters;
+               cal_filter_s* child_filter;
+
+               if (_cal_ipc_marshal_int(count,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+
+               while (cursor) {
+                       child_filter = (cal_filter_s*)cursor->data;
+
+                       if (child_filter->filter_type == CAL_FILTER_COMPOSITE) {
+                               if (__cal_ipc_marshal_composite_filter((cal_composite_filter_s*)child_filter, ipc_data) != CALENDAR_ERROR_NONE) {
+                                       ERR("__cal_ipc_marshal_composite_filter fail");
+                                       return CALENDAR_ERROR_INVALID_PARAMETER;
+                               }
+                       }
+                       else {
+                               if (__cal_ipc_marshal_attribute_filter((cal_attribute_filter_s*)child_filter, ipc_data) != CALENDAR_ERROR_NONE) {
+                                       ERR("__cal_ipc_marshal_attribute_filter fail");
+                                       return CALENDAR_ERROR_INVALID_PARAMETER;
+                               }
+                       }
+                       cursor = g_slist_next(cursor);
+               }
+       }
+       else {
+               if (_cal_ipc_marshal_int(0,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       if (filter->filter_ops) {
+               int count = g_slist_length(filter->filter_ops);
+               GSList *cursor = filter->filter_ops;
+
+               if (_cal_ipc_marshal_int(count,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+
+               while (cursor) {
+                       calendar_filter_operator_e op = (calendar_filter_operator_e)cursor->data;
+
+                       if (_cal_ipc_marshal_int(op,ipc_data) != CALENDAR_ERROR_NONE) {
+                               ERR("_cal_ipc_marshal fail");
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+
+                       cursor = g_slist_next(cursor);
+               }
+       }
+       else {
+               if (_cal_ipc_marshal_int(0,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       // properties //property_count
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_unmarshal_attribute_filter(const pims_ipc_data_h ipc_data, const cal_filter_type_e filter_type, cal_attribute_filter_s* filter)
+{
+       filter->filter_type = filter_type;
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&filter->property_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&filter->match) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       switch(filter->filter_type) {
+       case CAL_FILTER_STR:
+               if (_cal_ipc_unmarshal_char(ipc_data,&filter->value.s) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_unmarshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_FILTER_INT:
+               if (_cal_ipc_unmarshal_int(ipc_data,&filter->value.i) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_unmarshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_FILTER_DOUBLE:
+               if (_cal_ipc_unmarshal_double(ipc_data,&filter->value.d) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_unmarshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_FILTER_LLI:
+               if (_cal_ipc_unmarshal_lli(ipc_data,&filter->value.lli) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_unmarshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_FILTER_CALTIME:
+               if (_cal_ipc_unmarshal_caltime(ipc_data,&filter->value.caltime) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_unmarshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       default:
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_attribute_filter(const cal_attribute_filter_s* filter, pims_ipc_data_h ipc_data)
+{
+       if (_cal_ipc_marshal_int((filter->filter_type),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_int((filter->property_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_int((filter->match),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       switch(filter->filter_type) {
+       case CAL_FILTER_STR:
+               if (_cal_ipc_marshal_char((filter->value.s),ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_FILTER_INT:
+               if (_cal_ipc_marshal_int((filter->value.i),ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_FILTER_DOUBLE:
+               if (_cal_ipc_marshal_double((filter->value.d),ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_FILTER_LLI:
+               if (_cal_ipc_marshal_lli((filter->value.lli),ipc_data) != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       case CAL_FILTER_CALTIME:
+               if (_cal_ipc_marshal_caltime((filter->value.caltime),ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       default:
+               break;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_unmarshal_record(const pims_ipc_data_h ipc_data, calendar_record_h* precord)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_record_s common = {0,};
+       cal_record_s *pcommon = NULL;
+
+       retv_if(NULL == ipc_data, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(NULL == precord, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (_cal_ipc_unmarshal_record_common(ipc_data,&common) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       cal_ipc_marshal_record_plugin_cb_s *plugin_cb = __cal_ipc_marshal_get_plugin_cb(common.type);
+
+       if (NULL == plugin_cb || NULL == plugin_cb->unmarshal_record) {
+               ERR("Invalid parameter");
+               free(common.properties_flags);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = calendar_record_create(common.view_uri, precord);
+       retvm_if(ret != CALENDAR_ERROR_NONE, ret, "record create fail");
+
+       pcommon = (cal_record_s*)(*precord);
+       pcommon->properties_max_count = common.properties_max_count;
+       pcommon->properties_flags = common.properties_flags;
+
+       ret = plugin_cb->unmarshal_record(ipc_data, *precord);
+
+       if (ret != CALENDAR_ERROR_NONE) {
+               calendar_record_destroy(*precord,true);
+               *precord = NULL;
+               ERR("_cal_ipc_unmarshal fail");
+       }
+
+       return ret;
+}
+
+int _cal_ipc_marshal_record(const calendar_record_h record, pims_ipc_data_h ipc_data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == ipc_data, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       if (_cal_ipc_marshal_record_common(temp,ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       cal_ipc_marshal_record_plugin_cb_s *plugin_cb = __cal_ipc_marshal_get_plugin_cb(temp->type);
+
+       retvm_if(NULL == plugin_cb || NULL == plugin_cb->marshal_record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = plugin_cb->marshal_record(record, ipc_data);
+
+       return ret;
+}
+
+int _cal_ipc_marshal_record_get_primary_id(const calendar_record_h record,
+               unsigned int *property_id, int *id)
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       cal_record_s *temp = (cal_record_s*)(record);
+
+       retvm_if(NULL == record || NULL == property_id ||
+                       NULL == id, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       cal_ipc_marshal_record_plugin_cb_s *plugin_cb = __cal_ipc_marshal_get_plugin_cb(temp->type);
+
+       retvm_if(NULL == plugin_cb || NULL == plugin_cb->get_primary_id, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = plugin_cb->get_primary_id(record, property_id,id);
+
+       return ret;
+}
+
+int _cal_ipc_unmarshal_char(const pims_ipc_data_h ipc_data, char** ppbufchar)
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       void *tmp = NULL;
+       unsigned int size = 0;
+       char *str = NULL;
+
+       int length = 0;
+
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(ppbufchar==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       tmp = pims_ipc_data_get(ipc_data,&size);
+       if ( tmp == NULL) {
+               ERR("pims_ipc_data_get fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       length = *(int*)tmp;
+
+       if(length == -1) {
+               ret = CALENDAR_ERROR_NONE;
+               //CAL_DBG("string is null");
+               *ppbufchar = NULL;
+               return ret;
+       }
+
+       str = (char*)pims_ipc_data_get(ipc_data,&size);
+       if (str) {
+               *ppbufchar = SAFE_STRDUP(str);
+       }
+
+       return ret;
+}
+
+int _cal_ipc_unmarshal_int(const pims_ipc_data_h data, int *pout)
+{
+       void *tmp = NULL;
+       unsigned int size = 0;
+
+       retv_if(data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(pout==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       tmp = pims_ipc_data_get(data,&size);
+       if ( tmp == NULL) {
+               ERR("pims_ipc_data_get fail");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+       else {
+               *pout = *(int*)tmp;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_unmarshal_uint(const pims_ipc_data_h data, unsigned int *pout)
+{
+       void *tmp = NULL;
+       unsigned int size = 0;
+
+       retv_if(data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(pout==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       tmp = pims_ipc_data_get(data,&size);
+       if ( tmp == NULL) {
+               ERR("pims_ipc_data_get fail");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+       else {
+               *pout = *(unsigned int*)tmp;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_unmarshal_lli(const pims_ipc_data_h data, long long int *pout)
+{
+       void *tmp = NULL;
+       unsigned int size = 0;
+
+       retv_if(data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(pout==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       tmp = pims_ipc_data_get(data,&size);
+       if ( tmp == NULL) {
+               ERR("pims_ipc_data_get fail");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+       else {
+               *pout = *(long long int*)tmp;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_unmarshal_long(const pims_ipc_data_h data, long *pout)
+{
+       void *tmp = NULL;
+       unsigned int size = 0;
+
+       retv_if(data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(pout==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       tmp = pims_ipc_data_get(data,&size);
+       if ( tmp == NULL) {
+               ERR("pims_ipc_data_get fail");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+       else {
+               *pout = *(long*)tmp;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_unmarshal_double(const pims_ipc_data_h data, double *pout)
+{
+       void *tmp = NULL;
+       unsigned int size = 0;
+
+       retv_if(data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(pout==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       tmp = pims_ipc_data_get(data,&size);
+       if ( tmp == NULL) {
+               ERR("pims_ipc_data_get fail");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+       else {
+               *pout = *(double*)tmp;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_unmarshal_caltime(const pims_ipc_data_h data, calendar_time_s *pout)
+{
+       void *tmp = NULL;
+       unsigned int size = 0;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retv_if(data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(pout==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       tmp = pims_ipc_data_get(data,&size);
+       if ( tmp == NULL) {
+               ERR("pims_ipc_data_get fail");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+       else {
+               pout->type = *(int*)tmp;
+       }
+
+       if (pout->type == CALENDAR_TIME_UTIME) {
+               return _cal_ipc_unmarshal_lli(data, &(pout->time.utime));
+       }
+       else {
+               ret = _cal_ipc_unmarshal_int(data, &(pout->time.date.year));
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+               ret = _cal_ipc_unmarshal_int(data, &(pout->time.date.month));
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+               ret = _cal_ipc_unmarshal_int(data, &(pout->time.date.mday));
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+               ret = _cal_ipc_unmarshal_int(data, &(pout->time.date.hour));
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+               ret = _cal_ipc_unmarshal_int(data, &(pout->time.date.minute));
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+               ret = _cal_ipc_unmarshal_int(data, &(pout->time.date.second));
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_unmarshal_record_common(const pims_ipc_data_h ipc_data, cal_record_s* common)
+{
+       unsigned int size = 0;
+       const char* str = NULL;
+       void *ret_pims = NULL;
+
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       ret_pims = pims_ipc_data_get(ipc_data,&size);
+       if (NULL == ret_pims) {
+               ERR("pims_ipc_data_get() Fail");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+       common->type = *(cal_record_type_e*)ret_pims;
+       common->plugin_cb = _cal_record_get_plugin_cb(common->type);
+
+       str = (char*)pims_ipc_data_get(ipc_data,&size);
+       common->view_uri = _cal_view_get_uri(str);
+
+       ret_pims = pims_ipc_data_get(ipc_data,&size);
+       if (NULL == ret_pims) {
+               ERR("pims_ipc_data_get() Fail");
+               return CALENDAR_ERROR_IPC;
+       }
+       common->properties_max_count = *(unsigned int*)ret_pims;
+       if (common->properties_max_count > 0)
+       {
+               unsigned char *tmp_properties_flags;
+               ret_pims = pims_ipc_data_get(ipc_data,&size);
+               if (NULL == ret_pims) {
+                       ERR("pims_ipc_data_get() Fail");
+                       return CALENDAR_ERROR_IPC;
+               }
+               tmp_properties_flags = (unsigned char*)ret_pims;
+               common->properties_flags  = calloc(common->properties_max_count, sizeof(char));
+               if (common->properties_flags == NULL) {
+                       ERR("calloc fail");
+                       return CALENDAR_ERROR_OUT_OF_MEMORY;
+               }
+               memcpy(common->properties_flags,tmp_properties_flags,sizeof(char)*common->properties_max_count);
+       }
+
+       ret_pims = pims_ipc_data_get(ipc_data,&size);
+       if (NULL == ret_pims) {
+               ERR("pims_ipc_data_get() Fail");
+               free(common->properties_flags);
+               return CALENDAR_ERROR_IPC;
+       }
+       common->property_flag = *(unsigned char*)ret_pims;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_marshal_char(const char* bufchar, pims_ipc_data_h ipc_data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if( bufchar != NULL) {
+               int length = strlen(bufchar);
+               if (pims_ipc_data_put(ipc_data,(void*)&length,sizeof(int)) != 0) {
+                       ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               }
+
+               if ( pims_ipc_data_put(ipc_data,(void*)bufchar,length+1) != 0) {
+                       ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                       return ret;
+               }
+       }
+       else {
+               int length = -1;
+
+               if (pims_ipc_data_put(ipc_data,(void*)&length,sizeof(int)) != 0) {
+                       ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+               }
+       }
+       return ret;
+}
+
+int _cal_ipc_marshal_int(const int in, pims_ipc_data_h ipc_data)
+{
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (pims_ipc_data_put(ipc_data,(void*)&in,sizeof(int)) != 0) {
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_marshal_uint(const unsigned int in, pims_ipc_data_h ipc_data)
+{
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (pims_ipc_data_put(ipc_data,(void*)&in,sizeof(unsigned int)) != 0) {
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_marshal_lli(const long long int in, pims_ipc_data_h ipc_data)
+{
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (pims_ipc_data_put(ipc_data,(void*)&in,sizeof(long long int)) != 0) {
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_marshal_long(const long in, pims_ipc_data_h ipc_data)
+{
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (pims_ipc_data_put(ipc_data,(void*)&in,sizeof(long)) != 0) {
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_marshal_double(const double in, pims_ipc_data_h ipc_data)
+{
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (pims_ipc_data_put(ipc_data,(void*)&in,sizeof(double)) != 0) {
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_marshal_caltime(const calendar_time_s in, pims_ipc_data_h ipc_data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (pims_ipc_data_put(ipc_data,(void*)&(in.type),sizeof(int)) != 0) {
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       if ( in.type == CALENDAR_TIME_UTIME) {
+               return _cal_ipc_marshal_lli(in.time.utime,ipc_data);
+       }
+       else {
+               ret = _cal_ipc_marshal_int(in.time.date.year,ipc_data);
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+               ret = _cal_ipc_marshal_int(in.time.date.month,ipc_data);
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+               ret = _cal_ipc_marshal_int(in.time.date.mday,ipc_data);
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+               ret = _cal_ipc_marshal_int(in.time.date.hour,ipc_data);
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+               ret = _cal_ipc_marshal_int(in.time.date.minute,ipc_data);
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+               ret = _cal_ipc_marshal_int(in.time.date.second,ipc_data);
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_marshal_record_common(const cal_record_s* common, pims_ipc_data_h ipc_data)
+{
+
+       retv_if(NULL == common, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(NULL == ipc_data, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (pims_ipc_data_put(ipc_data,(void*)&common->type,sizeof(int)) < 0)
+               return CALENDAR_ERROR_NO_DATA;
+
+       int length = strlen(common->view_uri);
+
+       if (pims_ipc_data_put(ipc_data,(void*)common->view_uri,length+1) < 0) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (pims_ipc_data_put(ipc_data,(void*)&common->properties_max_count,sizeof(int)) < 0) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+
+       if (common->properties_max_count > 0) {
+               if(pims_ipc_data_put(ipc_data,(void*)common->properties_flags,sizeof(char)*common->properties_max_count) < 0) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_NO_DATA;
+               }
+       }
+
+       if (pims_ipc_data_put(ipc_data,(void*)&common->property_flag,sizeof(char)) < 0) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_NO_DATA;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_unmarshal_query(const pims_ipc_data_h ipc_data, calendar_query_h *query)
+{
+       cal_query_s *que = NULL;
+       unsigned int size = 0;
+       char* str = NULL;
+       int count = 0, i = 0;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retv_if(NULL == query, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(NULL == ipc_data, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       // view_uri
+       str = (char*)pims_ipc_data_get(ipc_data,&size);
+
+       ret = calendar_query_create(str, query);
+       if (ret != CALENDAR_ERROR_NONE) {
+               ERR("calendar_query_create fail");
+               return ret;
+       }
+
+       que = (cal_query_s *) *query;
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&count) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               goto ERROR_RETURN;
+       }
+
+       if (count == 0) {
+               que->filter = NULL;
+       }
+       else {
+               calendar_filter_h filter = (calendar_filter_h)que->filter;
+               if (calendar_filter_create(que->view_uri,&filter) != CALENDAR_ERROR_NONE) {
+                       ERR("calendar_filter_create fail");
+                       ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                       goto ERROR_RETURN;
+               }
+               que->filter = (cal_composite_filter_s*)filter;
+
+               // for filter_type
+               if (_cal_ipc_unmarshal_int(ipc_data,&count) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_unmarshal fail");
+                       ret = CALENDAR_ERROR_INVALID_PARAMETER;
+                       goto ERROR_RETURN;
+               }
+
+               if (__cal_ipc_unmarshal_composite_filter(ipc_data,que->filter) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_unmarshal fail");
+                       ret = CALENDAR_ERROR_INVALID_PARAMETER;
+                       goto ERROR_RETURN;
+               }
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&(que->projection_count)) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               goto ERROR_RETURN;
+       }
+
+       if (que->projection_count > 0) {
+               que->projection = (unsigned int*)malloc(sizeof(int)*que->projection_count);
+               if (que->projection == NULL) {
+                       ERR("malloc fail");
+                       ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                       goto ERROR_RETURN;
+               }
+
+               for(i=0;i<que->projection_count;i++) {
+                       if (_cal_ipc_unmarshal_uint(ipc_data,&(que->projection[i])) != CALENDAR_ERROR_NONE) {
+                               ERR("_cal_ipc_unmarshal fail");
+                               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+                               goto ERROR_RETURN;
+                       }
+               }
+       }
+       else {
+               que->projection = NULL;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&(que->sort_property_id)) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               goto ERROR_RETURN;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,(int*)&(que->asc)) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               goto ERROR_RETURN;
+       }
+
+       que->properties = (cal_property_info_s *)_cal_view_get_property_info(que->view_uri, &que->property_count);
+
+       if (_cal_ipc_unmarshal_int(ipc_data,(int*)&(que->distinct)) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               goto ERROR_RETURN;
+       }
+
+       return CALENDAR_ERROR_NONE;
+
+ERROR_RETURN:
+
+       calendar_query_destroy(*query);
+       *query = NULL;
+
+       return ret;
+}
+
+int _cal_ipc_marshal_query(const calendar_query_h query, pims_ipc_data_h ipc_data)
+{
+       cal_query_s *que = NULL;
+       int i = 0;
+       int length = 0;
+
+       retv_if(NULL == query, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(NULL == ipc_data, CALENDAR_ERROR_INVALID_PARAMETER);
+       que = (cal_query_s *)query;
+
+       //view_uri
+       length = strlen(que->view_uri);
+       if (pims_ipc_data_put(ipc_data,(void*)que->view_uri,length+1) < 0) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (que->filter) {
+               if (_cal_ipc_marshal_int(1,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               if (__cal_ipc_marshal_composite_filter(que->filter,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+       else
+       {
+               if (_cal_ipc_marshal_int(0,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       if (_cal_ipc_marshal_int((que->projection_count),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       for(i=0;i<que->projection_count;i++) {
+               if (_cal_ipc_marshal_uint((que->projection[i]),ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       if (_cal_ipc_marshal_int((que->sort_property_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_int((int)(que->asc),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_int((int)(que->distinct),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       //properties // property_count
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_unmarshal_list(const pims_ipc_data_h ipc_data, calendar_list_h* list)
+{
+       int count = 0, i = 0;
+       calendar_record_h record;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retvm_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER, "list is NULL");
+       retvm_if(NULL == ipc_data, CALENDAR_ERROR_INVALID_PARAMETER, "ipc_data is NULL");
+
+       if (calendar_list_create(list) != CALENDAR_ERROR_NONE) {
+               ERR("calendar_list_create fail");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&(count)) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               goto ERROR_RETURN;
+       }
+
+       for(i=0;i<count;i++) {
+               if (_cal_ipc_unmarshal_record(ipc_data,&record) != CALENDAR_ERROR_NONE ) {
+                       ERR("_cal_ipc_unmarshal fail");
+                       ret = CALENDAR_ERROR_INVALID_PARAMETER;
+                       goto ERROR_RETURN;
+               }
+
+               if (calendar_list_add(*list,record) != CALENDAR_ERROR_NONE) {
+                       ERR("calendar_list_add fail");
+                       ret = CALENDAR_ERROR_INVALID_PARAMETER;
+                       goto ERROR_RETURN;
+               }
+       }
+       calendar_list_first(*list);
+
+       return CALENDAR_ERROR_NONE;
+
+ERROR_RETURN:
+       if (*list) {
+               calendar_list_destroy(*list, true);
+               *list = NULL;
+       }
+
+       return ret;
+}
+
+int _cal_ipc_marshal_list(const calendar_list_h list, pims_ipc_data_h ipc_data)
+{
+       int count = 0, i = 0;
+       calendar_record_h record;
+       retv_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(NULL == ipc_data, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       // count
+       if (calendar_list_get_count(list, &count) != CALENDAR_ERROR_NONE) {
+               ERR("calendar_list_get_count fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_int(count,ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       calendar_list_first(list);
+
+       for(i=0;i<count;i++) {
+               if (calendar_list_get_current_record_p(list,&record) != CALENDAR_ERROR_NONE) {
+                       ERR("calendar_list_get_count fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+
+               if (_cal_ipc_marshal_record(record,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               calendar_list_next(list);
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_ipc_unmarshal_child_list(const pims_ipc_data_h ipc_data, calendar_list_h* list)
+{
+       unsigned int i = 0;
+       int count = 0;
+       calendar_record_h record;
+
+       retv_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(NULL == ipc_data, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&(count)) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal_int fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       for(i=0;i<count;i++) {
+               if (_cal_ipc_unmarshal_record(ipc_data,&record) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_unmarshal_record fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+
+               if (calendar_list_add(*list,record) != CALENDAR_ERROR_NONE) {
+                       ERR("calendar_list_add fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
diff --git a/common/ipc/cal_ipc_marshal.h b/common/ipc/cal_ipc_marshal.h
new file mode 100644 (file)
index 0000000..3eb8d50
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __CAL_IPC_MARSHAL__
+#define __CAL_IPC_MARSHAL__
+
+#include <pims-ipc-data.h>
+#include "cal_typedef.h"
+#include "cal_record.h"
+
+typedef int (*cal_ipc_unmarshal_record_cb)(const pims_ipc_data_h ipc_data, calendar_record_h record);
+typedef int (*cal_ipc_marshal_record_cb)(const calendar_record_h record, pims_ipc_data_h ipc_data);
+typedef int (*cal_ipc_marshal_record_get_primary_id_cb)(const calendar_record_h record, unsigned int *property_id, int *id);
+
+typedef struct {
+       cal_ipc_unmarshal_record_cb unmarshal_record;
+       cal_ipc_marshal_record_cb marshal_record;
+       cal_ipc_marshal_record_get_primary_id_cb get_primary_id;
+} cal_ipc_marshal_record_plugin_cb_s;
+
+int _cal_ipc_unmarshal_record(const pims_ipc_data_h ipc_data, calendar_record_h* precord);
+int _cal_ipc_marshal_record(const calendar_record_h record, pims_ipc_data_h ipc_data);
+int _cal_ipc_marshal_record_get_primary_id(const calendar_record_h record, unsigned int *property_id, int *id);
+
+int _cal_ipc_unmarshal_char(const pims_ipc_data_h ipc_data, char** ppbufchar);
+int _cal_ipc_unmarshal_int(const pims_ipc_data_h data, int *pout);
+int _cal_ipc_unmarshal_uint(const pims_ipc_data_h data, unsigned int *pout);
+int _cal_ipc_unmarshal_lli(const pims_ipc_data_h data, long long int *pout);
+int _cal_ipc_unmarshal_long(const pims_ipc_data_h data, long *pout);
+int _cal_ipc_unmarshal_double(const pims_ipc_data_h data, double *pout);
+int _cal_ipc_unmarshal_caltime(const pims_ipc_data_h data, calendar_time_s *pout);
+int _cal_ipc_unmarshal_record_common(const pims_ipc_data_h ipc_data, cal_record_s* common);
+
+int _cal_ipc_marshal_char(const char* bufchar, pims_ipc_data_h ipc_data);
+int _cal_ipc_marshal_int(const int in, pims_ipc_data_h ipc_data);
+int _cal_ipc_marshal_uint(const unsigned int in, pims_ipc_data_h ipc_data);
+int _cal_ipc_marshal_lli(const long long int in, pims_ipc_data_h ipc_data);
+int _cal_ipc_marshal_long(const long in, pims_ipc_data_h ipc_data);
+int _cal_ipc_marshal_double(const double in, pims_ipc_data_h ipc_data);
+int _cal_ipc_marshal_caltime(const calendar_time_s in, pims_ipc_data_h ipc_data);
+int _cal_ipc_marshal_record_common(const cal_record_s* common, pims_ipc_data_h ipc_data);
+
+int _cal_ipc_unmarshal_query(const pims_ipc_data_h ipc_data, calendar_query_h *query);
+int _cal_ipc_marshal_query(const calendar_query_h query, pims_ipc_data_h ipc_data);
+int _cal_ipc_unmarshal_list(const pims_ipc_data_h ipc_data, calendar_list_h *list);
+int _cal_ipc_marshal_list(const calendar_list_h list, pims_ipc_data_h ipc_data);
+
+int _cal_ipc_unmarshal_child_list(const pims_ipc_data_h ipc_data, calendar_list_h* list);
+
+/*
+ * for property_id
+ */
+#define CAL_IPC_CHECK_PROPERTIES_FLAG(src) (CAL_IPC_CHECK_PROJECTION(src) || CAL_IPC_CHECK_DIRTY(src))
+#define CAL_IPC_CHECK_PROJECTION(src) ((src) & (unsigned char)CAL_PROPERTY_FLAG_PROJECTION)
+#define CAL_IPC_CHECK_DIRTY(src) ((src) & (unsigned char)CAL_PROPERTY_FLAG_DIRTY)
+
+#endif /* __CAL_IPC_MARSHAL__ */
diff --git a/common/ipc/cal_ipc_marshal_alarm.c b/common/ipc/cal_ipc_marshal_alarm.c
new file mode 100644 (file)
index 0000000..3352f15
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "cal_internal.h"
+#include "cal_ipc_marshal.h"
+
+static int __cal_ipc_unmarshal_alarm(const pims_ipc_data_h ipc_data, calendar_record_h record);
+static int __cal_ipc_marshal_alarm(const calendar_record_h record, pims_ipc_data_h ipc_data);
+
+cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_alarm_plugin_cb = {
+       .unmarshal_record = __cal_ipc_unmarshal_alarm,
+       .marshal_record = __cal_ipc_marshal_alarm,
+       .get_primary_id = NULL
+};
+
+static int __cal_ipc_unmarshal_alarm(pims_ipc_data_h ipc_data, calendar_record_h record)
+{
+       cal_alarm_s* palarm = NULL;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(record==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       palarm = (cal_alarm_s*) record;
+
+       // read only or primary/secondary key
+       if (_cal_ipc_unmarshal_int(ipc_data,&palarm->id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&palarm->parent_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&palarm->is_deleted) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&palarm->remind_tick) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,(int*)&palarm->remind_tick_unit) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_char(ipc_data,&palarm->alarm_description) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_char(ipc_data,&palarm->alarm_summary) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&palarm->alarm_action) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_char(ipc_data,&palarm->alarm_attach) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&palarm->alarm) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_alarm(const calendar_record_h record, pims_ipc_data_h ipc_data)
+{
+       cal_alarm_s* palarm = (cal_alarm_s*) record;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(palarm==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       // read only or primary/secondary key
+       if (_cal_ipc_marshal_int((palarm->id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((palarm->parent_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_int((palarm->is_deleted),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_int((palarm->remind_tick),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((palarm->remind_tick_unit),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((palarm->alarm_description),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((palarm->alarm_summary),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((palarm->alarm_action),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((palarm->alarm_attach),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((palarm->alarm),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/ipc/cal_ipc_marshal_attendee.c b/common/ipc/cal_ipc_marshal_attendee.c
new file mode 100644 (file)
index 0000000..c4d4191
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "cal_internal.h"
+#include "cal_ipc_marshal.h"
+
+static int __cal_ipc_unmarshal_attendee(const pims_ipc_data_h ipc_data, calendar_record_h record);
+static int __cal_ipc_marshal_attendee(const calendar_record_h record, pims_ipc_data_h ipc_data);
+
+cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_attendee_plugin_cb = {
+       .unmarshal_record = __cal_ipc_unmarshal_attendee,
+       .marshal_record = __cal_ipc_marshal_attendee,
+       .get_primary_id = NULL
+};
+
+static int __cal_ipc_unmarshal_attendee(const pims_ipc_data_h ipc_data, calendar_record_h record)
+{
+       cal_attendee_s* pattendee = NULL;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(record==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       pattendee = (cal_attendee_s*) record;
+
+       // read only or primary/secondary key
+       if (_cal_ipc_unmarshal_int(ipc_data,&pattendee->id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&pattendee->parent_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_char(ipc_data,&pattendee->attendee_number) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&pattendee->attendee_cutype) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&pattendee->attendee_ct_index) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_char(ipc_data,&pattendee->attendee_uid) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_char(ipc_data,&pattendee->attendee_group) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_char(ipc_data,&pattendee->attendee_email) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&pattendee->attendee_role) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&pattendee->attendee_status) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&pattendee->attendee_rsvp) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_char(ipc_data,&pattendee->attendee_delegatee_uri) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_char(ipc_data,&pattendee->attendee_delegator_uri) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_char(ipc_data,&pattendee->attendee_name) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_unmarshal_char(ipc_data,&pattendee->attendee_member) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_attendee(const calendar_record_h record, pims_ipc_data_h ipc_data )
+{
+       cal_attendee_s* pattendee = (cal_attendee_s*) record;
+
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(pattendee==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       // read only or primary/secondary key
+       if (_cal_ipc_marshal_int((pattendee->id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_int((pattendee->parent_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_char((pattendee->attendee_number),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_int((pattendee->attendee_cutype),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_int((pattendee->attendee_ct_index),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_char((pattendee->attendee_uid),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_char((pattendee->attendee_group),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_char((pattendee->attendee_email),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_int((pattendee->attendee_role),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_int((pattendee->attendee_status),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_int((pattendee->attendee_rsvp),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_char((pattendee->attendee_delegatee_uri),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_char((pattendee->attendee_delegator_uri),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_char((pattendee->attendee_name),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (_cal_ipc_marshal_char((pattendee->attendee_member),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/ipc/cal_ipc_marshal_calendar.c b/common/ipc/cal_ipc_marshal_calendar.c
new file mode 100644 (file)
index 0000000..f601693
--- /dev/null
@@ -0,0 +1,188 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "cal_internal.h"
+#include "cal_ipc_marshal.h"
+#include "cal_view.h"
+
+static int __cal_ipc_unmarshal_calendar(pims_ipc_data_h ipc_data, calendar_record_h record);
+static int __cal_ipc_marshal_calendar(const calendar_record_h record, pims_ipc_data_h ipc_data);
+static int __cal_ipc_marshal_calendar_get_primary_id(const calendar_record_h record, unsigned int *property_id, int *id);
+
+cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_calendar_plugin_cb = {
+       .unmarshal_record = __cal_ipc_unmarshal_calendar,
+       .marshal_record = __cal_ipc_marshal_calendar,
+       .get_primary_id = __cal_ipc_marshal_calendar_get_primary_id
+};
+
+static int __cal_ipc_unmarshal_calendar(pims_ipc_data_h ipc_data, calendar_record_h record)
+{
+       cal_calendar_s* pcalendar = NULL;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(record==NULL,CALENDAR_ERROR_NO_DATA);
+
+       pcalendar = (cal_calendar_s*) record;
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&pcalendar->index) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pcalendar->store_type) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->uid) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_long(ipc_data,&pcalendar->updated) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->name) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->description) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->color) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->location) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pcalendar->visibility) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pcalendar->sync_event) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pcalendar->account_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->sync_data1) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->sync_data2) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->sync_data3) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->sync_data4) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pcalendar->mode) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_calendar(const calendar_record_h record, pims_ipc_data_h ipc_data)
+{
+       cal_calendar_s* pcalendar = (cal_calendar_s*)record;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(pcalendar==NULL,CALENDAR_ERROR_NO_DATA);
+
+       if (_cal_ipc_marshal_int((pcalendar->index),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pcalendar->store_type),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pcalendar->uid),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_long((pcalendar->updated),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pcalendar->name),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pcalendar->description),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pcalendar->color),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pcalendar->location),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pcalendar->visibility),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pcalendar->sync_event),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pcalendar->account_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pcalendar->sync_data1),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pcalendar->sync_data2),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pcalendar->sync_data3),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pcalendar->sync_data4),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pcalendar->mode),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_calendar_get_primary_id(const calendar_record_h record, unsigned int *property_id, int *id)
+{
+       *property_id = CAL_PROPERTY_CALENDAR_ID;
+       return calendar_record_get_int(record, *property_id, id );
+}
diff --git a/common/ipc/cal_ipc_marshal_event.c b/common/ipc/cal_ipc_marshal_event.c
new file mode 100644 (file)
index 0000000..5fc926c
--- /dev/null
@@ -0,0 +1,526 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "cal_internal.h"
+#include "cal_ipc_marshal.h"
+#include "cal_view.h"
+
+static int __cal_ipc_unmarshal_event(pims_ipc_data_h ipc_data, calendar_record_h record);
+static int __cal_ipc_marshal_event(const calendar_record_h record, pims_ipc_data_h ipc_data);
+static int __cal_ipc_marshal_event_get_primary_id(const calendar_record_h record, unsigned int *property_id, int *id);
+
+cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_event_plugin_cb = {
+       .unmarshal_record = __cal_ipc_unmarshal_event,
+       .marshal_record = __cal_ipc_marshal_event,
+       .get_primary_id = __cal_ipc_marshal_event_get_primary_id
+};
+
+static int __cal_ipc_unmarshal_event(pims_ipc_data_h ipc_data, calendar_record_h record)
+{
+       cal_event_s *pevent = NULL;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(record==NULL,CALENDAR_ERROR_NO_DATA);
+
+       pevent = (cal_event_s*) record;
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->index) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->calendar_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->summary) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->description) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->location) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->categories) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->exdate) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,(int*)&pevent->event_status) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,(int*)&pevent->priority) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->timezone) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->contact_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->busy_status) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->sensitivity) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->meeting_status) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->uid) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->organizer_name) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->organizer_email) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->original_event_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_double(ipc_data,&pevent->latitude) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_double(ipc_data,&pevent->longitude) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->email_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_lli(ipc_data,&pevent->created_time) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->is_deleted) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_lli(ipc_data,&pevent->last_mod) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->freq) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->range_type) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&pevent->until) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->count) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->interval) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->bysecond) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->byminute) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->byhour) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->byday) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->bymonthday) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->byyearday) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->byweekno) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->bymonth) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->bysetpos) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->wkst) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->recurrence_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->rdate) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->has_attendee) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->has_alarm) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->system_type) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_long(ipc_data,&pevent->updated) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->sync_data1) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->sync_data2) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->sync_data3) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->sync_data4) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&pevent->start) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->start_tzid) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&pevent->end) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pevent->end_tzid) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pevent->is_allday) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (CALENDAR_ERROR_NONE != _cal_ipc_unmarshal_child_list(ipc_data, (calendar_list_h *)&pevent->alarm_list)) {
+               ERR("_cal_ipc_unmarshal_list fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (CALENDAR_ERROR_NONE != _cal_ipc_unmarshal_child_list(ipc_data, (calendar_list_h *)&pevent->attendee_list)) {
+               ERR("_cal_ipc_unmarshal_list fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (CALENDAR_ERROR_NONE != _cal_ipc_unmarshal_child_list(ipc_data, (calendar_list_h *)&pevent->exception_list)) {
+               ERR("_cal_ipc_unmarshal_list fail: exception");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (CALENDAR_ERROR_NONE != _cal_ipc_unmarshal_child_list(ipc_data, (calendar_list_h *)&pevent->extended_list)) {
+               ERR("_cal_ipc_unmarshal_list fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_event(const calendar_record_h record, pims_ipc_data_h ipc_data)
+{
+       cal_event_s* pevent = (cal_event_s*) record;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(pevent==NULL,CALENDAR_ERROR_NO_DATA);
+
+       if (_cal_ipc_marshal_int((pevent->index),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->calendar_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->summary),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->description),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->location),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->categories),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->exdate),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->event_status),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->priority),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->timezone),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->contact_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->busy_status),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->sensitivity),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->meeting_status),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->uid),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->organizer_name),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->organizer_email),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->original_event_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_double((pevent->latitude),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_double((pevent->longitude),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->email_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_lli((pevent->created_time),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->is_deleted),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_lli((pevent->last_mod),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->freq),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->range_type),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((pevent->until),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->count),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->interval),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->bysecond),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->byminute),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->byhour),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->byday),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->bymonthday),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->byyearday),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->byweekno),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->bymonth),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->bysetpos),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->wkst),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->recurrence_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->rdate),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->has_attendee),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->has_alarm),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->system_type),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_long((pevent->updated),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->sync_data1),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->sync_data2),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->sync_data3),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->sync_data4),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((pevent->start),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->start_tzid),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((pevent->end),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pevent->end_tzid),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pevent->is_allday),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (CALENDAR_ERROR_NONE != _cal_ipc_marshal_list((calendar_list_h)pevent->alarm_list, ipc_data)) {
+               ERR("_cal_ipc_marshal_list fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (CALENDAR_ERROR_NONE != _cal_ipc_marshal_list((calendar_list_h)pevent->attendee_list, ipc_data)) {
+               ERR("_cal_ipc_marshal_list fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (CALENDAR_ERROR_NONE != _cal_ipc_marshal_list((calendar_list_h)pevent->exception_list, ipc_data)) {
+               ERR("_cal_ipc_marshal_list fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (CALENDAR_ERROR_NONE != _cal_ipc_marshal_list((calendar_list_h)pevent->extended_list, ipc_data)) {
+               ERR("_cal_ipc_marshal_list fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_event_get_primary_id(const calendar_record_h record, unsigned int *property_id, int *id)
+{
+       *property_id = CAL_PROPERTY_EVENT_ID;
+       return calendar_record_get_int(record, *property_id, id );
+}
diff --git a/common/ipc/cal_ipc_marshal_extended.c b/common/ipc/cal_ipc_marshal_extended.c
new file mode 100644 (file)
index 0000000..387e317
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "cal_internal.h"
+#include "cal_ipc_marshal.h"
+#include "cal_view.h"
+
+static int __cal_ipc_unmarshal_extended(pims_ipc_data_h ipc_data, calendar_record_h record);
+static int __cal_ipc_marshal_extended(const calendar_record_h record, pims_ipc_data_h ipc_data);
+static int __cal_ipc_marshal_extended_get_primary_id(const calendar_record_h record, unsigned int *property_id, int *id);
+
+cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_extended_plugin_cb = {
+       .unmarshal_record = __cal_ipc_unmarshal_extended,
+       .marshal_record = __cal_ipc_marshal_extended,
+       .get_primary_id = __cal_ipc_marshal_extended_get_primary_id
+};
+
+static int __cal_ipc_unmarshal_extended(pims_ipc_data_h ipc_data, calendar_record_h record)
+{
+       cal_extended_s* pextended = NULL;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(record==NULL,CALENDAR_ERROR_NO_DATA);
+
+       pextended = (cal_extended_s*) record;
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&pextended->id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pextended->record_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pextended->record_type) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pextended->key) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pextended->value) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_extended(const calendar_record_h record, pims_ipc_data_h ipc_data)
+{
+       cal_extended_s* pextended = (cal_extended_s*) record;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(pextended==NULL,CALENDAR_ERROR_NO_DATA);
+
+       if (_cal_ipc_marshal_int((pextended->id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pextended->record_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pextended->record_type),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pextended->key),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pextended->value),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_extended_get_primary_id(const calendar_record_h record, unsigned int *property_id, int *id)
+{
+       *property_id = CAL_PROPERTY_EXTENDED_ID;
+       return calendar_record_get_int(record, *property_id, id );
+}
diff --git a/common/ipc/cal_ipc_marshal_instance_allday.c b/common/ipc/cal_ipc_marshal_instance_allday.c
new file mode 100644 (file)
index 0000000..05dac85
--- /dev/null
@@ -0,0 +1,204 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "cal_internal.h"
+#include "cal_ipc_marshal.h"
+#include "cal_view.h"
+
+static int __cal_ipc_unmarshal_instance_allday(pims_ipc_data_h ipc_data, calendar_record_h record);
+static int __cal_ipc_marshal_instance_allday(const calendar_record_h record, pims_ipc_data_h ipc_data);
+
+cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_instance_allday_plugin_cb = {
+       .unmarshal_record = __cal_ipc_unmarshal_instance_allday,
+       .marshal_record = __cal_ipc_marshal_instance_allday,
+       .get_primary_id = NULL
+};
+
+static int __cal_ipc_unmarshal_instance_allday(pims_ipc_data_h ipc_data, calendar_record_h record)
+{
+       cal_instance_allday_s* pinstanceallday = NULL;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(record==NULL,CALENDAR_ERROR_NO_DATA);
+
+       pinstanceallday = (cal_instance_allday_s*) record;
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->event_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->calendar_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&pinstanceallday->start) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&pinstanceallday->end) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstanceallday->summary) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstanceallday->description) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstanceallday->location) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->busy_status) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->event_status) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->priority) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->sensitivity) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->has_rrule) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_double(ipc_data,&pinstanceallday->latitude) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_double(ipc_data,&pinstanceallday->longitude) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->has_alarm) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->original_event_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_lli(ipc_data,&pinstanceallday->last_mod) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstanceallday->sync_data1) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->is_allday) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_instance_allday(const calendar_record_h record, pims_ipc_data_h ipc_data)
+{
+       cal_instance_allday_s* pinstanceallday = (cal_instance_allday_s*) record;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(pinstanceallday==NULL,CALENDAR_ERROR_NO_DATA);
+
+       if (_cal_ipc_marshal_int((pinstanceallday->event_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->calendar_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((pinstanceallday->start),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((pinstanceallday->end),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstanceallday->summary),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstanceallday->description),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstanceallday->location),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->busy_status),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->event_status),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->priority),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->sensitivity),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->has_rrule),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_double((pinstanceallday->latitude),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_double((pinstanceallday->longitude),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->has_alarm),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->original_event_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_lli((pinstanceallday->last_mod),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstanceallday->sync_data1),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->is_allday),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/ipc/cal_ipc_marshal_instance_allday_extended.c b/common/ipc/cal_ipc_marshal_instance_allday_extended.c
new file mode 100755 (executable)
index 0000000..aa5005e
--- /dev/null
@@ -0,0 +1,253 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "cal_internal.h"
+#include "cal_ipc_marshal.h"
+#include "cal_view.h"
+
+static int __cal_ipc_unmarshal_instance_allday_extended(pims_ipc_data_h ipc_data, calendar_record_h record);
+static int __cal_ipc_marshal_instance_allday_extended(const calendar_record_h record, pims_ipc_data_h ipc_data);
+
+cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_instance_allday_extended_plugin_cb = {
+       .unmarshal_record = __cal_ipc_unmarshal_instance_allday_extended,
+       .marshal_record = __cal_ipc_marshal_instance_allday_extended,
+       .get_primary_id = NULL
+};
+
+static int __cal_ipc_unmarshal_instance_allday_extended(pims_ipc_data_h ipc_data, calendar_record_h record)
+{
+       cal_instance_allday_extended_s* pinstanceallday = NULL;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(record==NULL,CALENDAR_ERROR_NO_DATA);
+
+       pinstanceallday = (cal_instance_allday_extended_s*) record;
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->event_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->calendar_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&pinstanceallday->start) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&pinstanceallday->end) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstanceallday->summary) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstanceallday->description) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstanceallday->location) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->busy_status) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->event_status) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->priority) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->sensitivity) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->has_rrule) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_double(ipc_data,&pinstanceallday->latitude) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_double(ipc_data,&pinstanceallday->longitude) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->has_alarm) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->original_event_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_lli(ipc_data,&pinstanceallday->last_mod) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstanceallday->sync_data1) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstanceallday->organizer_name) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstanceallday->categories) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->has_attendee) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstanceallday->sync_data2) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstanceallday->sync_data3) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstanceallday->sync_data4) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstanceallday->is_allday) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_instance_allday_extended(const calendar_record_h record, pims_ipc_data_h ipc_data)
+{
+       cal_instance_allday_extended_s* pinstanceallday = (cal_instance_allday_extended_s*) record;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(pinstanceallday==NULL,CALENDAR_ERROR_NO_DATA);
+
+       if (_cal_ipc_marshal_int((pinstanceallday->event_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->calendar_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((pinstanceallday->start),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((pinstanceallday->end),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstanceallday->summary),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstanceallday->description),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstanceallday->location),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->busy_status),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->event_status),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->priority),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->sensitivity),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->has_rrule),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_double((pinstanceallday->latitude),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_double((pinstanceallday->longitude),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->has_alarm),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->original_event_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_lli((pinstanceallday->last_mod),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstanceallday->sync_data1),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstanceallday->organizer_name),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstanceallday->categories),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->has_attendee),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstanceallday->sync_data2),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstanceallday->sync_data3),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstanceallday->sync_data4),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstanceallday->is_allday),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/ipc/cal_ipc_marshal_instance_normal.c b/common/ipc/cal_ipc_marshal_instance_normal.c
new file mode 100644 (file)
index 0000000..4478bb4
--- /dev/null
@@ -0,0 +1,196 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "cal_internal.h"
+#include "cal_ipc_marshal.h"
+#include "cal_view.h"
+
+static int __cal_ipc_unmarshal_instance_normal(pims_ipc_data_h ipc_data, calendar_record_h record);
+static int __cal_ipc_marshal_instance_normal(const calendar_record_h record, pims_ipc_data_h ipc_data);
+
+cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_instance_normal_plugin_cb = {
+       .unmarshal_record = __cal_ipc_unmarshal_instance_normal,
+       .marshal_record = __cal_ipc_marshal_instance_normal,
+       .get_primary_id = NULL
+};
+
+static int __cal_ipc_unmarshal_instance_normal(pims_ipc_data_h ipc_data, calendar_record_h record)
+{
+       cal_instance_normal_s* pinstancenormal = NULL;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(record==NULL,CALENDAR_ERROR_NO_DATA);
+
+       pinstancenormal = (cal_instance_normal_s*) record;
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->event_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->calendar_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&pinstancenormal->start) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&pinstancenormal->end) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstancenormal->summary) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstancenormal->description) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstancenormal->location) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->busy_status) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->event_status) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->priority) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->sensitivity) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->has_rrule) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_double(ipc_data,&pinstancenormal->latitude) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_double(ipc_data,&pinstancenormal->longitude) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->has_alarm) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->original_event_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_lli(ipc_data,&pinstancenormal->last_mod) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstancenormal->sync_data1) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_instance_normal(const calendar_record_h record, pims_ipc_data_h ipc_data)
+{
+       cal_instance_normal_s* pinstancenormal = (cal_instance_normal_s*) record;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(pinstancenormal==NULL,CALENDAR_ERROR_NO_DATA);
+
+       if (_cal_ipc_marshal_int((pinstancenormal->event_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->calendar_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((pinstancenormal->start),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((pinstancenormal->end),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstancenormal->summary),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstancenormal->description),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstancenormal->location),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->busy_status),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->event_status),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->priority),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->sensitivity),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->has_rrule),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_double((pinstancenormal->latitude),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_double((pinstancenormal->longitude),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->has_alarm),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->original_event_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_lli((pinstancenormal->last_mod),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstancenormal->sync_data1),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/ipc/cal_ipc_marshal_instance_normal_extended.c b/common/ipc/cal_ipc_marshal_instance_normal_extended.c
new file mode 100755 (executable)
index 0000000..262603e
--- /dev/null
@@ -0,0 +1,245 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "cal_internal.h"
+#include "cal_ipc_marshal.h"
+#include "cal_view.h"
+
+static int __cal_ipc_unmarshal_instance_normal_extended(pims_ipc_data_h ipc_data, calendar_record_h record);
+static int __cal_ipc_marshal_instance_normal_extended(const calendar_record_h record, pims_ipc_data_h ipc_data);
+
+cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_instance_normal_extended_plugin_cb = {
+       .unmarshal_record = __cal_ipc_unmarshal_instance_normal_extended,
+       .marshal_record = __cal_ipc_marshal_instance_normal_extended,
+       .get_primary_id = NULL
+};
+
+static int __cal_ipc_unmarshal_instance_normal_extended(pims_ipc_data_h ipc_data, calendar_record_h record)
+{
+       cal_instance_normal_extended_s* pinstancenormal = NULL;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(record==NULL,CALENDAR_ERROR_NO_DATA);
+
+       pinstancenormal = (cal_instance_normal_extended_s*) record;
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->event_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->calendar_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&pinstancenormal->start) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&pinstancenormal->end) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstancenormal->summary) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstancenormal->description) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstancenormal->location) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->busy_status) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->event_status) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->priority) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->sensitivity) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->has_rrule) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_double(ipc_data,&pinstancenormal->latitude) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_double(ipc_data,&pinstancenormal->longitude) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->has_alarm) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->original_event_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_lli(ipc_data,&pinstancenormal->last_mod) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstancenormal->sync_data1) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstancenormal->organizer_name) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstancenormal->categories) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pinstancenormal->has_attendee) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstancenormal->sync_data2) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstancenormal->sync_data3) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&pinstancenormal->sync_data4) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_instance_normal_extended(const calendar_record_h record, pims_ipc_data_h ipc_data)
+{
+       cal_instance_normal_extended_s* pinstancenormal = (cal_instance_normal_extended_s*) record;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(pinstancenormal==NULL,CALENDAR_ERROR_NO_DATA);
+
+       if (_cal_ipc_marshal_int((pinstancenormal->event_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->calendar_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((pinstancenormal->start),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((pinstancenormal->end),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstancenormal->summary),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstancenormal->description),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstancenormal->location),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->busy_status),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->event_status),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->priority),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->sensitivity),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->has_rrule),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_double((pinstancenormal->latitude),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_double((pinstancenormal->longitude),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->has_alarm),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->original_event_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_lli((pinstancenormal->last_mod),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstancenormal->sync_data1),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstancenormal->organizer_name),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstancenormal->categories),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pinstancenormal->has_attendee),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstancenormal->sync_data2),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstancenormal->sync_data3),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((pinstancenormal->sync_data4),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/ipc/cal_ipc_marshal_search.c b/common/ipc/cal_ipc_marshal_search.c
new file mode 100644 (file)
index 0000000..6509e96
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h> //calloc
+#include "cal_internal.h"
+#include "cal_ipc_marshal.h"
+#include "cal_view.h"
+
+static int __cal_ipc_unmarshal_search(pims_ipc_data_h ipc_data, calendar_record_h record);
+static int __cal_ipc_marshal_search(const calendar_record_h record, pims_ipc_data_h ipc_data);
+
+cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_search_plugin_cb = {
+       .unmarshal_record = __cal_ipc_unmarshal_search,
+       .marshal_record = __cal_ipc_marshal_search,
+       .get_primary_id = NULL
+};
+
+static int __cal_ipc_unmarshal_search_value(pims_ipc_data_h ipc_data, cal_search_value_s* pvalue);
+static int __cal_ipc_marshal_search_value(const cal_search_value_s* pvalue, pims_ipc_data_h ipc_data);
+
+static int __cal_ipc_unmarshal_search(pims_ipc_data_h ipc_data, calendar_record_h record)
+{
+       cal_search_s* psearch = NULL;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(record==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       psearch = (cal_search_s*) record;
+
+       int count = 0,i = 0;
+       if (_cal_ipc_unmarshal_int(ipc_data,&count) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       for(i=0;i<count;i++) {
+               cal_search_value_s* value_data = NULL;
+               value_data = calloc(1, sizeof(cal_search_value_s));
+               if (value_data == NULL) {
+                       ERR("calloc fail");
+                       return CALENDAR_ERROR_OUT_OF_MEMORY;
+               }
+
+               if (__cal_ipc_unmarshal_search_value(ipc_data, value_data) != CALENDAR_ERROR_NONE) {
+                       CAL_FREE(value_data);
+                       ERR("_cal_ipc_unmarshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               psearch->values = g_slist_append(psearch->values, value_data);
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_search(const calendar_record_h record, pims_ipc_data_h ipc_data)
+{
+       cal_search_s* psearch = (cal_search_s*) record;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(psearch==NULL,CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (psearch->values) {
+               int count = g_slist_length(psearch->values);
+               GSList *cursor = psearch->values;
+               cal_search_value_s* value_data;
+
+               if (_cal_ipc_marshal_int(count,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+
+               while (cursor) {
+                       value_data = (cal_search_value_s *)cursor->data;
+                       if (value_data == NULL) {
+                               cursor = g_slist_next(cursor);
+                               continue;
+                       }
+                       if (__cal_ipc_marshal_search_value((const cal_search_value_s*)value_data, ipc_data) != CALENDAR_ERROR_NONE) {
+                               ERR("_cal_ipc_marshal fail");
+                               return CALENDAR_ERROR_INVALID_PARAMETER;
+                       }
+                       cursor = g_slist_next(cursor);
+               }
+
+       }
+       else {
+               if (_cal_ipc_marshal_int(0,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_unmarshal_search_value(pims_ipc_data_h ipc_data, cal_search_value_s* pvalue)
+{
+       if (_cal_ipc_unmarshal_int(ipc_data,&pvalue->property_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (CAL_PROPERTY_CHECK_DATA_TYPE(pvalue->property_id, CAL_PROPERTY_DATA_TYPE_STR) == true) {
+               if (_cal_ipc_unmarshal_char(ipc_data,&pvalue->value.s) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+       else if (CAL_PROPERTY_CHECK_DATA_TYPE(pvalue->property_id, CAL_PROPERTY_DATA_TYPE_INT) == true) {
+               if (_cal_ipc_unmarshal_int(ipc_data,&pvalue->value.i) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+       else if (CAL_PROPERTY_CHECK_DATA_TYPE(pvalue->property_id, CAL_PROPERTY_DATA_TYPE_DOUBLE) == true) {
+               if (_cal_ipc_unmarshal_double(ipc_data,&pvalue->value.d) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+       else if (CAL_PROPERTY_CHECK_DATA_TYPE(pvalue->property_id, CAL_PROPERTY_DATA_TYPE_LLI) == true) {
+               if (_cal_ipc_unmarshal_lli(ipc_data,&pvalue->value.lli) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+       else if (CAL_PROPERTY_CHECK_DATA_TYPE(pvalue->property_id, CAL_PROPERTY_DATA_TYPE_CALTIME) == true) {
+               if (_cal_ipc_unmarshal_caltime(ipc_data,&pvalue->value.caltime) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+       else {
+               ERR("invalid parameter (property:%d)",pvalue->property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_search_value(const cal_search_value_s* pvalue, pims_ipc_data_h ipc_data)
+{
+       if (_cal_ipc_marshal_int(pvalue->property_id,ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (CAL_PROPERTY_CHECK_DATA_TYPE(pvalue->property_id, CAL_PROPERTY_DATA_TYPE_STR) == true) {
+               if (_cal_ipc_marshal_char(pvalue->value.s,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+       else if (CAL_PROPERTY_CHECK_DATA_TYPE(pvalue->property_id, CAL_PROPERTY_DATA_TYPE_INT) == true) {
+               if (_cal_ipc_marshal_int(pvalue->value.i,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+       else if (CAL_PROPERTY_CHECK_DATA_TYPE(pvalue->property_id, CAL_PROPERTY_DATA_TYPE_DOUBLE) == true) {
+               if (_cal_ipc_marshal_double(pvalue->value.d,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+       else if (CAL_PROPERTY_CHECK_DATA_TYPE(pvalue->property_id, CAL_PROPERTY_DATA_TYPE_LLI) == true) {
+               if (_cal_ipc_marshal_lli(pvalue->value.lli,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+       else if (CAL_PROPERTY_CHECK_DATA_TYPE(pvalue->property_id, CAL_PROPERTY_DATA_TYPE_CALTIME) == true) {
+               if (_cal_ipc_marshal_caltime(pvalue->value.caltime,ipc_data) != CALENDAR_ERROR_NONE) {
+                       ERR("_cal_ipc_marshal fail");
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+       else {
+               ERR("invalid parameter (property:%d)",pvalue->property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/common/ipc/cal_ipc_marshal_timezone.c b/common/ipc/cal_ipc_marshal_timezone.c
new file mode 100644 (file)
index 0000000..0452aee
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "cal_internal.h"
+#include "cal_ipc_marshal.h"
+#include "cal_view.h"
+
+static int __cal_ipc_unmarshal_timezone(pims_ipc_data_h ipc_data, calendar_record_h record);
+static int __cal_ipc_marshal_timezone(const calendar_record_h record, pims_ipc_data_h ipc_data);
+static int __cal_ipc_marshal_timezone_get_primary_id(const calendar_record_h record, unsigned int *property_id, int *id);
+
+cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_timezone_plugin_cb = {
+       .unmarshal_record = __cal_ipc_unmarshal_timezone,
+       .marshal_record = __cal_ipc_marshal_timezone,
+       .get_primary_id = __cal_ipc_marshal_timezone_get_primary_id
+};
+
+static int __cal_ipc_unmarshal_timezone(pims_ipc_data_h ipc_data, calendar_record_h record)
+{
+       cal_timezone_s* ptimezone = NULL;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(record==NULL,CALENDAR_ERROR_NO_DATA);
+
+       ptimezone = (cal_timezone_s*) record;
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptimezone->index) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptimezone->tz_offset_from_gmt) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptimezone->standard_name) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptimezone->std_start_month) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptimezone->std_start_position_of_week) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptimezone->std_start_day) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptimezone->std_start_hour) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptimezone->standard_bias) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptimezone->day_light_name) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptimezone->day_light_start_month) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptimezone->day_light_start_position_of_week) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptimezone->day_light_start_day) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptimezone->day_light_start_hour) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptimezone->day_light_bias) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptimezone->calendar_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_timezone(const calendar_record_h record, pims_ipc_data_h ipc_data)
+{
+       cal_timezone_s* ptimezone = (cal_timezone_s*) record;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(ptimezone==NULL,CALENDAR_ERROR_NO_DATA);
+
+       if (_cal_ipc_marshal_int((ptimezone->index),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptimezone->tz_offset_from_gmt),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptimezone->standard_name),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptimezone->std_start_month),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptimezone->std_start_position_of_week),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptimezone->std_start_day),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptimezone->std_start_hour),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptimezone->standard_bias),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptimezone->day_light_name),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptimezone->day_light_start_month),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptimezone->day_light_start_position_of_week),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptimezone->day_light_start_day),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptimezone->day_light_start_hour),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptimezone->day_light_bias),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptimezone->calendar_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_timezone_get_primary_id(const calendar_record_h record, unsigned int *property_id, int *id)
+{
+       *property_id = CAL_PROPERTY_TIMEZONE_ID;
+       return calendar_record_get_int(record, *property_id, id );
+}
diff --git a/common/ipc/cal_ipc_marshal_todo.c b/common/ipc/cal_ipc_marshal_todo.c
new file mode 100644 (file)
index 0000000..ebae1ca
--- /dev/null
@@ -0,0 +1,455 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "cal_internal.h"
+#include "cal_ipc_marshal.h"
+#include "cal_view.h"
+
+static int __cal_ipc_unmarshal_todo(pims_ipc_data_h ipc_data, calendar_record_h record);
+static int __cal_ipc_marshal_todo(const calendar_record_h record, pims_ipc_data_h ipc_data);
+static int __cal_ipc_marshal_todo_get_primary_id(const calendar_record_h record, unsigned int *property_id, int *id);
+
+cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_todo_plugin_cb = {
+       .unmarshal_record = __cal_ipc_unmarshal_todo,
+       .marshal_record = __cal_ipc_marshal_todo,
+       .get_primary_id = __cal_ipc_marshal_todo_get_primary_id
+};
+
+static int __cal_ipc_unmarshal_todo(pims_ipc_data_h ipc_data, calendar_record_h record)
+{
+       cal_todo_s* ptodo = NULL;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(record==NULL,CALENDAR_ERROR_NO_DATA);
+
+       ptodo = (cal_todo_s*) record;
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptodo->index) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptodo->calendar_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->summary) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->description) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->location) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->categories) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,(int*)&ptodo->todo_status) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,(int*)&ptodo->priority) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptodo->sensitivity) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->uid) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_double(ipc_data,&ptodo->latitude) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_double(ipc_data,&ptodo->longitude) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_lli(ipc_data,&ptodo->created_time) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_lli(ipc_data,&ptodo->completed_time) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptodo->progress) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptodo->is_deleted) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_lli(ipc_data,&ptodo->last_mod) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptodo->freq) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptodo->range_type) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&ptodo->until) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptodo->count) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptodo->interval) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->bysecond) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->byminute) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->byhour) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->byday) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->bymonthday) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->byyearday) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->byweekno) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->bymonth) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->bysetpos) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptodo->wkst) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptodo->has_alarm) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_long(ipc_data,&ptodo->updated) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->sync_data1) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->sync_data2) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->sync_data3) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->sync_data4) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&ptodo->start) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->start_tzid) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_caltime(ipc_data,&ptodo->due) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->due_tzid) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->organizer_name) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_char(ipc_data,&ptodo->organizer_email) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptodo->has_attendee) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&ptodo->is_allday) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (CALENDAR_ERROR_NONE != _cal_ipc_unmarshal_list(ipc_data, (calendar_list_h *)&ptodo->alarm_list)) {
+               ERR("_cal_ipc_unmarshal_list fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (CALENDAR_ERROR_NONE != _cal_ipc_unmarshal_list(ipc_data, (calendar_list_h *)&ptodo->attendee_list)) {
+               ERR("_cal_ipc_unmarshal_list fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (CALENDAR_ERROR_NONE != _cal_ipc_unmarshal_list(ipc_data, (calendar_list_h *)&ptodo->extended_list)) {
+               ERR("_cal_ipc_unmarshal_list fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_todo(const calendar_record_h record, pims_ipc_data_h ipc_data)
+{
+       cal_todo_s* ptodo = (cal_todo_s*)record;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(ptodo==NULL,CALENDAR_ERROR_NO_DATA);
+
+       if (_cal_ipc_marshal_int((ptodo->index),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->calendar_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->summary),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->description),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->location),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->categories),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->todo_status),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->priority),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->sensitivity),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->uid),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_double((ptodo->latitude),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_double((ptodo->longitude),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_lli((ptodo->created_time),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_lli((ptodo->completed_time),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->progress),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->is_deleted),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_lli((ptodo->last_mod),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->freq),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->range_type),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((ptodo->until),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->count),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->interval),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->bysecond),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->byminute),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->byhour),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->byday),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->bymonthday),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->byyearday),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->byweekno),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->bymonth),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->bysetpos),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->wkst),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->has_alarm),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_long((ptodo->updated),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->sync_data1),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->sync_data2),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->sync_data3),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->sync_data4),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((ptodo->start),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->start_tzid),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_caltime((ptodo->due),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->due_tzid),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->organizer_name),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_char((ptodo->organizer_email),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->has_attendee),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((ptodo->is_allday),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (CALENDAR_ERROR_NONE != _cal_ipc_marshal_list((calendar_list_h)ptodo->alarm_list, ipc_data)) {
+               ERR("_cal_ipc_marshal_list fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (CALENDAR_ERROR_NONE != _cal_ipc_marshal_list((calendar_list_h)ptodo->attendee_list, ipc_data)) {
+               ERR("_cal_ipc_marshal_list fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (CALENDAR_ERROR_NONE != _cal_ipc_marshal_list((calendar_list_h)ptodo->extended_list, ipc_data)) {
+               ERR("_cal_ipc_marshal_list fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_todo_get_primary_id(const calendar_record_h record, unsigned int *property_id, int *id)
+{
+       *property_id = CAL_PROPERTY_TODO_ID;
+       return calendar_record_get_int(record, *property_id, id );
+}
+
diff --git a/common/ipc/cal_ipc_marshal_updated_info.c b/common/ipc/cal_ipc_marshal_updated_info.c
new file mode 100644 (file)
index 0000000..ca50389
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "cal_internal.h"
+#include "cal_ipc_marshal.h"
+
+static int __cal_ipc_unmarshal_updated_info(pims_ipc_data_h ipc_data, calendar_record_h record);
+static int __cal_ipc_marshal_updated_info(const calendar_record_h record, pims_ipc_data_h ipc_data);
+
+cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_updated_info_plugin_cb = {
+       .unmarshal_record = __cal_ipc_unmarshal_updated_info,
+       .marshal_record = __cal_ipc_marshal_updated_info,
+       .get_primary_id = NULL
+};
+
+static int __cal_ipc_unmarshal_updated_info(pims_ipc_data_h ipc_data, calendar_record_h record)
+{
+       cal_updated_info_s* pupdatedinfo = NULL;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(record==NULL,CALENDAR_ERROR_NO_DATA);
+
+       pupdatedinfo = (cal_updated_info_s*) record;
+
+       if (_cal_ipc_unmarshal_int(ipc_data,&pupdatedinfo->type) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pupdatedinfo->id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pupdatedinfo->calendar_id) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_unmarshal_int(ipc_data,&pupdatedinfo->version) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_ipc_marshal_updated_info(const calendar_record_h record, pims_ipc_data_h ipc_data)
+{
+       cal_updated_info_s* pupdatedinfo = (cal_updated_info_s*) record;
+       retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
+       retv_if(pupdatedinfo==NULL,CALENDAR_ERROR_NO_DATA);
+
+       if (_cal_ipc_marshal_int((pupdatedinfo->type),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pupdatedinfo->id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pupdatedinfo->calendar_id),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (_cal_ipc_marshal_int((pupdatedinfo->version),ipc_data) != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_marshal fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/debian/changelog b/debian/changelog
deleted file mode 100644 (file)
index e605b1d..0000000
+++ /dev/null
@@ -1,2149 +0,0 @@
-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.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-36
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Thu, 02 Aug 2012 22:22:13 +0900
-
-libslp-calendar (0.1.13-35) unstable; urgency=low
-
-  * fixed: s1-6577.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-35
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Wed, 01 Aug 2012 21:04:51 +0900
-
-libslp-calendar (0.1.13-34) unstable; urgency=low
-
-  * fixed: s1-6343.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-34
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Tue, 31 Jul 2012 20:01:00 +0900
-
-libslp-calendar (0.1.13-33) unstable; urgency=low
-
-  * added op code for location
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-33
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Tue, 31 Jul 2012 11:04:01 +0900
-
-libslp-calendar (0.1.13-32) unstable; urgency=low
-
-  * fixed s1-6157, 6184, 6213, 6499.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-32
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Mon, 30 Jul 2012 17:37:05 +0900
-
-libslp-calendar (0.1.13-31) unstable; urgency=low
-
-  * updated tag name.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-31
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Fri, 27 Jul 2012 10:27:17 +0900
-
-libslp-calendar (0.1.13-30) unstable; urgency=low
-
-  * fixed jira 6213.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-30
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Wed, 25 Jul 2012 13:09:20 +0900
-
-libslp-calendar (0.1.13-29) unstable; urgency=low
-
-  * modified jira issue. s1-6213.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-29
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Mon, 23 Jul 2012 17:44:42 +0900
-
-libslp-calendar (0.1.13-28) unstable; urgency=low
-
-  * added define before deprecated enum value.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-28
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Mon, 23 Jul 2012 13:32:18 +0900
-
-libslp-calendar (0.1.13-27) unstable; urgency=low
-
-  * updated changelog for obs.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-27
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Sat, 21 Jul 2012 10:40:l5 +0900
-
-libslp-calendar (0.1.13-26) unstable; urgency=low
-
-  * fixed todo condition query: time type was changed from long int to long long int.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-26
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Fri, 20 Jul 2012 15:31:09 +0900
-
-libslp-calendar (0.1.13-25) unstable; urgency=low
-
-  * updated changelog for obs.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-25
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Tue, 17 Jul 2012 17:44:14 +0900
-
-libslp-calendar (0.1.13-24) unstable; urgency=low
-
-  * fixed bug: stmt was not filled before step, added notify after deleting instance.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-24
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Mon, 16 Jul 2012 18:59:53 +0900
-
-libslp-calendar (0.1.13-23) unstable; urgency=low
-
-  * added api for get_todo_iter without period.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-23
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Mon, 16 Jul 2012 18:59:51 +0900
-
-libslp-calendar (0.1.13-22) unstable; urgency=low
-
-  * fixed updated deleted table in local calendar.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-22
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Tue, 10 Jul 2012 15:26:47 +0900
-
-libslp-calendar (0.1.13-21) unstable; urgency=low
-
-  * able to add db for past event, but not registered to alarmmgr.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-21
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Mon, 09 Jul 2012 17:45:22 +0900
-
-libslp-calendar (0.1.13-20) unstable; urgency=low
-
-  * fixed not showing repeat, alarm in db.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-20
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Thu, 05 Jul 2012 18:36:56 +0900
-
-libslp-calendar (0.1.13-19) unstable; urgency=low
-
-  * added type in instance struct.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-19
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Tue, 03 Jul 2012 15:26:31 +0900
-
-libslp-calendar (0.1.13-18) unstable; urgency=low
-
-  * updated until when once event.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-18
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Sun, 01 Jul 2012 21:40:19 +0900
-
-libslp-calendar (0.1.13-17) unstable; urgency=low
-
-  * 1. added instance table for allday and normal events. 2. added period search APIs 3. added test code.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-17
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Sun, 01 Jul 2012 16:31:43 +0900
-
-libslp-calendar (0.1.13-16) unstable; urgency=low
-
-  * clean deprecated code.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-16
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Wed, 20 Jun 2012 18:09:08 +0900
-
-libslp-calendar (0.1.13-15) unstable; urgency=low
-
-  * fixed bug: noty event.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-15
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Tue, 22 May 2012 16:39:46 +0900
-
-libslp-calendar (0.1.13-14) unstable; urgency=low
-
-  * fixed bug: change iter policy.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-14
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Fri, 18 May 2012 17:20:17 +0900
-
-libslp-calendar (0.1.13-13) unstable; urgency=low
-
-  * fixed bug: deleted sync.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-13
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Fri, 18 May 2012 14:50:38 +0900
-
-libslp-calendar (0.1.13-12) unstable; urgency=low
-
-  * fiex bug in get_changes.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-12
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Mon, 14 May 2012 17:18:56 +0900
-
-libslp-calendar (0.1.13-11) unstable; urgency=low
-
-  * fixed error query in get_changes.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-11
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Mon, 14 May 2012 15:28:57 +0900
-
-libslp-calendar (0.1.13-10) unstable; urgency=low
-
-  * fixed bug.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-10
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Thu, 10 May 2012 17:04:39 +0900
-
-libslp-calendar (0.1.13-9) unstable; urgency=low
-
-  * Add smartsearch API
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-9
-
- -- Sunghyuk Lee <sunghyuk.lee@samsung.com>  Thu, 10 May 2012 16:08:08 +0900
-
-libslp-calendar (0.1.13-8) unstable; urgency=low
-
-  * added is_deleted and event, todo changes..
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-8
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Tue, 08 May 2012 20:13:09 +0900
-
-libslp-calendar (0.1.13-7) unstable; urgency=low
-
-  * fixed duplicated sting.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-7
-
- -- Sunghyuk Lee <sunghyuk.lee@samsung.com>  Thu, 03 May 2012 16:46:34 +0900
-
-libslp-calendar (0.1.13-6) unstable; urgency=low
-
-  * modified import export vcs file apis.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-6
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Thu, 26 Apr 2012 21:43:50 +0900
-
-libslp-calendar (0.1.13-5) unstable; urgency=low
-
-  * Replace 1st paramter of calendar_svc_get_updated_schedules
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-5
-
- -- Sunghyuk Lee <sunghyuk.lee@samsung.com>  Thu, 26 Apr 2012 13:38:30 +0900
-
-libslp-calendar (0.1.13-4) unstable; urgency=low
-
-  * updated changelog and modified api name write schedules.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-4
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Wed, 25 Apr 2012 10:29:17 +0900
-
-libslp-calendar (0.1.13-3) unstable; urgency=low
-
-  * added quotied printable, rrule for vcal.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-3
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Mon, 23 Apr 2012 10:33:02 +0900
-
-libslp-calendar (0.1.13-2) unstable; urgency=low
-
-  * Change calendar_svc_end_trans parameter
-  * Fix timezone data getting bug
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-2
-
- -- Sunghyuk Lee <sunghyuk.lee@samsung.com>  Thu, 19 Apr 2012 20:14:15 +0900
-
-libslp-calendar (0.1.13-1) unstable; urgency=low
-
-  * Add calender versioning feature
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.13-1
-
- -- Sunghyuk Lee <sunghyuk.lee@samsung.com>  Mon, 16 Apr 2012 16:14:42 +0900
-
-libslp-calendar (0.1.12-23) unstable; urgency=low
-
-  * Set the repeat end date unless its until_type is date-time (N_SE 505)
-  * Fix a crash caused by timezone vconf
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-23
-
- -- Sunghyuk Lee <sunghyuk.lee@samsung.com>  Fri, 13 Apr 2012 09:24:22 +0900
-
-libslp-calendar (0.1.12-22) unstable; urgency=low
-
-  * Make the last modified time field read-only
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-22
-
- -- Sunghyuk Lee <sunghyuk.lee@samsung.com>  Thu, 05 Apr 2012 10:16:16 +0900
-
-libslp-calendar (0.1.12-21) unstable; urgency=low
-
-  * modified alarm description error (located wrong column)
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-21
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Mon, 02 Apr 2012 17:24:25 +0900
-
-libslp-calendar (0.1.12-20) unstable; urgency=low
-
-  * Add repeat until type
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-20
-
- -- Sunghyuk Lee <sunghyuk.lee@samsung.com>  Fri, 30 Mar 2012 18:47:39 +0900
-
-libslp-calendar (0.1.12-19) unstable; urgency=low
-
-  * modified todo and rrule crash.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-19
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Fri, 30 Mar 2012 10:05:05 +0900
-
-libslp-calendar (0.1.12-18) unstable; urgency=low
-
-  * Fix a bug on getting todo list and add order option
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-18
-
- -- Sunghyuk Lee <sunghyuk.lee@samsung.com>  Thu, 29 Mar 2012 13:53:17 +0900
-
-libslp-calendar (0.1.12-17) unstable; urgency=low
-
-  * modified icalendar decoding code.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-17
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Wed, 21 Mar 2012 10:00:00 +0900
-
-libslp-calendar (0.1.12-16) unstable; urgency=low
-
-  * added calendar sensitivity enum values.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-16
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Tue, 21 Feb 2012 10:00:00 +0900
-
-libslp-calendar (0.1.12-15) unstable; urgency=low
-
-  * fiexed query for edit.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-15
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Fri, 17 Feb 2012 13:00:00 +0900
-
-libslp-calendar (0.1.12-14) unstable; urgency=low
-
-  * added alarm_description.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-14
-
- -- Jeesun Kim <iamjs.kim@samsung.com>  Fri, 10 Feb 2012 16:00:00 +0900
-
-libslp-calendar (0.1.12-13) unstable; urgency=low
-
-  * revise
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-13
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Wed, 01 Feb 2012 10:16:13 +0900
-
-libslp-calendar (0.1.12-12) unstable; urgency=low
-
-  * change default calendar application pkg name
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-12
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Thu, 26 Jan 2012 09:07:42 +0900
-
-libslp-calendar (0.1.12-11) unstable; urgency=low
-
-  * fix bug
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-11
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Thu, 19 Jan 2012 11:33:45 +0900
-
-libslp-calendar (0.1.12-10) unstable; urgency=low
-
-  * revise noti
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-10
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Mon, 16 Jan 2012 11:15:38 +0900
-
-libslp-calendar (0.1.12-9) unstable; urgency=low
-
-  * add type for calendar
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-9
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Thu, 12 Jan 2012 17:04:34 +0900
-
-libslp-calendar (0.1.12-8) unstable; urgency=low
-
-  * clean up and change enum name
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-8
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Fri, 06 Jan 2012 15:01:13 +0900
-
-libslp-calendar (0.1.12-7) unstable; urgency=low
-
-  * fix bug
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-7
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Mon, 26 Dec 2011 18:44:07 +0900
-
-libslp-calendar (0.1.12-6) unstable; urgency=low
-
-  * fix bug
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-6
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Thu, 22 Dec 2011 10:26:12 +0900
-
-libslp-calendar (0.1.12-5) unstable; urgency=low
-
-  * fix bugs
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-5
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Wed, 14 Dec 2011 10:29:27 +0900
-
-libslp-calendar (0.1.12-4) unstable; urgency=low
-
-  * fix bugs
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-4
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Thu, 08 Dec 2011 18:12:54 +0900
-
-libslp-calendar (0.1.12-3) unstable; urgency=low
-
-  * fix bugs
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-3
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Thu, 08 Dec 2011 13:39:10 +0900
-
-libslp-calendar (0.1.12-2) unstable; urgency=low
-
-  * fix bugs
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-2
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Thu, 08 Dec 2011 11:05:37 +0900
-
-libslp-calendar (0.1.12-1) unstable; urgency=low
-
-  * revise alarm(support multi alarms)
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.12-1
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Mon, 05 Dec 2011 15:55:16 +0900
-
-libslp-calendar (0.1.11-4) unstable; urgency=low
-
-  * fix bug generated by "clean up"
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.11-4
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Tue, 22 Nov 2011 13:45:44 +0900
-
-libslp-calendar (0.1.11-3) unstable; urgency=low
-
-  * add old files for immigration
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.11-3
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Mon, 21 Nov 2011 14:50:38 +0900
-
-libslp-calendar (0.1.11-2) unstable; urgency=low
-
-  * fix bug generated by "clean up"
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.11-2
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Mon, 21 Nov 2011 14:16:53 +0900
-
-libslp-calendar (0.1.11-1) unstable; urgency=low
-
-  * clean up
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.11-1
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Sat, 19 Nov 2011 16:48:56 +0900
-
-libslp-calendar (0.1.10-35) unstable; urgency=low
-
-  * Fix bug : Update alarm info.
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-35
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Tue, 15 Nov 2011 10:59:02 +0900
-
-libslp-calendar (0.1.10-34) unstable; urgency=low
-
-  * code cleanup and fix bug of using heynoti
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-34
-
- -- Youngjae Shin <yj99.shin@samsung.com>  Thu, 03 Nov 2011 20:46:44 +0900
-
-libslp-calendar (0.1.10-33) unstable; urgency=low
-
-  * Change lock timezone vconf
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-33
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Sat, 30 Oct 2011 14:34:34 +0900
-
-libslp-calendar (0.1.10-32) unstable; urgency=low
-
-  * fixed multiple alarm problem
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-32
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Sat, 29 Oct 2011 14:34:34 +0900
-
-libslp-calendar (0.1.10-31) unstable; urgency=low
-
-  * add calendar multivalue list remove function
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-31
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 26 Oct 2011 15:25:05 +0900
-
-libslp-calendar (0.1.10-30) unstable; urgency=low
-
-  * add calendar multivalue list remove function
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-30
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Tue, 18 Oct 2011 13:09:51 +0900
-
-libslp-calendar (0.1.10-29) unstable; urgency=low
-
-  * noti type add for calendarbook update, basic test passed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-29
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Sat, 08 Oct 2011 14:23:39 +0900
-
-libslp-calendar (0.1.10-28) unstable; urgency=low
-
-  * vcalendar convert error fixed, basic test passed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-28
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Fri, 30 Sep 2011 17:39:41 +0900
-
-libslp-calendar (0.1.10-27) unstable; urgency=low
-
-  * all day event exception handling error fixed, basic test passed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-27
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 21 Sep 2011 15:28:50 +0900
-
-libslp-calendar (0.1.10-26) unstable; urgency=low
-
-  * prevent error fixed, basic test passed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-26
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Mon, 19 Sep 2011 20:24:46 +0900
-
-libslp-calendar (0.1.10-25) unstable; urgency=low
-
-  * default calendar error fixed in edit view
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-25
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Fri, 16 Sep 2011 10:16:22 +0900
-
-libslp-calendar (0.1.10-24) unstable; urgency=low
-
-  * pkg update
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-24
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Thu, 08 Sep 2011 12:02:00 +0900
-
-libslp-calendar (0.1.10-23) unstable; urgency=low
-
-  * monthly event count return, delete flag passed to ui
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-23
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Thu, 08 Sep 2011 11:01:30 +0900
-
-libslp-calendar (0.1.10-22) unstable; urgency=low
-
-  * recurrence exception operation error fixed, basic test passed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-22
-
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 07 Sep 2011 19:14:56 +0900
-
-libslp-calendar (0.1.10-21) unstable; urgency=low
-
-  * add get delete flag value,  basic test passed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-21
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 07 Sep 2011 15:19:55 +0900
-
-libslp-calendar (0.1.10-20) unstable; urgency=low
-
-  * prevent error fixed,  basic test passed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-20
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Tue, 06 Sep 2011 09:04:32 +0900
-
-libslp-calendar (0.1.10-19) unstable; urgency=low
-
-  * all day event time setting error fixed,  basic test passed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-19
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Fri, 02 Sep 2011 16:02:08 +0900
-
-libslp-calendar (0.1.10-18) unstable; urgency=low
-
-  * delete error fixed(recurrence delete), TC passed, basic test passed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-18
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Thu, 01 Sep 2011 18:00:32 +0900
-
-libslp-calendar (0.1.10-17) unstable; urgency=low
-
-  * delete error fixed(recurrence delete), TC passed, basic test passed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-17
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Tue, 30 Aug 2011 16:58:05 +0900
-
-libslp-calendar (0.1.10-16) unstable; urgency=low
-
-  * release problem fixed(save error),vobject move to calendar-engine basic test passed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-16
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Mon, 29 Aug 2011 14:01:22 +0900
-
-libslp-calendar (0.1.10-15) unstable; urgency=low
-
-  * change vcalendar encode type,   basic test passed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-15
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 24 Aug 2011 16:49:56 +0900
-
-libslp-calendar (0.1.10-14) unstable; urgency=low
-
-  * vcalendar length error fixed(release issue) , add protection code(MACRO) , TC passed, basic test passed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-14
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Tue, 23 Aug 2011 14:06:33 +0900
-
-libslp-calendar (0.1.10-13) unstable; urgency=low
-
-  * dts error fixed, add location field for get_list
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-13
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 17 Aug 2011 19:42:52 +0900
-
-libslp-calendar (0.1.10-12) unstable; urgency=low
-
-  * remove duplicated delete not
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-12
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Wed, 10 Aug 2011 22:00:38 +0900
-
-
-libslp-calendar (0.1.10-11) unstable; urgency=low
-
-  * remove dependency, pkg release
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-11
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Tue, 02 Aug 2011 16:04:16 +0900
-
-libslp-calendar (0.1.10-10) unstable; urgency=low
-
-  * add error check code
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-10
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Thu, 28 Jul 2011 18:05:21 +0900
-
-libslp-calendar (0.1.10-9) unstable; urgency=low
-
-  * prevent error fixed & api header rearrangement
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-9
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Tue, 26 Jul 2011 18:55:36 +0900
-
-libslp-calendar (0.1.10-8) unstable; urgency=low
-
-  * remove system()
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-8
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 20 Jul 2011 14:51:16 +0900
-
-libslp-calendar (0.1.10-7) unstable; urgency=low
-
-  * pkg update
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-7
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Mon, 18 Jul 2011 15:08:02 +0900
-
-libslp-calendar (0.1.10-6) unstable; urgency=low
-
-  * add exception handling for tz info search api
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-6
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Thu, 07 Jul 2011 11:33:11 +0900
-
-libslp-calendar (0.1.10-5) unstable; urgency=low
-
-  * add exception handling for tz info search api
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-5
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Thu, 07 Jul 2011 09:30:16 +0900
-
-libslp-calendar (0.1.10-4) unstable; urgency=low
-
-  * add tz info header
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-4
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 06 Jul 2011 18:55:50 +0900
-
-libslp-calendar (0.1.10-3) unstable; urgency=low
-
-  * pkg update(set tz info api error fixed)
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-3
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 06 Jul 2011 18:46:19 +0900
-
-libslp-calendar (0.1.10-2) unstable; urgency=low
-
-  * pkg update(sync b/s fixed)
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-2
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 06 Jul 2011 18:41:08 +0900
-
-libslp-calendar (0.1.10-1) unstable; urgency=low
-
-  * pkg update(Auto DST)
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.10-1
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Tue, 05 Jul 2011 15:15:08 +0900
-
-libslp-calendar (0.1.9-11) unstable; urgency=low
-
-  * Add calendar_id in get_list(), Add default calendar color in postinst
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.9-11
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Fri, 24 Jun 2011 13:59:26 +0900
-
-libslp-calendar (0.1.9-10) unstable; urgency=low
-
-  * vobject, task convert error fixed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.9-10
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 22 Jun 2011 16:43:11 +0900
-
-libslp-calendar (0.1.9-9) unstable; urgency=low
-
-  * Modify repeat end date error condition
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.9-9
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Tue, 14 Jun 2011 17:02:59 +0900
-
-libslp-calendar (0.1.9-8) unstable; urgency=low
-
-  * Fix BS issue regarding meeting category
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.9-8
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Thu, 02 Jun 2011 09:26:55 +0900
-
-libslp-calendar (0.1.9-7) unstable; urgency=low
-
-  * search text api modification
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.9-7
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Tue, 24 May 2011 11:38:51 +0900
-
-libslp-calendar (0.1.9-6) unstable; urgency=low
-
-  * alarm error fixed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.9-6
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Tue, 17 May 2011 16:07:47 +0900
-
-libslp-calendar (0.1.9-5) unstable; urgency=low
-
-  * alarm error fixed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.9-5
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Mon, 16 May 2011 10:22:45 +0900
-
-libslp-calendar (0.1.9-4) unstable; urgency=low
-
-  * vobject convert error fixed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.9-4
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Thu, 12 May 2011 17:27:36 +0900
-
-libslp-calendar (0.1.9-3) unstable; urgency=low
-
-  * add list update api
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.9-3
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 11 May 2011 12:23:01 +0900
-
-libslp-calendar (0.1.9-2) unstable; urgency=low
-
-  * Fix recurrence counting bug
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.9-2
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Mon, 02 May 2011 19:29:34 +0900
-
-libslp-calendar (0.1.9-1) unstable; urgency=low
-
-  * ui lockup issue fix
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.9-1
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Thu, 28 Apr 2011 18:43:44 +0900
-
-libslp-calendar (0.1.9-0) unstable; urgency=low
-
-  * voject-convert-error fixed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.9-0
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 27 Apr 2011 18:49:49 +0900
-
-libslp-calendar (0.1.8-99) unstable; urgency=low
-
-  * month check error fixed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-99
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 27 Apr 2011 14:10:32 +0900
-
-libslp-calendar (0.1.8-98) unstable; urgency=low
-
-  * Release 0.1.8-98
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-98
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Wed, 27 Apr 2011 10:15:42 +0900
-
-libslp-calendar (0.1.8-97) unstable; urgency=low
-
-  * Release 0.1.8-97
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-97
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Tue, 26 Apr 2011 14:44:56 +0900
-
-libslp-calendar (0.1.8-96) unstable; urgency=low
-
-  * Release 0.1.8-96
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-96
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Mon, 25 Apr 2011 15:06:23 +0900
-
-libslp-calendar (0.1.8-95) unstable; urgency=low
-
-  * Release 0.1.8-95
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-95
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Mon, 25 Apr 2011 14:48:51 +0900
-
-libslp-calendar (0.1.8-94) unstable; urgency=low
-
-  * Release 0.1.8-94
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-94
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Mon, 25 Apr 2011 11:26:42 +0900
-
-libslp-calendar (0.1.8-93) unstable; urgency=low
-
-  * Release 0.1.8-93
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-93
-
- -- Heungjae Jeong <hj98.jeong@samsung.com>  Wed, 20 Apr 2011 20:09:05 +0900
-
-libslp-calendar (0.1.8-92) unstable; urgency=low
-
-  * Release 0.1.8-92
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-92
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Wed, 20 Apr 2011 10:56:39 +0900
-
-libslp-calendar (0.1.8-91) unstable; urgency=low
-
-  * Release 0.1.8-91
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-91
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Fri, 01 Apr 2011 08:52:50 +0900
-
-libslp-calendar (0.1.8-90) unstable; urgency=low
-
-  * Fix bug : alarm_init
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-90
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Tue, 22 Mar 2011 13:58:37 +0900
-
-libslp-calendar (0.1.8-89) unstable; urgency=low
-
-  * Fix bug : alarm_init
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-89
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Mon, 21 Mar 2011 17:19:09 +0900
-
-libslp-calendar (0.1.8-88) unstable; urgency=low
-
-  * Fix bug : alarm_init
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-88
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Wed, 16 Mar 2011 16:59:05 +0900
-
-libslp-calendar (0.1.8-87) unstable; urgency=low
-
-  * Fix bug : alarm_init
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-87
-
- -- Taeho Kang <taeho84.kang@samsung.com>  Wed, 09 Mar 2011 14:49:36 +0900
-
-libslp-calendar (0.1.8-86) unstable; urgency=low
-
-  * timezone add
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-86
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 22 Feb 2011 12:52:22 +0900
-
-libslp-calendar (0.1.8-85) unstable; urgency=low
-
-  * prevent error fixed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-85
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Wed, 16 Feb 2011 20:27:49 +0900
-
-libslp-calendar (0.1.8-84) unstable; urgency=low
-
-  * pkg update
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-84
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Wed, 16 Feb 2011 15:53:11 +0900
-
-libslp-calendar (0.1.8-83) unstable; urgency=low
-
-  * prevent error fixed, tz type add
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-83
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 15 Feb 2011 20:19:17 +0900
-
-libslp-calendar (0.1.8-82) unstable; urgency=low
-
-  * pc studio b/s error fix
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-82
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Wed, 02 Feb 2011 09:24:35 +0900
-
-libslp-calendar (0.1.8-81) unstable; urgency=low
-
-  * pkg update
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-81
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 27 Jan 2011 13:29:25 +0900
-
-libslp-calendar (0.1.8-80) unstable; urgency=low
-
-  * add account_id for calendar table
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-80
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 27 Jan 2011 13:23:26 +0900
-
-libslp-calendar (0.1.8-79) unstable; urgency=low
-
-  * add account_id for calendar table
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-79
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 27 Jan 2011 10:29:58 +0900
-
-libslp-calendar (0.1.8-78) unstable; urgency=low
-
-  * remove alarm fini api(active sync b/s issue fixed):
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-78
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Wed, 26 Jan 2011 14:55:30 +0900
-
-libslp-calendar (0.1.8-77) unstable; urgency=low
-
-  * setting b/s error fix - alarm fini api add
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-77
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 25 Jan 2011 18:13:26 +0900
-
-libslp-calendar (0.1.8-76) unstable; urgency=low
-
-  * tz name field added for timezone support
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-76
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 20 Jan 2011 20:13:28 +0900
-
-libslp-calendar (0.1.8-75) unstable; urgency=low
-
-  * priority field error fixed, max year value changed(2030->2037)
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-75
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 13 Jan 2011 11:50:39 +0900
-
-libslp-calendar (0.1.8-74) unstable; urgency=low
-
-  * alarm error fix
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-74
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Wed, 12 Jan 2011 11:00:50 +0900
-
-libslp-calendar (0.1.8-73) unstable; urgency=low
-
-  * TC make file modification
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-73
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Fri, 07 Jan 2011 11:31:23 +0900
-
-libslp-calendar (0.1.8-72) unstable; urgency=low
-
-  * delete account error fixed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-72
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 06 Jan 2011 10:36:15 +0900
-
-libslp-calendar (0.1.8-71) unstable; urgency=low
-
-  * account id error fix
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-71
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 04 Jan 2011 14:50:31 +0900
-
-libslp-calendar (0.1.8-70) unstable; urgency=low
-
-  * alarm error fixed
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-70
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Wed, 29 Dec 2010 17:03:06 +0900
-
-libslp-calendar (0.1.8-69) unstable; urgency=low
-
-  * pkgs update
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-69
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 28 Dec 2010 16:09:41 +0900
-
-libslp-calendar (0.1.8-68) unstable; urgency=low
-
-  * fixed recurrence error
-  * Git: /slp/limo/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-68
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 28 Dec 2010 15:37:09 +0900
-
-libslp-calendar (0.1.8-67) unstable; urgency=low
-
-  * prepare limo contribution
-  * Git: /slp/limo/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-67
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 28 Dec 2010 15:22:15 +0900
-
-libslp-calendar (0.1.8-66) unstable; urgency=low
-
-  * prepare limo contribution
-  * Git: /slp/limo/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-66
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Mon, 27 Dec 2010 11:22:49 +0900
-
-libslp-calendar (0.1.8-65) unstable; urgency=low
-
-  * alarm enable
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-65
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Wed, 22 Dec 2010 14:39:24 +0900
-
-libslp-calendar (0.1.8-64) unstable; urgency=low
-
-  * fixed attendee's ct index return error
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-64
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Mon, 20 Dec 2010 21:28:49 +0900
-
-libslp-calendar (0.1.8-63) unstable; urgency=low
-
-  * vobject error fix, alarm type add
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-63
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Fri, 17 Dec 2010 18:18:42 +0900
-
-libslp-calendar (0.1.8-62) unstable; urgency=low
-
-  * postinst error fixed, default calendar added
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-62
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Wed, 15 Dec 2010 08:16:30 +0900
-
-libslp-calendar (0.1.8-61) unstable; urgency=low
-
-  * todo support
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-61
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 14 Dec 2010 10:03:15 +0900
-
-libslp-calendar (0.1.8-60) unstable; urgency=low
-
-  * pkg update
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-60
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Mon, 13 Dec 2010 11:14:11 +0900
-
-libslp-calendar (0.1.8-59) unstable; urgency=low
-
-  * pkg update
-  * Git: slp/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-59
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 09 Dec 2010 17:42:12 +0900
-
-libslp-calendar (0.1.8-58) unstable; urgency=low
-
-  * remove lucene dependency for limo
-  * Git: /slp/limo/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-58
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 09 Dec 2010 17:08:44 +0900
-
-libslp-calendar (0.1.8-57) unstable; urgency=low
-
-  * remove dependency for limo
-  * Git: /slp/limo/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-57
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 09 Dec 2010 16:53:23 +0900
-
-libslp-calendar (0.1.8-56) unstable; urgency=low
-
-  * pkg update for limo
-  * Git: /slp/limo/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-56
-
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 09 Dec 2010 16:42:02 +0900
-
-libslp-calendar (0.1.8-54) unstable; urgency=low
-
-  * pkg update
-  * Git: /slp/limo/pkgs/l/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-54
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 09 Dec 2010 14:34:03 +0900
-
-libslp-calendar (0.1.8-53) unstable; urgency=low
-
-  * removed vobject-service-dev in control
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-53
-
- -- jeesun kim <iamjs.kim@samsung.com>  Fri, 10 Dec 2010 17:07:25 +0900
-
-libslp-calendar (0.1.8-52) unstable; urgency=low
-
-  * pkg update
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-52
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 02 Dec 2010 18:11:32 +0900
-
-libslp-calendar (0.1.8-51) unstable; urgency=low
-
-  * multi calendar index add
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-51
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 25 Nov 2010 17:52:53 +0900
-
-libslp-calendar (0.1.8-50) unstable; urgency=low
-
-  * pkg update
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-50
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 23 Nov 2010 23:14:37 +0900
-
-libslp-calendar (0.1.8-49) unstable; urgency=low
-
-  * pkg update(dependency add-alarm)
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-49
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 23 Nov 2010 22:42:03 +0900
-
-libslp-calendar (0.1.8-48) unstable; urgency=low
-
-  * repeat_end_date bug fix, multi account bug fix
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-48
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 23 Nov 2010 10:55:48 +0900
-
-libslp-calendar (0.1.8-47) unstable; urgency=low
-
-  * doxygen update
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-47
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Fri, 12 Nov 2010 15:56:09 +0900
-
-libslp-calendar (0.1.8-46) unstable; urgency=low
-
-  * doxygen update
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-46
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Fri, 12 Nov 2010 15:22:05 +0900
-
-libslp-calendar (0.1.8-45) unstable; urgency=low
-
-  * sqlite3 add(dependency add)
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-45
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 11 Nov 2010 14:58:20 +0900
-
-libslp-calendar (0.1.8-44) unstable; urgency=low
-
-  * dependency removed
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-44
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 11 Nov 2010 11:53:10 +0900
-
-libslp-calendar (0.1.8-43) unstable; urgency=low
-
-  * recurrence module performance improvement, multi calendar/account implementation
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-43
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Wed, 10 Nov 2010 20:13:06 +0900
-
-libslp-calendar (0.1.8-42) unstable; urgency=low
-
-  * cq b/s issue fixed, log message modification
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-42
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 09 Nov 2010 14:52:54 +0900
-
-libslp-calendar (0.1.8-41) unstable; urgency=low
-
-  * convert time_t -> tm update(for week day)
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-41
-
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 09 Nov 2010 12:41:12 +0900
-
-libslp-calendar (0.1.8-40) unstable; urgency=low
-
-  * pkg update
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-40
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Mon, 08 Nov 2010 14:30:46 +0900
-
-libslp-calendar (0.1.8-39) unstable; urgency=low
-
-  * remove unused code
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-39
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Mon, 08 Nov 2010 14:17:56 +0900
-
-libslp-calendar (0.1.8-38) unstable; urgency=low
-
-  * old api remove
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-38
-
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Mon, 08 Nov 2010 11:33:57 +0900
-
-libslp-calendar (0.1.8-37) unstable; urgency=low
-
-  * add time convert api, fixed time convert error
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-37
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Fri, 05 Nov 2010 09:43:32 +0900
-
-libslp-calendar (0.1.8-36) unstable; urgency=low
-
-  * get updated list error fixed, add status for updated type
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-36
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Fri, 29 Oct 2010 11:40:17 +0900
-
-libslp-calendar (0.1.8-35) unstable; urgency=low
-
-  * attendee update error fix, location error fix
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-35
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 26 Oct 2010 13:45:57 +0900
-
-libslp-calendar (0.1.8-34) unstable; urgency=low
-
-  * sync status error fixed
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-34
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Tue, 26 Oct 2010 09:33:01 +0900
-
-libslp-calendar (0.1.8-33) unstable; urgency=low
-
-  * change param type , bool -> int
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-33
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Fri, 22 Oct 2010 11:09:01 +0900
-
-libslp-calendar (0.1.8-32) unstable; urgency=low
-
-  * package update, timezone api added
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-32
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 21 Oct 2010 14:22:07 +0900
-
-libslp-calendar (0.1.8-31) unstable; urgency=low
-
-  * 2days event error fixed, alarm field error fixed
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-31
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Wed, 20 Oct 2010 11:38:14 +0900
-
-libslp-calendar (0.1.8-30) unstable; urgency=low
-
-  * db owner change(script error fixed)
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-30
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Mon, 18 Oct 2010 14:26:14 +0900
-
-libslp-calendar (0.1.8-29) unstable; urgency=low
-
-  * recurrent util bug fixed
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-29
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Sat, 16 Oct 2010 08:26:01 +0900
-
-libslp-calendar (0.1.8-28) unstable; urgency=low
-
-  * recurrent util bug fixed
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-28
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Sat, 16 Oct 2010 08:16:58 +0900
-
-libslp-calendar (0.1.8-27) unstable; urgency=low
-  * calendar.pc file modification for compile error
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-27
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Fri, 15 Oct 2010 10:17:08 +0900
-
-libslp-calendar (0.1.8-26) unstable; urgency=low
-
-  * support new calendar api, remove old api
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-26
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 14 Oct 2010 14:08:17 +0900
-
-libslp-calendar (0.1.8-14) unstable; urgency=low
-
-  * support new calendar api, remove old api
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-14
-
- -- heungjae jeong <hj98.jeong@samsung.com>  Thu, 14 Oct 2010 14:03:40 +0900
-
-libslp-calendar (0.1.8-13) unstable; urgency=low
-
-  * added exception code in db.c
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-13
-
- -- jeesun kim <iamjs.kim@samsung.com>  Mon, 02 Aug 2010 17:46:23 +0900
-
-libslp-calendar (0.1.8-12) unstable; urgency=low
-
-  * added event_t for sg
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-12
-
- -- jeesun kim <iamjs.kim@samsung.com>  Fri, 30 Jul 2010 14:24:54 +0900
-
-libslp-calendar (0.1.8-11) unstable; urgency=low
-
-  * added new apis
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-11
-
- -- jeesun kim <iamjs.kim@samsung.com>  Fri, 30 Jul 2010 11:32:53 +0900
-
-libslp-calendar (0.1.8-10) unstable; urgency=low
-
-  * modified eventAddDeletedOccur
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-10
-
- -- jeesun kim <iamjs.kim@samsung.com>  Thu, 22 Jul 2010 10:09:24 +0900
-
-libslp-calendar (0.1.8-9) unstable; urgency=low
-
-  * added missing api(eventModLocation)
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-9
-
- -- jeesun kim <iamjs.kim@samsung.com>  Mon, 19 Jul 2010 17:54:50 +0900
-
-libslp-calendar (0.1.8-8) unstable; urgency=low
-
-  * added omitted api
-  * Git: /git/slp/pkgs/libslp-calendar
-  * Tag: libslp-calendar_0.1.8-8
-
- -- jeesun kim <iamjs.kim@samsung.com>  Fri, 16 Jul 2010 10:15:20 +0900
-
-libslp-calendar (0.1.8-7) unstable; urgency=low
-
-  * modified cmake to see internal header calenda.h
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.8-7
-
- -- jeesun kim <iamjs.kim@samsung.com>  Wed, 14 Jul 2010 17:53:18 +0900
-
-libslp-calendar (0.1.8-6) unstable; urgency=low
-
-  * modified comment for doxygen
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.8-6
-
- -- jeesun kim <iamjs.kim@samsung.com>  Wed, 14 Jul 2010 16:20:43 +0900
-
-libslp-calendar (0.1.8-5) unstable; urgency=low
-
-  * moved sglib to c file
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.8-5
-
- -- jeesun kim <iamjs.kim@samsung.com>  Tue, 13 Jul 2010 13:40:23 +0900
-
-libslp-calendar (0.1.8-4) unstable; urgency=low
-
-  * delete sglib define from event header
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.8-4
-
- -- jeesun kim <iamjs.kim@samsung.com>  Tue, 13 Jul 2010 11:01:05 +0900
-
-libslp-calendar (0.1.8-3) unstable; urgency=low
-
-  * modified "_"apis
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.8-3
-
- -- jeesun kim <iamjs.kim@samsung.com>  Tue, 06 Jul 2010 08:39:54 +0900
-
-libslp-calendar (0.1.8-2) unstable; urgency=low
-
-  * modified _* api
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.8-2
-
- -- jeesun kim <iamjs.kim@samsung.com>  Mon, 05 Jul 2010 20:20:37 +0900
-
-libslp-calendar (0.1.8-1) unstable; urgency=low
-
-  * modified dpkg option
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.8-1
-
- -- jeesun kim <iamjs.kim@samsung.com>  Mon, 05 Jul 2010 17:09:57 +0900
-
-libslp-calendar (0.1.2-79) unstable; urgency=low
-
-  * removed warning
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-79
-
- -- jeesun kim <iamjs.kim@samsung.com>  Thu, 24 Jun 2010 15:24:02 +0900
-
-libslp-calendar (0.1.2-78) unstable; urgency=low
-
-  * set hasUntill none 1 instead of zero
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-78
-
- -- Yongjun Wang <yj.wang@samsung.com>  Thu, 17 Jun 2010 13:47:57 +0800
-
-libslp-calendar (0.1.2-77) unstable; urgency=low
-
-  * dac at journal file
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-77
-
- -- jeesun kim <iamjs.kim@samsung.com>  Wed, 16 Jun 2010 10:04:10 +0900
-
-libslp-calendar (0.1.2-76) unstable; urgency=low
-
-  * modified VCal api
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-76
-
- -- jeesun kim <iamjs.kim@samsung.com>  Mon, 31 May 2010 19:44:06 +0900
-
-libslp-calendar (0.1.2-75) unstable; urgency=low
-
-  * fix the bug that synced calendar events can't be showed in month view
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-75
-
- -- Yongjun Wang <yj.wang@samsung.com>  Wed, 26 May 2010 15:42:43 +0800
-
-libslp-calendar (0.1.2-74) unstable; urgency=low
-
-  * fix the bug about calendar sync
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-74
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Sun, 23 May 2010 10:34:46 +0900
-
-libslp-calendar (0.1.2-73) unstable; urgency=low
-
-  * fix the bug about calendar sync
-
- -- Yongjun Wang <yj.wang@samsung.com>  Fri, 21 May 2010 10:55:28 +0800
-
-libslp-calendar (0.1.2-72) unstable; urgency=low
-
-  * fix the bug about birthday event sync
-
- -- Yongjun Wang <yj.wang@samsung.com>  Fri, 21 May 2010 10:33:31 +0800
-
-libslp-calendar (0.1.2-71) unstable; urgency=low
-
-  * fix the bug of repeat end date
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Fri, 21 May 2010 09:56:56 +0800
-
-libslp-calendar (0.1.2-70) unstable; urgency=low
-
-  * fix the bug about unitll date
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 19 May 2010 10:54:58 +0800
-
-libslp-calendar (0.1.2-69) unstable; urgency=low
-
-  * fix bug about untill date
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-69
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 13 May 2010 16:53:16 +0800
-
-libslp-calendar (0.1.2-68) unstable; urgency=low
-
-  * fix vcalendar bug
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-68
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 12 May 2010 21:39:11 +0900
-
-libslp-calendar (0.1.2-67) unstable; urgency=low
-
-  * revise calendar recurrence API
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-67
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 12 May 2010 08:32:52 +0900
-
-libslp-calendar (0.1.2-66) unstable; urgency=low
-
-  * revise calendar recurrence API
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Mon, 10 May 2010 17:46:46 +0800
-
-libslp-calendar (0.1.2-65) unstable; urgency=low
-
-  * fix the bug about vcalendar recurrence
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-65
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 06 May 2010 09:36:12 +0900
-
-libslp-calendar (0.1.2-64) unstable; urgency=low
-
-  * fix the bug that list view cannot show all the events
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-64
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 28 Apr 2010 20:01:11 +0900
-
-libslp-calendar (0.1.2-63) unstable; urgency=low
-
-  * update changelog
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-63
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Tue, 27 Apr 2010 07:59:59 +0900
-
-libslp-calendar (0.1.2-62) unstable; urgency=low
-
-  * fix bug of vcalendar_convert_vfile_to_record API
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-62
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Sat, 24 Apr 2010 10:16:45 +0900
-
-libslp-calendar (0.1.2-61) unstable; urgency=low
-
-  * vCalendar support X-FUNAMBOL-ALLDAY
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-61
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Mon, 19 Apr 2010 14:50:09 +0800
-
-libslp-calendar (0.1.2-60) unstable; urgency=low
-
-  * support Deleteing Repeat events
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar_0.1.2-60
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Sun, 18 Apr 2010 09:46:30 +0900
-
-libslp-calendar (0.1.2-59) unstable; urgency=low
-
-  * support Deleteing Repeat events
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar-0_0.1.2-59
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Sun, 18 Apr 2010 09:29:35 +0900
-
-libslp-calendar (0.1.2-58) unstable; urgency=low
-
-  * support Deleteing Repeat events
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Tue, 13 Apr 2010 14:33:07 +0800
-
-libslp-calendar (0.1.2-57) unstable; urgency=low
-
-  * support RRULE for vCalendar 1.0
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Mon, 12 Apr 2010 15:50:14 +0800
-
-libslp-calendar (0.1.2-56) unstable; urgency=low
-
-  * fix vCalendar bugs when event type is anniversary
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar-0_0.1.2-56
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Tue, 06 Apr 2010 15:13:42 +0800
-
-libslp-calendar (0.1.2-55) unstable; urgency=low
-
-  * add get day list function
-  * Git: /git/slp2.0/slp2.0-pkgs/libslp-calendar-0
-  * Tag: libslp-calendar-0_0.1.2-55
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Mon, 05 Apr 2010 21:17:06 +0900
-
-libslp-calendar (0.1.2-54) unstable; urgency=low
-
-  * add monthly recurrence check
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Tue, 30 Mar 2010 18:02:53 +0900
-
-libslp-calendar (0.1.2-53) unstable; urgency=low
-
-  * fix recurrece API bugs
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 25 Mar 2010 10:16:14 +0800
-
-libslp-calendar (0.1.2-52) unstable; urgency=low
-
-  * exception handle for vcalendar attendee
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 24 Mar 2010 10:40:58 +0800
-
-libslp-calendar (0.1.2-51) unstable; urgency=low
-
-  * modify calendar_get_data_by_alarmId and eventModDescription
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Fri, 19 Mar 2010 19:37:12 +0900
-
-libslp-calendar (0.1.2-50) unstable; urgency=low
-
-  * add globalMeetingId field in exception event table
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 18 Mar 2010 13:54:16 +0900
-
-libslp-calendar (0.1.2-49) unstable; urgency=low
-
-  * reflect modified sync_db APIs
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Mon, 15 Mar 2010 19:48:16 +0900
-
-libslp-calendar (0.1.2-48) unstable; urgency=low
-
-  * modify value of event category in calendar-engine's header
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 11 Mar 2010 18:01:13 +0900
-
-libslp-calendar (0.1.2-47) unstable; urgency=low
-
-  * fix the bug of eventAddException and _s API
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 11 Mar 2010 10:57:12 +0900
-
-libslp-calendar (0.1.2-46) unstable; urgency=low
-
-  * add calendar_insert_data_for_test_by_category API
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Tue, 09 Mar 2010 17:22:05 +0900
-
-libslp-calendar (0.1.2-45) unstable; urgency=low
-
-  * add calendar_get_all_data_list_by_category API
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Tue, 09 Mar 2010 16:02:57 +0900
-
-libslp-calendar (0.1.2-44) unstable; urgency=low
-
-  * add exception handling before using strdup
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Mon, 08 Mar 2010 10:16:07 +0900
-
-libslp-calendar (0.1.2-43) unstable; urgency=low
-
-  * add some APIs for "change calendar"
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 03 Mar 2010 19:54:49 +0900
-
-libslp-calendar (0.1.2-42) unstable; urgency=low
-
-  * change vcalendar file path to "/opt/share"
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 25 Feb 2010 08:48:04 +0900
-
-libslp-calendar (0.1.2-41) unstable; urgency=low
-
-  * change vcalendar file path to /opt/share/vcs"
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Tue, 23 Feb 2010 15:14:12 +0800
-
-libslp-calendar (0.1.2-40) unstable; urgency=low
-
-  * fix the defects about vcalendar file name duplicated
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Mon, 22 Feb 2010 16:54:04 +0800
-
-libslp-calendar (0.1.2-39) unstable; urgency=low
-
-  * apply sync-db for interacting with syncml
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Mon, 22 Feb 2010 14:46:26 +0900
-
-libslp-calendar (0.1.2-38) unstable; urgency=low
-
-  * add new include directory for calendar-engine-include-dev
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Mon, 22 Feb 2010 11:19:31 +0900
-
-libslp-calendar (0.1.2-37) unstable; urgency=low
-
-  * generate initial DB file in /opt/dbspace
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Fri, 19 Feb 2010 09:21:35 +0900
-
-libslp-calendar (0.1.2-36) unstable; urgency=low
-
-  * add calendar_insert_data_for_test API for DB test in process
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 18 Feb 2010 17:36:19 +0900
-
-libslp-calendar (0.1.2-35) unstable; urgency=low
-
-  * add completionDate field in event structure for task
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 18 Feb 2010 09:07:34 +0900
-
-libslp-calendar (0.1.2-34) unstable; urgency=low
-
-  * fix the bug(eventSetIsAllDayEvent)
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 17 Feb 2010 09:31:40 +0900
-
-libslp-calendar (0.1.2-33) unstable; urgency=low
-
-  * add isComplete field in Event
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Tue, 09 Feb 2010 12:14:23 +0900
-
-libslp-calendar (0.1.2-32) unstable; urgency=low
-
-  * add calendar_get_data_counts_by_category API
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Mon, 08 Feb 2010 19:53:32 +0900
-
-libslp-calendar (0.1.2-31) unstable; urgency=low
-
-  * add dbg-package
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Sat, 06 Feb 2010 17:03:59 +0900
-
-libslp-calendar (0.1.2-30) unstable; urgency=low
-
-  * fix the bug(calendar_free_all_data API) and apply autoincrement to primary key
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 04 Feb 2010 22:26:55 +0900
-
-libslp-calendar (0.1.2-29) unstable; urgency=low
-
-  * remove dummy node in linked-list
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 03 Feb 2010 23:37:42 +0900
-
-libslp-calendar (0.1.2-28) unstable; urgency=low
-
-  * fix the bug(calendar_update_data API)
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 03 Feb 2010 18:11:30 +0900
-
-libslp-calendar (0.1.2-27) unstable; urgency=low
-
-  * fix the bug(calendar_update_data API)
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 03 Feb 2010 18:05:54 +0900
-
-libslp-calendar (0.1.2-26) unstable; urgency=low
-
-  * add alarm id field to event table for alarm ring
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 03 Feb 2010 15:47:23 +0900
-
-libslp-calendar (0.1.2-25) unstable; urgency=low
-
-  * modify eventAddxxx() APIs and calendar_free_data API
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 03 Feb 2010 14:29:53 +0900
-
-libslp-calendar (0.1.2-24) unstable; urgency=low
-
-  * fix the bug(calendar_insert_data API)
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Tue, 02 Feb 2010 20:43:42 +0900
-
-libslp-calendar (0.1.2-23) unstable; urgency=low
-
-  * fix the bug(eventSetTimeZone API)
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Sun, 31 Jan 2010 14:17:00 +0900
-
-libslp-calendar (0.1.2-22) unstable; urgency=low
-
-  * reupload pkg because of build machine's problem
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Fri, 29 Jan 2010 20:01:34 +0900
-
-libslp-calendar (0.1.2-21) unstable; urgency=low
-
-  * add eventRemoveAllxxx APIs
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Fri, 29 Jan 2010 14:47:42 +0900
-
-libslp-calendar (0.1.2-20) unstable; urgency=low
-
-  * add notification API using dbus
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Fri, 29 Jan 2010 10:03:06 +0900
-
-libslp-calendar (0.1.2-19) unstable; urgency=low
-
-  * modify enum AttendeeStatus
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 28 Jan 2010 14:16:38 +0900
-
-libslp-calendar (0.1.2-18) unstable; urgency=low
-
-  * add removing string API(eventRemovexxx())
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 28 Jan 2010 10:22:41 +0900
-
-libslp-calendar (0.1.2-17) unstable; urgency=low
-
-  * modify calendar event API
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 27 Jan 2010 20:30:56 +0900
-
-libslp-calendar (0.1.2-16) unstable; urgency=low
-
-  * modify data structure of RecurDateList and DeletedOccurList
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 27 Jan 2010 14:09:17 +0900
-
-libslp-calendar (0.1.2-15) unstable; urgency=low
-
-  * remove prefix "SLP"
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Wed, 27 Jan 2010 13:31:38 +0900
-
-libslp-calendar (0.1.2-14) unstable; urgency=low
-
-  * add SLP_calendar_get_range_data_list_by_time API
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Tue, 26 Jan 2010 17:49:45 +0900
-
-libslp-calendar (0.1.2-13) unstable; urgency=low
-
-  * reinsert old data structure
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Tue, 26 Jan 2010 10:29:54 +0900
-
-libslp-calendar (0.1.2-12) unstable; urgency=low
-
-  * add doxygen
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Mon, 25 Jan 2010 22:36:46 +0900
-
-libslp-calendar (0.1.2-11) unstable; urgency=low
-
-  * add eventSetAttendeeList API
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Mon, 25 Jan 2010 13:53:42 +0900
-
-libslp-calendar (0.1.2-10) unstable; urgency=low
-
-  * add vcalendar APIs
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Sat, 23 Jan 2010 21:05:09 +0800
-
-libslp-calendar (0.1.2-9) unstable; urgency=low
-
-  * modify data structure and API for interacting with SEVEN
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Fri, 22 Jan 2010 23:27:15 +0900
-
-libslp-calendar (0.1.2-8) unstable; urgency=low
-
-  * use libslp-db-util-dev
-
- -- Sangjung Woo <sangjung.woo@samsung.com>  Thu, 21 Jan 2010 09:09:25 +0900
-
-libslp-calendar (0.1.2-7) unstable; urgency=low
-
-  * change location of database(from /root to /opt/dbspace)
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 14 Jan 2010 09:06:31 +0900
-
-libslp-calendar (0.1.2-6) unstable; urgency=low
-
-  * modify for interaction with SEVEN
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Tue, 05 Jan 2010 14:58:53 +0900
-
-libslp-calendar (0.1.2-5) unstable; urgency=low
-
-  * fix the bug (H0100075687)
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Fri, 01 Jan 2010 13:39:38 +0900
-
-libslp-calendar (0.1.2-4) unstable; urgency=low
-
-  * remove SLP_alarm feature
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 24 Dec 2009 11:09:26 +0900
-
-libslp-calendar (0.1.2-3) unstable; urgency=low
-
-  * modify structure of source tree
-
- -- Deokjin Kim <deokjin81.kim@samsung.com>  Thu, 10 Dec 2009 17:35:35 +0900
-
-libslp-calendar (0.1.2-2) unstable; urgency=low
-
-  * fix
-
- -- Jihoon Kim <jihoon48.kim@samsung.com>  Fri, 20 Nov 2009 21:04:40 +0900
-
-libslp-calendar (0.1.2-1) unstable; urgency=low
-
-  * fix installing pkgconfi
-
- -- Jihoon Kim <jihoon48.kim@samsung.com>  Fri, 20 Nov 2009 20:47:46 +0900
-
-libslp-calendar (0.1.2) unstable; urgency=low
-
-  * change control file
-
- -- Jihoon Kim <jihoon48.kim@samsung.com>  Fri, 20 Nov 2009 19:50:13 +0900
-
-libx1-calendar (0.1.1) unstable; urgency=low
-
-  * rename X1 -> SLP
-
- -- Jihoon Kim <jihoon48.kim@samsung.com>  Fri, 20 Nov 2009 19:27:38 +0900
-
-libx1-calendar (0.1.0) unstable; urgency=low
-
-  * Initial Release.
-
- -- Jihoon Kim <jihoon48.kim@samsung.com>  Mon, 16 Nov 2009 15:40:49 +0900
diff --git a/debian/compat b/debian/compat
deleted file mode 100644 (file)
index 7ed6ff8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-5
diff --git a/debian/control b/debian/control
deleted file mode 100644 (file)
index 166450f..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-Source: libslp-calendar
-Section: devel
-Priority: extra
-Maintainer: Youngjae Shin <yj99.shin@samsung.com> , Sunghyuk Lee <sunghyuk.lee@samsung.com>, Jeesun Kim <iamjs.kim@samsung.com>
-Build-Depends: debhelper (>= 5), libslp-db-util-dev, libsqlite3-dev, libglib2.0-dev, dlog-dev, libvconf-dev, libvconf-keys-dev, libalarm-dev, libicu-dev, libappsvc-dev
-Standards-Version: 3.7.2
-
-Package: libslp-calendar-dev
-Section: devel
-Architecture: any
-Depends: libslp-calendar-0 (= ${Source-Version}), libglib2.0-dev, libalarm-dev
-Description: calendar service Library (development)
-
-Package: libslp-calendar-0
-Section: libs
-Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}
-Description: calendar service Library (Library)
-
-Package: libslp-calendar-dbg
-Section: debug
-Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}, libslp-calendar-0 (= ${Source-Version})
-Description: calendar service Library (unstripped)
-
diff --git a/debian/copyright b/debian/copyright
deleted file mode 100644 (file)
index 4f93c69..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the Apache License version 2.0.
-
-The full text of the Apache 2.0 can be found in
-/usr/share/common-licenses.
diff --git a/debian/dirs b/debian/dirs
deleted file mode 100644 (file)
index ca882bb..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-usr/bin
-usr/sbin
diff --git a/debian/docs b/debian/docs
deleted file mode 100644 (file)
index a0f0008..0000000
+++ /dev/null
@@ -1 +0,0 @@
-CMakeLists.txt
diff --git a/debian/libslp-calendar-0.install.in b/debian/libslp-calendar-0.install.in
deleted file mode 100644 (file)
index f5ec216..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-@PREFIX@/lib/*.so.*
-@PREFIX@/bin/calendar-svc-initdb
-/opt/*
diff --git a/debian/libslp-calendar-0.postinst b/debian/libslp-calendar-0.postinst
deleted file mode 100644 (file)
index 26f0e0d..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-
-if [ ! -d /opt/dbspace ]
-then
-       mkdir -p /opt/dbspace
-fi
-
-calendar-svc-initdb
-
-if [ "$USER" = "root" ]
-then
-       chown root:root /usr/lib/libcalendar-service.so.*
-       chown :6003 /opt/data/calendar-svc/.CALENDAR_SVC_*
-       chown :6003 /opt/dbspace/.calendar-svc.db
-       chown :6003 /opt/dbspace/.calendar-svc.db-journal
-       vconftool set -t int db/calendar/timezone_on_off 0 -g 6003
-       vconftool set -t string db/calendar/timezone_path "Asia/Seoul" -g 6003
-fi
-
-chmod 660 /opt/dbspace/.calendar-svc.db
-chmod 660 /opt/dbspace/.calendar-svc.db-journal
-chmod 660 /opt/data/calendar-svc/.CALENDAR_SVC_*
-
-echo "Done"
diff --git a/debian/libslp-calendar-dev.install.in b/debian/libslp-calendar-dev.install.in
deleted file mode 100644 (file)
index 690c8d5..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-@PREFIX@/lib/*.so
-@PREFIX@/include/calendar-svc/*.h
-@PREFIX@/include/calendar/*.h
-@PREFIX@/lib/pkgconfig/calendar-service.pc
-@PREFIX@/lib/pkgconfig/calendar.pc
diff --git a/debian/rules b/debian/rules
deleted file mode 100755 (executable)
index eefc51d..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-#!/usr/bin/make -f
-# -*- makefile -*-
-# Sample debian/rules that uses debhelper.
-# This file was originally written by Joey Hess and Craig Small.
-# As a special exception, when this file is copied by dh-make into a
-# dh-make output file, you may use that output file without restriction.
-# This special exception was added by Craig Small in version 0.37 of dh-make.
-
-# Uncomment this to turn on verbose mode.
-#export DH_VERBOSE=1
-
-CFLAGS += -Wall
-LDFLAGS ?=
-PREFIX ?= /usr
-DATADIR ?= /opt
-
-ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
-       CFLAGS += -O0
-else
-       CFLAGS += -O2
-endif
-
-LDFLAGS += -Wl,--hash-style=both -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed
-
-configure: configure-stamp
-configure-stamp:
-       dh_testdir
-       # Add here commands to configure the package.
-       CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" cmake . -DCMAKE_INSTALL_PREFIX=$(PREFIX)
-
-       touch configure-stamp
-
-build: build-stamp
-
-build-stamp: configure-stamp
-       dh_testdir
-
-       # Add here commands to compile the package.
-       $(MAKE)
-
-       for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
-               cat $$f > $${f%.in}; \
-               sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \
-               sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \
-       done
-
-
-       touch $@
-
-clean:
-       dh_testdir
-       dh_testroot
-       rm -f build-stamp configure-stamp
-
-       # Add here commands to clean up after the build process.
-       -$(MAKE) clean
-       rm -rf CMakeCache.txt CMakeFiles cmake_install.cmake Makefile install_manifest.txt
-       cd schema; rm -rf CMakeCache.txt CMakeFiles cmake_install.cmake Makefile install_manifest.txt
-
-       for f in `find $(CURDIR)/debian/ -name "*.in"`; do \
-               rm -f $${f%.in}; \
-       done
-
-       dh_clean
-
-install: build
-       dh_testdir
-       dh_testroot
-       dh_prep
-       dh_installdirs
-
-       # Add here commands to install the package.
-       $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install
-
-
-# Build architecture-independent files here.
-binary-indep: build install
-# We have nothing to do by default.
-
-# Build architecture-dependent files here.
-binary-arch: build install
-       dh_testdir
-       dh_testroot
-#      dh_installchangelogs
-#      dh_installdocs
-       dh_installexamples
-       dh_install --sourcedir=debian/tmp
-#      dh_installmenu
-#      dh_installdebconf
-#      dh_installlogrotate
-#      dh_installemacsen
-#      dh_installpam
-#      dh_installmime
-#      dh_python
-#      dh_installinit
-#      dh_installcron
-#      dh_installinfo
-       dh_installman
-       dh_link
-       dh_strip --dbg-package=libslp-calendar-dbg
-       dh_compress
-       dh_fixperms
-#      dh_perl
-       dh_makeshlibs
-       dh_installdeb
-       dh_shlibdeps
-       dh_gencontrol
-       dh_md5sums
-       dh_builddeb
-
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install configure
diff --git a/doc/calendar_doc.h b/doc/calendar_doc.h
new file mode 100644 (file)
index 0000000..e21bcc5
--- /dev/null
@@ -0,0 +1,1177 @@
+/**
+ * @ingroup CAPI_SOCIAL_FRAMEWORK
+ * @defgroup CAPI_SOCIAL_CALENDAR_SVC_MODULE Calendar
+ *
+ * @brief The Calendar Service API provides functions for managing calendars(including events, to-dos).
+ * This API allows you not only to store information about calendar but also to query calendar information.
+ *
+ * @section CAPI_SOCIAL_CALENDARS_SVC_MODULE_HEADER Required Header
+ *  \#include <calendar.h>
+ *
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_MODULE_OVERVIEW Overview
+ * A calendar is a system of organizing days for social purposes and is composed of records like events and todos.
+ * These records are made up of another sub records like alarms, attendees or extended ones.
+ * Events could have recurrence rule, instances would be generated.
+ * @image html calendar_model.png "Figure: Calendar model"
+ *
+ * The Calendar-Service provides an interface to manage the information of records.
+ * <table>
+ * <caption> Table: Calendar service properties. </caption>
+ *     <tr>
+ *             <td>
+ *             * Managing information stored in database. <br>
+ *             * Aggregating information from various accounts. <br>
+ *             * Notifying changes of information. <br>
+ *             * Searching information. <br>
+ *             * Vcalendar  supports ver1.0(vcs) / 2.0(ics).
+ *             </td>
+ *     </tr>
+ * </table>
+ *
+ * Calendar service module works in a way similar to client-service architecture.
+ * In this architecture Tizen application is a client side and has to connect to service before using calendar service APIs.
+ * Connection/disconnection MUST be done with use of calendar_connect() / calendar_disconnect().
+ *
+ * @code
+ * calendar_connect();
+ *
+ * // jobs for records
+ *
+ * calendar_disconnect(); *
+ * @endcode
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_MODULE_Entities Entities
+ * Calendar service manages information related to following entities.
+ * - Calendar books
+ *    - Represents where event and todo should belong to.
+ *    - Created by one of calendars sources below
+ *       -# Local device, which has no account.
+ *       -# Service providers such as Google or Yahoo, with account.
+ *       -# Applications like ChatON, Joyn, Facebook, etc.
+ *    - Have properties like name, account id, color.
+ * - Events
+ *    - Have properties like summary, start_time, description.
+ *    - Single entry can be available on each calendar book.
+ * - Todos
+ *    - Similar with event entry.
+ *
+ * @subsection CAPI_SOCIAL_CALENDAR_SVC_MODULE_Entities_Relationship_between_entities Relationship between entities
+ * @image html entities.png "Figure: Relationship between entities"
+ *
+ * @subsection CAPI_SOCIAL_CALENDAR_SVC_MODULE_Entities_Multiple_Address_books_from_Accounts Multiple Address books from Accounts
+ * Each account can create multiple calendar books. Calendar book name does not need to be unique on the device because it is handled with id.
+ * Local device address book has no account and its related account id is zero.
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_MODULE_Views Views
+ * \ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE
+ * To access and handle entities, views are provided. <br>
+ * According to data-view declarations, generic access functions are used (calendar_db_insert_record(), calendar_record_get_int(), …). <br>
+ * Data-View is almost same as database "VIEW" which limits access and guarantees the performance by offering various views for the proper purpose.
+ *
+ * _calendar_instance_utime, _calendar_instance_localtime views are not offered but combination with another view are provided.
+ *
+ * <table>
+ * <caption> Table: Calendar views </caption>
+ * <tr>
+ *     <th> Editable view </th>
+ *     <th> Read only view </th>
+ * </tr>
+ * <tr>
+ *     <td>
+ *             _calendar_book <br>
+ *             _calendar_event <br>
+ *             _calendar_todo <br>
+ *             _calendar_timezone <br>
+ *             _calendar_attendee <br>
+ *             _calendar_alarm <br>
+ *             _calendar_extended_property
+ *     </td>
+ *     <td>
+ *             _calendar_updated_info <br>
+ *             _calendar_event_calendar_book <br>
+ *             _calendar_todo_calendar_book <br>
+ *             _calendar_event_calendar_book_attendee <br>
+ *             _calendar_instance_utime_calendar_book <br>
+ *             _calendar_instance_localtime_calendar_book <br>
+ *             _calendar_instance_utime_calendar_book_extended <br>
+ *             _calendar_instance_localtime_calendar_book_extended
+
+ *     </td>
+ * </tr>
+ * </table>
+ *
+ *
+ * _calendar_updated_info is used when identifying record changes depending on version.
+ *
+ * The other read only views are combination of editable views for UI convenience. <br>
+ * _calendar_event + _calendar_book = _calendar_event_calendar_book <br>
+ * _calendar_instance_utime + _calendar_book = _calendar_instance_utime_calendar_book <br>
+ * _calendar_event + _calendar_book + _calendar_attendee = _calendar_event_calendar_book_attendee <br>
+ *
+ *
+ * @subsection CAPI_SOCIAL_CALENDAR_SVC_MODULE_Views_Properties Properties
+ * Record types which have *_id as their properties, hold identifiers of other records - e.g. attendee and alarm views hold id of their corresponding events or to-dos in event_id or todo_id property respectively (as children of the corresponding events or to-dos record).
+ * Properties of type 'record' are other records. For example, a event record has 'attendee' and 'alarm', which means that records of those types can be children of event type records.
+ *
+ * In calendar_view.h header file, view macros are found and below figure. show what macro means.
+ * @image html view_property.png "Figure: Properties"
+ *
+ * There is an example how to create event with view.
+ *
+ * @code
+ * // create an event with _calendar_event view.
+ * calendar_record_h event = NULL;
+ * calendar_record_create(_calendar_event._uri, &event);
+ *
+ * // set event summary to _calendar_event view.
+ * calendar_record_set_str(event, _calendar_event.summary, "Meeting");
+ * @endcode
+ *
+ * @subsection CAPI_SOCIAL_CALENDAR_SVC_MODULE_Views_Version Version
+ *
+ * Calendar service uses version system in bellow APIs.
+ *
+ * <table>
+ * <caption> Table: Version related APIs </caption>
+ * <tr>
+ *  <td>
+ * calendar_db_get_current_version(int* calendar_db_version) <br>
+ * calendar_db_get_changes_by_version(const char *view_uri, int calendar_book_id, int calendar_db_version, calendar_list_h *record_list, int *current_calendar_db_version) <br>
+ * calendar_db_get_last_change_version(int* last_change_version) <br>
+ * calendar_db_get_changes_exception_by_version(const char *view_uri, int original_event_id, int calendar_db_version, calendar_list_h *list)
+ *  </td>
+ * </tr>
+ * </table>
+ *
+ * Whenever modifications are in DB, version number is increased every time. <br>
+ * If sync applications like google, facebook sync at version 13 and they try to sync again every 1 minute, they want to get changes from version 14 to current version. <br>
+ * To get current version, calendar_db_get_current_version() is used and calendar_db_get_changes_by_version() is used to get the modified record list. calendar_db_get_changes_exception_by_version() is used to get modified instances in recurring event.
+ * (see exception in Events and instances)
+ *
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_MODULE_Records Records
+ * An important concept in Calendar service APIs is a record.
+ * It may be helpful to know that a record represents an actual record in the internal database, but in general, you can think of a record as a structure describing a single (but complex) view, like a calendar event or a time zone.
+ *
+ * A record has many properties, for example, a to-do record has the to-do's description, priority, progress, created, last modified and completed time, plus many others. <br>
+ * A record can also contain an identifier field, which holds an identifier of another record. Setting this field's value establishes a relation between the records, for example, a calendar event contains the identifier of a calendar book to which it belongs.
+ *
+ * @subsection CAPI_SOCIAL_CALENDAR_SVC_MODULE_Records_URI URI
+ *
+ * A record's type is identified by a structure called the view.
+ * For example, the _calendar_event view describes the properties of the calendar event record.
+ * Every view has a special field - _uri - that uniquely identifies the view.
+ * In many cases you will need to provide the _uri value to indicate what type of record you wish to create or operate on.
+ * @code
+ * // create an event and get handle
+ * calendar_record_h event = NULL;
+ * calendar_record_create(_calendar_event._uri, &event);
+ * @endcode
+ *
+ * @subsection CAPI_SOCIAL_CALENDAR_SVC_MODULE_Records_Record_handle Record handle
+ *
+ * To use a record, you must obtain its handle.
+ * There are many ways to obtains it, including creating a new record and referring to child records of a record.
+ * @code
+ * // create an event and get handle
+ * calendar_record_h event = NULL;
+ * calendar_record_create(_calendar_event._uri, &event);
+ *
+ * // get record handle with id
+ * calendar_record_h event2 = NULL
+ * calendar_db_get_record(_calendar_event._uri, event_id, &event2);
+ * @endcode
+ *
+ * @subsection CAPI_SOCIAL_CALENDAR_SVC_MODULE_Records_Basic_types Basic types
+ *
+ * Records contain properties of basic types: integer, lli (long integer, long long int), double,
+ * string and calendar_time_s.<br>
+ * The calendar_time_s type holds either a long long int, or three integers (year, month, day).
+ * There are setter and getter functions for each type:
+ *
+ * <table>
+ * <caption> Table: Setter and getter functions </caption>
+ * <tr>
+ *     <th> Property </th>
+ *     <th> Setter </th>
+ *     <th> Getter </th>
+ * </tr>
+ * <tr>
+ *     <td> integer </td>
+ *     <td> calendar_record_set_int </td>
+ *     <td> calendar_record_get_int </td>
+ * </tr>
+ * <tr>
+ *     <td> long long integer </td>
+ *     <td> calendar_record_set_lli </td>
+ *     <td> calendar_record_get_lli </td>
+ * </tr>
+ * <tr>
+ *     <td> double </td>
+ *     <td> calendar_record_set_double </td>
+ *     <td> calendar_record_get_double </td>
+ * </tr>
+ * <tr>
+ *     <td> string </td>
+ *     <td> calendar_record_set_str </td>
+ *     <td> calendar_record_get_str </td>
+ * </tr>
+ * <tr>
+ *     <td> calendar_time_s </td>
+ *     <td> calendar_record_set_caltime </td>
+ *     <td> calendar_record_get_caltime </td>
+ * </tr>
+ * </table>
+ *
+ * A record's type is identified by a structure called the view. For example,
+ * the _calendar_event view describes the properties of the calendar event record.
+ * Every view has a special field - _uri - that uniquely identifies the view.
+ * In many cases you will need to provide the _uri value to indicate what
+ * type of record you wish to create or operate on.
+ *
+ * @subsection CAPI_SOCIAL_CALENDAR_SVC_MODULE_Records_Child Child
+ *
+ * Records of certain type also hold 'child list' properties.
+ * If a record has property of this type, it can be a parent of other records, called child records.
+ * For example, attendee records can hold an event's identifier in their event_id property.
+ * The event is the parent record of the child attendee records.
+ *
+ * To use a record, you must obtain its handle. There are many ways to obtains it,
+ * including creating a new record and referring to child records of a record.
+ *
+ * Sample code:<br>
+ * the code below creates an event and inserts it into default event book
+ * (see below on calendar books).
+ *
+ * @code
+ * // create an event
+ * calendar_record_h event;
+ * calendar_record_create(_calendar_event._uri, &event);
+ *
+ * // set event summary
+ * calendar_record_set_str(event, _calendar_event.summary, "Meeting");
+ *
+ * // put the event into the default calendar book for events
+ * calendar_record_set_int(event, _calendar_event.calendar_book_id, book_id);
+ *
+ * // add alarm as child
+ * calendar_record_h alarm = NULL;
+ * calendar_record_create(_calendar_alarm._uri, &alarm);
+ * calendar_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_MINUTE);
+ * calendar_record_set_int(alarm, _calendar_alarm.tick, 5);
+ * calendar_record_add_child_record(event, _calendar_event.calendar_alarm, alarm);
+ *
+ * // insert calendar book into the database
+ * int event_id = 0;
+ * calendar_db_insert_record(event, &event_id);
+ *
+ * // destroy
+ * calendar_record_destroy(event, true);
+ * @endcode
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_MODULE_Calendar_books Calendar Books
+ * A calendar book is a placeholder for other records in Calendar API.
+ * Every event and to-do has to belong to a calendar book.
+ * There are three built-in calendar books.
+ * <table>
+ * <caption> Table: Calendar books </caption>
+ * <tr>
+ *  <td> DEFAULT_EVENT_CALENDAR_BOOK_ID </td>
+ *  <td> Event book </td>
+ * </tr>
+ * <tr>
+ *  <td> DEFAULT_TODO_CALENDAR_BOOK_ID </td>
+ *  <td> Todo book </td>
+ * </tr>
+ * <tr>
+ *  <td> DEFAULT_BIRTHDAY_CALENDAR_BOOK_ID </td>
+ *  <td> Birthday book </td>
+ * </tr>
+ * </table>
+ *
+ * There is an example how calendar book id is set.
+ *
+ * @code
+ * calendar_record_h event = NULL;
+ *
+ * calendar_record_create(_calendar_event._uri, &event);
+ *
+ * // set default calendar book id
+ * calendar_record_set_int(event, _calendar_event.calendar_id, DEFAULT_EVENT_CALENDAR_BOOK_ID);
+ *
+ * // set other fields
+ *
+ * int event_id = 0;
+ * calendar_db_insert_record(event &event_id);
+ *
+ * // destroy
+ * calendar_record_destroy(event, true);
+ * @endcode
+ *
+ * To receive a list of existing calendar books, use the following:
+ *
+ * @code
+ * calendar_list_h calendar_book_list = NULL;
+ * calendar_db_get_all_records(_calendar_calendar_book._uri, 0, 0, &calendar_book_list);
+ * @endcode
+ *
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_MODULE_Events_and_instances Events and Instances
+ * Two important concepts are event and instance. An event record describes
+ * various properties of the event, like description, categories, priority
+ * and many others. It also contains information on when the event takes place,
+ * there can be more than one instance of the event. Each instance has its
+ * corresponding instance record. <br>
+ * If event is inserted with rrule, alarm and attendee, its data is saved to each database.
+ * Generated instances based on rrule are also stored in instance database.
+ * @image html view_db.png "Figure: Views and databases"
+ *
+ * For example, if an event has the following properties:
+ * <table>
+ * <caption> Table: Event and instance example </caption>
+ * <tr>
+ *     <th> event </th>
+ *     <th> instances </th>
+ * </tr>
+ * <tr>
+ *     <td>
+ *             start date on 2012-10-09 (Tuesday) <br>
+ *             frequency set to 'WEEKLY' <br>
+ *             interval set to 1 <br>
+ *             count set to 3
+ * </td>
+ *     <td>
+ *             2012-10-09 Tuesday <br>
+ *             2012-10-16 Tuesday <br>
+ *             2012-10-23 Tuesday
+ *     </td>
+ * </tr>
+ * </table>
+ *
+ * Interval is a multiplier of frequency, which means that if it is set to N,
+ * instances occur every N weeks (or whatever was set in frequency attribute).
+ *
+ * The recurrence model in Calendar API is compliant with iCalendar specification
+ * (<a href="http://www.ietf.org/rfc/rfc2445.txt">www.ietf.org/rfc/rfc2445.txt</a>).
+ * The following event properties have the same functionality as their corresponding
+ * values in iCalendar:
+ *
+ * <table>
+ * <caption> Table: Recurrence rules. </caption>
+ * <tr>
+ *     <th> Recurrence rule property </th>
+ *     <th> comment </th>
+ * </tr>
+ * <tr>
+ *     <td> freq </td>
+ *     <td> Yearly, monthly, weekly, daily </td>
+ * </tr>
+ * <tr>
+ *     <td> count </td>
+ *     <td> Until count. If count is 3, 3 instances are generated </td>
+ * </tr>
+ * <tr>
+ *     <td> interval </td>
+ *     <td> The interval is positive integer representing how often the recurrence rule repeats </td>
+ * </tr>
+ * <tr>
+ *     <td> byday </td>
+ *     <td> MO, TU, WE, TH, FR, SA, SU </td>
+ * </tr>
+ * <tr>
+ *     <td> bymonthday </td>
+ *     <td> Days of month </td>
+ * </tr>
+ * <tr>
+ *     <td> byyearday </td>
+ *     <td> Days of year </td>
+ * </tr>
+ * <tr>
+ *     <td> byweekno </td>
+ *     <td> Ordinals specifying weeks of the year </td>
+ * </tr>
+ * <tr>
+ *     <td> bymonth </td>
+ *     <td> Months of year </td>
+ * </tr>
+ * <tr>
+ *     <td> bysetpos </td>
+ *     <td> Values which corresponds to the nth occurrence within the set of events </td>
+ * </tr>
+ * <tr>
+ *     <td> wkst </td>
+ *     <td> The day on which the workweek starts </td>
+ * </tr>
+ * </table>
+ *
+ * @subsection CAPI_SOCIAL_CALENDAR_SVC_MODULE_Events_and_instances_Exceptions Exceptions
+ *
+ * If one of instances is modified in summary, date… or deleted, this is called exception.<br>
+ * For example, if 2nd instance date is modified from 16th to 17th, 17th is the exception.
+ * <table>
+ * <caption> Table: Exception example </caption>
+ * <tr>
+ *     <th> event </th>
+ *     <th> instances </th>
+ *     <th> exceptions </th>
+ * </tr>
+ * <tr>
+ *     <td>
+ *             start date on 2012-10-09 (Tuesday) <br>
+ *             frequency set to 'WEEKLY' <br>
+ *             interval set to 1 <br>
+ *             count set to 3
+ * </td>
+ *     <td>
+ *             2012-10-09 Tuesday <br>
+ *             2012-10-23 Tuesday
+ *     </td>
+ *  <td>
+ *             2012-10-17 Tuesday <br>
+ *  </td>
+ * </tr>
+ * </table>
+ *
+ * To get changes in exception, calendar_db_get_changes_exception_by_version() is called. These instances and exceptions are deleted together when original event is deleted.
+ *
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_MODULE_Calendar_time_structure Calendar Time Structure
+ * The calendar time structure, calendar_caltime_s, is defined as follows:
+ *
+ * @code
+ * typedef struct
+ * {
+ *     calendar_time_type_e type;
+ *     union {
+ *         long long int utime;
+ *         struct {
+ *             int year;
+ *             int month;
+ *             int mday;
+ *         } date;
+ *     } time;
+ * } calendar_time_s;
+ * @endcode
+ *
+ * The structure should be used when setting the calendar time type
+ * (_CALENDAR_PROPERTY_CALTIME) properties of records.
+ *
+ * It can hold two types of data: UTC time (long long int) and date,
+ * given as year, month and day of the month (three integers). These types
+ * are identified by values of calendar_time_type_e, which are CALENDAR_TIME_UTIME
+ * and CALENDAR_TIME_LOCALTIME, respectively. The data type determines the usage
+ * of the structure.
+ *
+ * <table>
+ * <caption> Table: Data types </caption>
+ * <tr>
+ *     <th> Identifier </th>
+ *     <th> Type </th>
+ *     <th> Name </th>
+ *     <th> Purpose </th>
+ * </tr>
+ * <tr>
+ *     <td> CALENDAR_TIME_UTIME </td>
+ *     <td> long long int </td>
+ *     <td> utime </td>
+ *     <td> UTC time, used to describe non-all-day events </td>
+ * </tr>
+ * <tr>
+ *     <td> CALENDAR_TIME_LOCALTIME </td>
+ *     <td> struct </td>
+ *     <td> date </td>
+ *     <td> date only (year, month and day of the month), used to describe all day events </td>
+ * </tr>
+ * </table>
+ *
+ *
+ * @subsection CAPI_SOCIAL_CALENDAR_SVC_MODULE_Calendar_time_structure_UTC_time_usage UTC Time Usage
+ *
+ * Structures with UTC time should be used for non-all-day events.
+ * In such cases, the API user should convert local time to UTC time. The local
+ * time zone identifier should be stored in the record, in the corresponding
+ * property.
+ *
+ * For example, when setting starting time of an event, the local
+ * time zone should be stored in start_tzid.
+ *
+ * When converting local time to UTC time, the function below can be useful.
+ * The function converts the given date and time to the corresponding
+ * UTC time, considering the given time zone (first argument).
+ *
+ * @code
+ * #define ms2sec(ms) (long long int)(ms / 1000.0)
+ *
+ * long long int _time_convert_itol(char *tzid, int y, int mon, int d, int h, int min, int s)
+ * {
+ *     int ret = 0;
+ *     i18n_uchar utf16_timezone[64] = {0};
+ *     i18n_ustring_copy_ua_n(utf16_timezone, tzid, sizeof(utf16_timezone)/sizeof(i18n_uchar));
+ *
+ *     i18n_ucalendar_h ucal = NULL;
+ *     char *loc_default = NULL;
+ *     i18n_ulocale_get_default((const char **)&loc_default);
+ *     ret = i18n_ucalendar_create(utf16_timezone, -1, loc_default, I18N_UCALENDAR_GREGORIAN, &ucal);
+ *     if (I18N_ERROR_NONE != ret) {
+ *                dlog_print(DLOG_DEBUG, LOG_TAG, "i18n_ucalendar_create() is failed (%d)\n", ret);
+ *         return -1;
+ *     }
+ *
+ *     i18n_ucalendar_set_date_time(ucal, y, mon - 1, d, h, min, s);
+ *
+ *     i18n_udate date;
+ *     ret = i18n_ucalendar_get_millisecond(ucal, &date);
+ *     if (I18N_ERROR_NONE != ret) {
+ *         dlog_print(DLOG_DEBUG, LOG_TAG, "i18n_ucalendar_create() is failed (%d)\n", ret);
+ *         i18n_ucalendar_destroy(ucal);
+ *         return -1;
+ *     }
+ *     i18n_ucalendar_destroy(ucal);
+ *
+ *     return ms2sec(date);
+ * }
+ * @endcode
+ *
+ * Sample code:<br>
+ * @code
+ * // fill calendar time structures (start and end time)
+ * calendar_time_s st = {0};
+ * calendar_time_s et = {0};
+ *
+ * st.type = CALENDAR_TIME_UTIME;
+ * st.time.utime = _time_convert_itol("Asia/Seoul", 2012, 9, 15, 11, 0, 0);
+ *
+ * et.type = CALENDAR_TIME_UTIME;
+ * et.time.utime = _time_convert_itol("Asia/Seoul", 2012, 9, 15, 12, 0, 0);
+ *
+ * // create an event record
+ * // ...
+ *
+ * // set local time zone of start time
+ * calendar_record_set_str(event, _calendar_event.start_tzid, "Asia/Seoul");
+ *
+ * // set start time
+ * calendar_record_set_caltime(event, _calendar_event.start_time, st);
+ *
+ * // set local time zone of end time
+ * calendar_record_set_str(event, _calendar_event.end_tzid, "Asia/Seoul");
+ *
+ * // set end time
+ * calendar_record_set_caltime(event, _calendar_event.end_time, et);
+ * @endcode
+ *
+ *
+ * @subsection CAPI_SOCIAL_CALENDAR_SVC_MODULE_Calendar_time_structure_Date_usage Date Usage
+ * Another usage of time structure is an all day event.
+ * In case of such events, the structure's type field MUST be set to CALENDAR_TIME_LOCALTIME.
+ * Only the date (no time) will be stored. Such structures can be used to set start and end time of an event. <br>
+ * Both start and end time of the event MUST be set.
+ * The end date value MUST be later in time than the value of the start date.
+ *
+ * @code
+ * // range is 2days: 2014/02/17 00:00:00 ~ 2014/02/19 00:00:00
+ *
+ * calendar_time_s st = {0};
+ * st.type = CALENDAR_TIME_LOCALTIME;
+ * st.time.date.year = 2014;
+ * st.time.date.month = 2;
+ * st.time.date.mday = 17;
+ *
+ * calendar_time_s et = {0};
+ * et.type = CALENDAR_TIME_LOCALTIME;
+ * et.time.date.year = 2014;
+ * et.time.date.month = 2;
+ * et.time.date.mday = 19;
+ *
+ * // create an event record
+ * // ...
+ * @endcode
+ *
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_MODULE_Creating_a_recurring_event Recurring Events
+ * To create a recurring event in Calendar API, you MUST set frequency.
+ * There is a sample code how to create recurring event. Firstly, set start and end time.
+ *
+ * @code
+ * calendar_time_s st = {0};
+ * st.type = CALENDAR_TIME_UTIME;
+ * st.time.utime = _time_convert_itol("Asia/Seoul", 2012, 9, 15, 11, 0, 0);
+ *
+ * calendar_time_s et = {0};
+ * et.type = CALENDAR_TIME_UTIME;
+ * et.time.utime = _time_convert_itol("Asia/Seoul", 2012, 9, 15, 12, 0, 0);
+ * @endcode
+ *
+ * Then, the remaining properties should be set.
+ * Each frequency needs other proper fields except daily event.
+ * If other values are not inserted, these values are calculated based on start time.
+ *
+ * <table>
+ * <caption> Table: Frequency properties </caption>
+ * <tr>
+ *  <th> Freq </th>
+ *  <th> Property </th>
+ *  <th> Comment </th>
+ * </tr>
+ * <tr>
+ *  <td> CALENDAR_RECURRENCE_YEARLY </td>
+ *  <td> byyearday </td>
+ *  <td> Every 100th day </td>
+ * </tr>
+ * <tr>
+ *  <td> </td>
+ *  <td> byweekno </td>
+ *  <td> Every 34th week </td>
+ * </tr>
+ * <tr>
+ *  <td> </td>
+ *  <td> bymonthday </td>
+ *  <td> Every 1st February (birthday)</td>
+ * </tr>
+ * <tr>
+ *  <td> </td>
+ *  <td> byday </td>
+ *  <td> Every 1st Monday of May (holiday) </td>
+ * </tr>
+ * <tr>
+ *  <td> CALENDAR_RECURRENCE_MONTHLY </td>
+ *  <td> bymonthday </td>
+ *  <td> Every 29th (payday) </td>
+ * </tr>
+ * <tr>
+ *  <td> </td>
+ *  <td> byday </td>
+ *  <td> Every last Friday </td>
+ * </tr>
+ * <tr>
+ *  <td> CALENDAR_RECURRENCE_WEEKLY </td>
+ *  <td> byday </td>
+ *  <td> Every week </td>
+ * </tr>
+ * <tr>
+ *  <td> CALENDAR_RECURRENCE_DAILY </td>
+ *  <td> - </td>
+ *  <td> - </td>
+ * </tr>
+ * </table>
+ *
+ * If byday is not set in weekly event, default byday is followed start day of week.
+ * By the same token, default interval is 1 and default range type is endless.
+ *
+ * <table>
+ * <caption> Table: Range types </caption>
+ * <tr>
+ *  <th> Range type </th>
+ *  <th> Comment </th>
+ * </tr>
+ * <tr>
+ *  <td> CALENDAR_RANGE_NONE </td>
+ *  <td> Endless(max date is 2036/12/31) </td>
+ * </tr>
+ * <tr>
+ *  <td> CALENDAR_RANGE_UNTIL </td>
+ *  <td> Should set until property </td>
+ * </tr>
+ * <tr>
+ *  <td> CALENDAR_RANGE_COUNT </td>
+ *  <td> Should set count property </td>
+ * </tr>
+ * </table>
+ *
+ * @code
+ * calendar_record_h event;
+ * calendar_record_create(_calendar_event._uri, &event);
+ *
+ * calendar_record_set_str(event, _calendar_event.start_tzid, "Asia/Seoul");
+ * calendar_record_set_caltime(event, _calendar_event.start_time, st);
+ * calendar_record_set_str(event, _calendar_event.end_tzid, "Asia/Seoul");
+ * calendar_record_set_caltime(event, _calendar_event.end_time, et);
+ *
+ * calendar_record_set_int(event, _calendar_event.freq, CALENDAR_RECURRENCE_WEEKLY);
+ * calendar_record_set_int(event, _calendar_event.interval, 1)
+ * calendar_record_set_int(event, _calendar_event.count, 3);
+ * @endcode
+ *
+ * The last step is inserting the event into the database.
+ * Records representing instances of the event are created when the event record is inserted.
+ *
+ * @code
+ * int event_id = 0;
+ * calendar_db_insert_record(event, &event_id);
+ *
+ * calendar_record_destroy(event, true);
+ * @endcode
+ *
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_MODULE_Filters_and_queries Filters and Queries
+ * Queries are used to retrieve data which satisfies given criteria, like an integer
+ * property being greater than a given value, or a string property containing a given substring.
+ * The criteria are defined by creating filters and adding conditions to them, joining them
+ * with logical operators. Also, instead of a condition, another filter can be added,
+ * which can be used to create more complex filters.
+ *
+ * Operator precedence in filters determined by the order in which the
+ * conditions and filters are added.
+ *
+ * When a filter is ready, it can be set as a property of a query.
+ * Other query properties allow configuring how the returned results
+ * are grouped and sorted.
+ *
+ * Operator precedence in filters is determined by the order in which the
+ * conditions and filters are added are added.
+ * For example, if the following sequence is added:
+ *
+ * <table>
+ * <caption> Table: Filter and conditions </caption>
+ * <tr>
+ *     <th> Filter with conditions </th>
+ *     <th> Result </th>
+ * </tr>
+ * <tr>
+ *     <td>
+ *             Contidion C1 <br>
+ *             OR <br>
+ *             Contidion C2 <br>
+ *             AND <br>
+ *             Condition C3
+ *     </td>
+ *     <td> (C1 OR C2) AND C3 </td>
+ * </tr>
+ * <tr>
+ *     <td>
+ *             Filter F1: <br>
+ *                     Condition C1 <br>
+ *                     OR <br>
+ *                     Condition C2 <br><br>
+ *             Filter F2: <br>
+ *                     Condition C3 <br>
+ *                     OR <br>
+ *                     Condition C4 <br><br>
+ *             Filter F3: <br>
+ *                     Condition C5 <br>
+ *                     AND <br>
+ *                     F1 <br>
+ *                     AND <br>
+ *                     F2
+ *     </td>
+ *     <td>
+ *             (C5 AND F1) AND F2 <br>
+ *             Which is: <br>
+ *             (C5 AND (C1 OR C2)) AND (C3 OR C4)
+ *     </td>
+ * </tr>
+ * </table>
+ *
+ * The following code creates a filter, accepting events with high priority
+ * or those that include the word "meeting" in their description.
+ *
+ * @code
+ * calendar_filter_h filter = NULL;
+ *
+ * // create a filter returning event type records
+ * calendar_filter_create(_calendar_event._uri, &filter);
+ *
+ * // add 'priority equals high' condition
+ * calendar_filter_add_int(filter, _calendar_event.priority, CALENDAR_MATCH_EQUAL, CALENDAR_EVENT_PRIORITY_HIGH);
+ *
+ * // add OR operator
+ * calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_OR);
+ *
+ * // add 'description contains "meeting"' condition
+ * calendar_filter_add_str(filter, _calendar_event.description, CALENDAR_MATCH_CONTAINS, "meeting");
+ * @endcode
+ *
+ * The filter should be inserted into a query and the query should be executed:
+ *
+ * @code
+ * calendar_query_h query = NULL;
+ * calendar_list_h list = NULL;
+ *
+ * // create a query returning event type records
+ * calendar_query_create(_calendar_event._uri, &query);
+ *
+ * // add the filter
+ * calendar_query_set_filter(query, filter);
+ *
+ * // execute the query, results are returned in a list
+ * calendar_db_get_records_with_query(query, 0, 0, &list);
+ *
+ * calendar_filter_destroy(filter);
+ * calendar_query_destroy(query);
+ *
+ * // use the list
+ * // ...
+ *
+ * calendar_list_destroy(list, true);
+ * @endcode
+ *
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_MODULE_Projections Projections
+ * Useful concept in Calendar service APIs is projection, related to searching with filters and queries.
+ * Projection allows you to query the Data for just those specific properties of a record that you actually need, at lower latency
+ * and cost than retrieving the entire properties
+ *
+ * Sample code:<br>
+ * create filter which will get event id, summary and start time from the record with its summary has “test” (string filter).
+ * Create a query and add the filter to it. Results are received in a list.
+ *
+ * @code
+ * calendar_query_h query = NULL;
+ * calendar_filter_h filter = NULL;
+ *
+ * // set query with filter
+ * calendar_query_create(_calendar_event_calendar_book_attendee._uri, &query);
+ * calendar_filter_create(_calendar_event_calendar_book_attendee._uri, &filter);
+ * calendar_filter_add_str(filter, _calendar_event.summary, CALENDAR_MATCH_CONTAINS, "test");
+ * calendar_query_set_filter(query, filter);
+ *
+ * // set projection
+ * unsigned int projection[3];
+ * projection[0]=_calendar_event_calendar_book_attendee.event_id;
+ * projection[1]=_calendar_event_calendar_book_attendee.summary;
+ * projection[2]=_calendar_event_calendar_book_attendee.start_time;
+ *
+ * // get list
+ * calendar_query_set_projection(query, projection, 3);
+ * calendar_db_get_records_with_query(query, 0, 0, &list);
+ *
+ * // destroy handle
+ * calendar_filter_destroy(filter);
+ * calendar_query_destroy(query);
+ * calendar_list_destroy(list, true);
+ * @endcode
+ *
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_MODULE_Reminders Reminders
+ * Alarm and reminder is the similar terminology but reminder is used as package name storages in below figure 5.
+ * When alarm alerts, calendar-service sends notification to all packages which is registered in reminder DB table with calendar_reminder_add_receiver().
+ *
+ * This shows how to set alarm and how alarm works.
+ *
+ * @image html alarm_process.png "Figure: Alarm process"
+ * After adding receiver, registered alarm would be alerted on reserved time by inserting alarm as child.
+ *
+ * <table>
+ * <caption> Table: Alarm fields </caption>
+ * <tr>
+ *     <th> tick_unit </th>
+ *     <th> related field </th>
+ *     <th> comment </th>
+ * </tr>
+ * <tr>
+ *     <td> CALENDAR_ALARM_TIME_UNIT_SPECIFIC </td>
+ *     <td> time </td>
+ *     <td> This represents the number of seconds elapsed since the Epoch, 1970-01-01 00:00:00 +0000 (UTC) </td>
+ * </tr>
+ * <tr>
+ *     <td> CALENDAR_ALARM_TIME_UNIT_WEEK </td>
+ *     <td> tick </td>
+ *     <td> The number of weeks before start time </td>
+ * </tr>
+ * <tr>
+ *     <td> CALENDAR_ALARM_TIME_UNIT_DAY </td>
+ *     <td> tick </td>
+ *     <td> The number of days before start time </td>
+ * </tr>
+ * <tr>
+ *     <td> CALENDAR_ALARM_TIME_UNIT_HOUR </td>
+ *     <td> tick </td>
+ *     <td> The number of hours before start time </td>
+ * </tr>
+ * <tr>
+ *     <td> CALENDAR_ALARM_TIME_UNIT_MINUTE </td>
+ *     <td> tick </td>
+ *     <td> The number of minutes before start time </td>
+ * </tr>
+ * </table>
+ *
+ * Below example shows the alarm which is set 1 minute before start time.
+ *
+ * @code
+ // set alarm with normal unit
+ * calendar_record_h alarm = NULL;
+ * calendar_record_create(_calendar_alarm._uri, &alarm);
+ * calendar_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_MINUTE);
+ * calendar_record_set_int(alarm, _calendar_alarm.tick, 1); // before 1min (60secs)
+ *
+ * // add alarm as child
+ * calendar_record_add_child_record(event, _calendar_event.calendar_alarm, alarm);
+ * @endcode
+ *
+ * With CALENDAR_ALARM_TIME_UNIT_SPECIFIC, the alarm could be set regardless of the start time.
+ *
+ * @code
+ // set alarm with specific unit
+ * calendar_record_h alarm = NULL;
+ * calendar_record_create(_calendar_alarm._uri, &alarm);
+ * calendar_record_set_int(alarm, _calendar_alarm.tick_unit, CALENDAR_ALARM_TIME_UNIT_SPECIFIC);
+ * // suppose start time is 1404036000(Sun, 29 Jun 2014 10:00:00 GMT) and alarm is set 60secs after from start time.
+ * calendar_time_s ct;
+ * ct.type = CALENDAR_TIME_UTIME;
+ * ct.time.utime = 1404036000 + 60;
+ * calendar_record_set_caltime(alarm, _calendar_alarm.alarm_time, ct);
+ *
+ * // add alarm as child
+ * calendar_record_add_child_record(event, _calendar_event.calendar_alarm, alarm);
+ * @endcode
+ *
+ * How to register package as reminder.
+ *
+ * In manifest.xml file, below code must be inserted.
+ * @code
+ * <app-control>
+ *    <operation name="http://tizen.org/appcontrol/operation/view" />
+ *    <mime name="application/x-tizen.calendar.reminder" />
+ * </app-control>
+ * @endcode
+ *
+ * When alarm alerts, calendar-service sends data with key, value pairs.<br>
+ * With "ids" key, id array could be get.<br>
+ * Each detail value could be get with "each id" key.<br>
+ * The detail data is the combination of alarm values. id, time, tick, unit and type is connected with "&" charater.<br>
+ * ex> id=64&time=1415106300&tick=0&unit=60&type=0
+ *
+ * @code
+ * // "ids" string is the key, to get id array
+ * char **ids = NULL;
+ * int len = 0;
+ * app_control_get_extra_data_array(b, "ids", &ids, &len);
+ *
+ * int i = 0;
+ * for (i = 0; i < len; i++) {
+ *     // "id" is the key to get detail value
+ *     char *value = NULL;
+ *     app_control_get_extra_data(b, ids[i], &value);
+ *     if (NULL == value) {
+ *             continue;
+ *     }
+ *     // parse detail data
+ *
+ *     // free
+ *     free(ids[i]);
+ *     ids[i] = NULL;
+ * }
+ *
+ * free(ids);
+ * @endcode
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_MODULE_Db_change_noties Database Change Notifications
+ *
+ * Applications add/remove callback function to detect/ignore the calendar DB changes
+ * with calendar_db_add_changed_cb() / calendar_db_remove_changed_cb(). <br>
+ * Clients wait calendar change notification on client side.
+ * If calendar is changed by another module, server publishes inotify event. Inotify module broadcasts to subscribe modules.
+ * Internal inotify handler is called at client side. User callback function is called with user data.
+ *
+ * @code
+ * // add callback function
+ * void __event_changed_cb(const char *view_uri, void *user_data)
+ * {
+ * }
+ * // add changed noti callback
+ * calendar_db_add_changed_cb(_calendar_event._uri, __event_changed_cb, NULL);
+ * @endcode
+ *
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_MODULE_Vcalendar Vcalendar
+ *
+ * To exchange of personal calendaring and scheduling information, vcalendar is used.
+ * In order to avoid confusion with this referenced work, this is to be known as the vcalendar specification.
+ * Vcalendar ver2.0 is known as icalendar.
+ *
+ *
+ * <table>
+ * <caption> Table: Vcalendar example ( http://www.ietf.org/rfc/rfc2445.txt ) </caption>
+ * <tr>
+ *  <td>
+ *     BEGIN:VCALENDAR<br>
+ *     VERSION:2.0<br>
+ *     PRODID:-//hacksw/handcal//NONSGML v1.0//EN<br>
+ *     BEGIN:VEVENT<br>
+ *     DTSTART:19970714T170000Z<br>
+ *     DTEND:19970715T035959Z<br>
+ *     SUMMARY:Bastille Day Party<br>
+ *     END:VEVENT<br>
+ *     END:VCALENDAR<br>
+ *  </td>
+ * </tr>
+ * </table>
+ *
+ * Calendar service provides APIs to compose vcalendar stream.
+ * With stream, file could be made or data could be transmitted with json data.
+ *
+ * @code
+ * calendar_list_h list = NULL;
+ * // create or get list to make vcalendar stream
+ *
+ * char *stream = NULL;
+ * calendar_vcalendar_make_from_records(list, &stream);
+ *
+ * // jobs for stream
+ *
+ * // free
+ * free(stream);
+ * @endcode
+ *
+ * Vcalendar could be parsed with calendar service APIs as well.
+ *
+ * @code
+ * // read  stream from file
+ *
+ * calendar_list_h list = NULL;
+ * calendar_vcalendar_parse_to_calendar(stream, &list);
+ *
+ * // jobs for list…
+ * calendar_list_destroy(list, true);
+ * @endcode
+ *
+ */
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @defgroup CAPI_SOCIAL_CALENDAR_SVC_DATABASE_MODULE Database
+ *
+ * @brief The calendar database API provides the set of the definitions and interfaces that enable you to handle calendar database.
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_DATABASE_MODULE_HEADER Required Header
+ *  \#include <calendar.h>
+ *
+ * <BR>
+ */
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @defgroup CAPI_SOCIAL_CALENDAR_SVC_FILTER_MODULE Filter
+ *
+ * @brief The calendar filter API provides the set of the definitions and interfaces that enable you to handle filter.
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_FILTER_MODULE_HEADER Required Header
+ *  \#include <calendar.h>
+ *
+ * <BR>
+ */
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @defgroup CAPI_SOCIAL_CALENDAR_SVC_LIST_MODULE List
+ *
+ * @brief The calendar list API provides the set of the definitions and interfaces that enable you to handle list.
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_LIST_MODULE_HEADER Required Header
+ *  \#include <calendar.h>
+ *
+ * <BR>
+ */
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @defgroup CAPI_SOCIAL_CALENDAR_SVC_QUERY_MODULE Query
+ *
+ * @brief The calendar query API provides the set of the definitions and interfaces that enable you to handle query.
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_QUERY_MODULE_HEADER Required Header
+ *  \#include <calendar.h>
+ *
+ * <BR>
+ */
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @defgroup CAPI_SOCIAL_CALENDAR_SVC_RECORD_MODULE Record
+ *
+ * @brief The calendar record API provides the set of the definitions and interfaces that enable you to get/set data from/to calendar record handle.
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_RECORD_MODULE_HEADER Required Header
+ *  \#include <calendar.h>
+ *
+ * <BR>
+ */
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @defgroup CAPI_SOCIAL_CALENDAR_SVC_REMINDER_MODULE Reminder
+ *
+ * @brief The calendar reminder API provides the interface to set/unset reminder callback.
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_REMINDER_MODULE_HEADER Required Header
+ *  \#include <calendar.h>
+ *
+ * <BR>
+ */
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @defgroup CAPI_SOCIAL_CALENDAR_SVC_VCALENDAR_MODULE vCalendar
+ *
+ * @brief The calendar vcalendar API provides the set of the definitions and interfaces that enable you to get/set data from/to vCalendar.
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VCALENDAR_MODULE_HEADER Required Header
+ *  \#include <calendar.h>
+ *
+ * <BR>
+ */
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @defgroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ *
+ * @brief This page provides information about views with properties.
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_OVERVIEW Overview
+ * A view is a structure which describes properties of a record.
+ * A record can have basic properties of four types: integer, string, long integer. Each property
+ * of basic type has functions to operate on it:
+ *
+ * <table>
+ * <tr>
+ *     <th> Property </th>
+ *     <th> Setter </th>
+ *     <th> Getter </th>
+ * </tr>
+ * <tr>
+ *     <td> integer </td>
+ *     <td> calendar_record_set_int </td>
+ *     <td> calendar_record_get_int </td>
+ * </tr>
+ * <tr>
+ *     <td> long long integer </td>
+ *     <td> calendar_record_set_lli </td>
+ *     <td> calendar_record_get_lli </td>
+ * </tr>
+ * <tr>
+ *     <td> double </td>
+ *     <td> calendar_record_set_double </td>
+ *     <td> calendar_record_get_double </td>
+ * </tr>
+ * <tr>
+ *     <td> string </td>
+ *     <td> calendar_record_set_str </td>
+ *     <td> calendar_record_get_str </td>
+ * </tr>
+ * <tr>
+ *     <td> calendar_time_s </td>
+ *     <td> calendar_record_set_caltime </td>
+ *     <td> calendar_record_get_caltime </td>
+ * </tr>
+ * </table>
+ *
+ * For long long integer functions, "lli" stands for long long int, ususally used to hold UTC time.
+ *
+ * Below you can find tables with view properties.
+ *
+ * Properties of type 'record' are other records. For example, the @ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_event
+ * has a 'calendar_alarm' property of type 'record'. This means that records of type calendar_alarm (@ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_alarm)
+ * can be children of the event record. If a name record holds the identifier
+ * of a event record in its 'event_id' property, it is the child record of the corresponding
+ * event record.
+ *
+ * Records can have many children of a given type.
+ *
+ * Please refer to the main section of Calendar API for a more detailed explanation and examples.
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_HEADER Required Header
+ *  \#include <calendar.h>
+ */
+
+
diff --git a/doc/images/alarm_process.png b/doc/images/alarm_process.png
new file mode 100755 (executable)
index 0000000..f77c144
Binary files /dev/null and b/doc/images/alarm_process.png differ
diff --git a/doc/images/calendar_model.png b/doc/images/calendar_model.png
new file mode 100755 (executable)
index 0000000..29f5f0f
Binary files /dev/null and b/doc/images/calendar_model.png differ
diff --git a/doc/images/entities.png b/doc/images/entities.png
new file mode 100755 (executable)
index 0000000..ff98ee2
Binary files /dev/null and b/doc/images/entities.png differ
diff --git a/doc/images/properties.png b/doc/images/properties.png
new file mode 100755 (executable)
index 0000000..ae60a15
Binary files /dev/null and b/doc/images/properties.png differ
diff --git a/doc/images/view_db.png b/doc/images/view_db.png
new file mode 100755 (executable)
index 0000000..b623127
Binary files /dev/null and b/doc/images/view_db.png differ
diff --git a/doc/images/view_property.png b/doc/images/view_property.png
new file mode 100755 (executable)
index 0000000..19ec00f
Binary files /dev/null and b/doc/images/view_property.png differ
diff --git a/include/calendar-svc-errors.h b/include/calendar-svc-errors.h
deleted file mode 100755 (executable)
index 1d7b29f..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-/**
- * @defgroup return_value return_value
- * @ingroup CALENDAR_SVC
- * @brief
- *             return value with api call
- */
-
-#ifndef __CALENDAR_SVC_ERRORS_H__
-#define __CALENDAR_SVC_ERRORS_H__
-
-typedef enum
-{
-       CAL_ERR_EVENT_START_DATE = -405,
-       CAL_ERR_EVENT_END_DATE = -404,
-       CAL_ERR_EVENT_REPEAT_END_DATE = -403,
-       CAL_ERR_EVENT_DURATION = -402,
-       CAL_ERR_EVENT_REPEAT_DURATION_TOO_SHORT = -401,
-
-       CAL_ERR_INVALID_DATA_TYPE       =-301,
-
-       CAL_ERR_DB_LOCK = -204,
-       CAL_ERR_DB_RECORD_NOT_FOUND = -203,
-       CAL_ERR_DB_FAILED = -202,
-       CAL_ERR_DB_NOT_OPENED= -201,
-
-       CAL_ERR_ALARMMGR_FAILED = -105,
-       CAL_ERR_TIME_FAILED = -104,
-       CAL_ERR_INOTIFY_FAILED = -103,
-       CAL_ERR_VCONF_FAILED = -102,
-       CAL_ERR_VOBJECT_FAILED = -101,
-
-       CAL_ERR_NO_SPACE = -11,
-       CAL_ERR_IO_ERR = -10,
-       CAL_ERR_EXCEEDED_LIMIT = -9,
-       CAL_ERR_OUT_OF_MEMORY = -8,
-       CAL_ERR_ALREADY_EXIST = -7,
-       CAL_ERR_ENV_INVALID = -6,
-       CAL_ERR_ARG_NULL = -5,
-       CAL_ERR_ARG_INVALID = -4,
-       CAL_ERR_NO_DATA = -3,
-       CAL_ERR_FINISH_ITER= -2,
-       CAL_ERR_FAIL= -1,
-       CAL_SUCCESS = 0,
-       CAL_FALSE = 0,
-       CAL_TRUE
-}cal_error;
-
-#endif /* __CALENDAR_SVC_ERRORS_H__ */
-
diff --git a/include/calendar-svc-provider.h b/include/calendar-svc-provider.h
deleted file mode 100755 (executable)
index f83d8ff..0000000
+++ /dev/null
@@ -1,2703 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __CALENDAR_SVC_H__
-#define __CALENDAR_SVC_H__
-
-#ifndef DEPRECATED
-#define DEPRECATED __attribute__ ((deprecated))
-#endif
-
-
-/**
- * @defgroup CALENDAR_SVC  Calendar Service
- */
-
-/**
- * @defgroup common    common
- * @ingroup CALENDAR_SVC
- * @brief
- *             common struct for calendar service
- */
-
-
-/**
- * cal_struct is an opaque type, it must be
- * used via accessor functions.
- * @addtogroup common
- * @see calendar_svc_struct_new(), calendar_svc_struct_free()
- * @see calendar_svc_struct_get_value(), calendar_svc_struct_get_list(),
- * @see calendar_svc_struct_store_value(), calendar_svc_struct_store_list()
- */
-
-#include <glib.h>
-#include <stdbool.h>
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <calendar-svc-errors.h>
-#include <calendar-svc-struct.h>
-#include <alarm.h>
-
-/**
- * @addtogroup common
- * @{
- */
-
-/**
- * This enumeration date type, sun or lunar.
- */
-typedef enum
-{
-       CAL_DATE_SUN = 0,          /**< date is sun type*/
-       CAL_DATE_LUNAR,         /**< date is lunar type */
-} cal_date_type_t;
-
-/**
- * This enumeration defines Remind Tick Unit for schedule.
- * Ex. remindTick = 1, remindTickUnit = CAL_SCH_TIME_UNIT_MIN, Organizer alarms
- * 1 minute before schedule starting time.
- */
-typedef enum /* use with *60 */
-{
-       CAL_SCH_TIME_UNIT_OFF = -1, /**< off */
-       CAL_SCH_TIME_UNIT_MIN = 1, /**< Minute */
-       CAL_SCH_TIME_UNIT_HOUR = 60, /**< Hour 60 * 60 */
-       CAL_SCH_TIME_UNIT_DAY = 1440, /**< Day 60 * 60 *24 */
-       CAL_SCH_TIME_UNIT_WEEK = 10080, /**< Week DAY * 7 */
-       CAL_SCH_TIME_UNIT_MONTH,        /**< Month - will be removed*/
-       CAL_SCH_TIME_UNIT_SPECIFIC  /**< using alarm time */
-} cal_sch_remind_tick_unit_t;
-
-/**
- * This enumeration defines Repeat term.
- */
-typedef enum
-{
-       CAL_REPEAT_NONE = 0,             /**< never Repeat */
-       CAL_REPEAT_EVERY_DAY,         /**< Repeats every day */
-       CAL_REPEAT_EVERY_WEEK,        /**< Repeats every week */
-       CAL_REPEAT_EVERY_MONTH,       /**< Repeats every month */
-       CAL_REPEAT_EVERY_YEAR,        /**< Repeats every year */
-       CAL_REPEAT_EVERY_WEEKDAYS,    /**< Repeats every weekdays *//* same with CAL_REPEAT_EVERY_WEEK, but week_flag="0111110", day_date=1, sun_moon=0, week_start=0 */
-       CAL_REPEAT_EVERY_MONTH_DAY,   /**< Repeats every month's week days *//* same with CAL_REPEAT_EVERY_MONTH, but week_flag="1000000"~"0000001", day_date=0, sun_moon=0, week_start=0 */
-       CAL_REPEAT_EVERY_YEAR_DAY,    /**< Repeats every year's month week days *//* same with CAL_REPEAT_EVERY_YEAR, but week_flag="1000000"~"0000001", day_date=0, sun_moon=0, week_start=0 */
-} cal_repeat_term_t;
-
-/**
- * This enumeration defines Repeat term.
- */
-typedef enum
-{
-       CALS_REPEAT_UNTIL_TYPE_NONE = 0,  /**< Repeat endlessly */
-       CALS_REPEAT_UNTIL_TYPE_COUNT,     /**< Repeat number of times, which the CAL_VALUE_INT_REPEAT_OCCURRENCES indicates */
-       CALS_REPEAT_UNTIL_TYPE_DATETIME,  /**< Repeat until the date-time which the CAL_VALUE_GMT_REPEAT_END_DATE indicates */
-} cal_repeat_until_type_t;
-
-/**
- * This enumeration defines sync status.
- */
-typedef enum
-{
-       CAL_SYNC_STATUS_NEW = 0,        /**< newly added. */
-       CAL_SYNC_STATUS_UPDATED,        /**< updated. */
-       CAL_SYNC_STATUS_DELETED,        /**< deleted. */
-       CAL_SYNC_STATUS_SYNCED,         /**< synced */
-} cal_sync_status_t;
-
-/**
- * This enumeration defines Expiration for schedule data.
- */
-typedef enum
-{
-       CAL_SCH_EXPIRATION_NONE = 0,                      /**< never expirate */
-       CAL_SCH_EXPIRATION_AFTER_1_MONTH,               /**< After 1 month */
-       CAL_SCH_EXPIRATION_AFTER_1_YEAR,                  /**< After 1 year */
-       CAL_SCH_EXPIRATION_AFTER_2_YEARS,               /**< After 2 years */
-       CAL_SCH_EXPIRATION_AFTER_3_YEARS                  /**< After 3 years */
-} cal_expiration_t;
-
-/**
- * This enumeration defines lart type.
- */
-typedef enum
-{
-       CAL_ALERT_MELODY = 0,                             /**< alarm type is melody */
-       CAL_ALERT_MUTE,                                           /**< alarm type is mute */
-       CAL_ALERT_INCREASING_MELODY,              /**< alarm type is increasing melody */
-       CAL_ALERT_VIBRATION,                               /**< alarm type is vibrate */
-       CAL_ALERT_VIBRATION_THEN_MELODY,          /**< alarm type is vibrate then melody */
-       CAL_ALERT_VIBMELODY,                               /**< alarm type is melody with vibrate */
-       CAL_ALERT_VIB_INCREASING_MELODY         /**< alarm type is increasing melody */
-} cal_alert_type_t;
-
-/**
- * This enumeration defines alarm volume .
- */
-typedef enum
-{
-       CAL_SNOOZE_OFF = 0,     /**< snoooze is off */
-       CAL_SNOOZE_1MIN,          /**< snoooze time is 1 min */
-       CAL_SNOOZE_3MINS,         /**< snoooze time is 3 mins */
-       CAL_SNOOZE_5MINS,         /**< snoooze time is 5 mins */
-       CAL_SNOOZE_10MINS,      /**< snoooze time is 10 mins */
-       CAL_SNOOZE_15MINS         /**< snoooze time is 15 mins */
-
-} cal_snooze_type_t;
-
-/**
- * This enumeration defines alarm snooze count .
- */
-typedef enum
-{
-       CAL_SNOOZE_0TIME = 0,           /**< snoooze count is 0 time */
-       CAL_SNOOZE_1TIME = 1,     /**< snoooze count is 1 time */
-       CAL_SNOOZE_2TIMES = 2,    /**< snoooze count is 2 times */
-       CAL_SNOOZE_5TIMES = 5,    /**< snoooze count is 5 times */
-       CAL_SNOOZE_10TIMES = 10   /**< snoooze count is 10 times */
-} cal_snooze_count_t;
-
-/**
- * This enumeration defines attendee's status .
- */
-typedef enum
-{
-       CAL_TZ_FLAG_GMT = 0,    /**< gmt time */
-       CAL_TZ_FLAG_LOCAL = 1,   /**< calendar local time */
-} cal_timezone_flag;
-
-/**
- * This enumeration defines calendar's visibility .
- */
-typedef enum
-{
-       PUBLIC_VISIBILITY = 0,
-       PRIVATE_VISIBILITY,
-       CONFIDENTIAL_VISIBILITY
-} cal_visibility_type_t;
-
-/**
- * This enumeration defines event attendee's availability .
- */
-typedef enum
-{
-       EVENT_BUSY_FB=0,
-       EVENT_BUSY_UNAVAILABLE_FB,
-       EVENT_FREE_FB,
-       EVENT_BUSY_TENTATIVE_FB,
-} cal_event_availability_type_t;
-
-
-/**
- * This enumeration defines event attendee's role .
- */
-typedef enum
-{
-       EVENT_ATTENDEE_REQ_PARTICIPANT_ROLE=0,
-       EVENT_ATTENDEE_OPT_PARTICIPANT_ROLE,
-       EVENT_ATTENDEE_NON_PARTICIPANT_ROLE,
-       EVENT_ATTENDEE_CHAIR_ROLE,
-} cal_event_attendee_role_type_t;
-
-/**
- * This enumeration defines event attendee's status.
- */
-typedef enum
-{
-       EVENT_ATTENDEE_NEEDS_ACTION_AT_STATUS=0,
-       EVENT_ATTENDEE_ACCEPTED_AT_STATUS,
-       EVENT_ATTENDEE_DECLINED_AT_STATUS,
-       EVENT_ATTENDEE_TENTATIVE_AT_STATUS,
-       EVENT_ATTENDEE_DELEGATED_AT_STATUS,
-       EVENT_ATTENDEE_COMPLETED_AT_STATUS,
-       EVENT_ATTENDEE_IN_PROCESS_AT_STATUS
-} cal_event_attendee_status_type_t;
-
-
-/**
- * Deprecated.
- */
-#define EVENT_ATTENDEE_PENDING_AT_STATUS EVENT_ATTENDEE_NEEDS_ACTION_AT_STATUS
-
-/**
- * This enumeration defines event attendee's type .
- */
-typedef enum
-{
-       EVENT_ATTENDEE_INDIVIDUAL_TYPE=0,
-       EVENT_ATTENDEE_GROUP_TYPE,
-       EVENT_ATTENDEE_RESOURCE_TYPE,
-       EVENT_ATTENDEE_ROOM_TYPE,
-       EVENT_ATTENDEE_UNKNOWN_TYPE
-} cal_event_attendee_type_t;
-
-
-/**
- * This enumeration defines CAL_VALUE_INT_PRIORITY .
- */
-typedef enum
-{
-       EVENT_PRIORITY_LOW = 0,
-       EVENT_PRIORITY_NORMAL,
-       EVENT_PRIORITY_HIGH,
-} cal_priority_type_t;
-
-enum {
-       CALS_TODO_PRIORITY_NONE = 0x01,
-       CALS_TODO_PRIORITY_HIGH = 0x02,
-       CALS_TODO_PRIORITY_MID = 0x04,
-       CALS_TODO_PRIORITY_LOW = 0x08,
-};
-
-/**
- * This enumeration defines status.
- * (related with CAL_VALUE_INT_TASK_STATUS)
- */
-
-#define CALS_STATUS_NONE CALS_EVENT_STATUS_NONE
-typedef enum
-{
-       CALS_EVENT_STATUS_NONE = 0x0001,
-       CALS_EVENT_STATUS_TENTATIVE = 0x0002,
-       CALS_EVENT_STATUS_CONFIRMED = 0x0004,
-       CALS_EVENT_STATUS_CANCELLED = 0x0008,
-       CALS_TODO_STATUS_NONE = 0x0100,
-       CALS_TODO_STATUS_NEEDS_ACTION = 0x0200,
-       CALS_TODO_STATUS_IN_PROCESS = 0x0400,
-       CALS_TODO_STATUS_CANCELLED = 0x0800,
-       CALS_TODO_STATUS_COMPLETED = 0x1000,
-} cals_status_t;
-
-/**
- * This enumeration defines calendar type.
- * (related with CAL_TABLE_INT_STORE_TYPE)
- */
-typedef enum
-{
-       CALS_CALENDAR_TYPE_NONE = 0,
-       CALS_CALENDAR_TYPE_EVENT = 1<<0,
-       CALS_CALENDAR_TYPE_TODO = 1<<1,
-} cals_calendar_store_type;
-
-/**
- * This enumeration defines todo list ordering type.
- */
-typedef enum
-{
-       CALS_TODO_LIST_ORDER_END_DATE = 0,
-       CALS_TODO_LIST_ORDER_PRIORITY,
-       CALS_TODO_LIST_ORDER_STATUS,
-} cals_todo_list_order_t;
-
-/**
- * This enumeration defines calendar sensitivity.
- * (related with CAL_VALUE_INT_SENSITIVITY)
- */
-typedef enum
-{
-       CALS_SENSITIVITY_PUBLIC = 0x0,
-       CALS_SENSITIVITY_PRIVATE,
-       CALS_SENSITIVITY_CONFIDENTIAL,
-} cals_sensitivity_t;
-
-/**
- * This enumeration defines updated type
- * (related with CALS_STRUCT_UPDATED_INT_TYPE)
- */
-enum cals_updated_type {
-       CALS_UPDATED_TYPE_INSERTED = 0x0,
-       CALS_UPDATED_TYPE_MODIFIED,
-       CALS_UPDATED_TYPE_DELETED,
-};
-
-/**
- * Flags to specify what fields will be searched by search API
- */
-enum SEARCHFIELD {
-       CALS_SEARCH_FIELD_NONE = 0,
-       CALS_SEARCH_FIELD_SUMMARY = 1<<0,
-       CALS_SEARCH_FIELD_DESCRIPTION = 1<<2,
-       CALS_SEARCH_FIELD_LOCATION = 1<<3,
-       CALS_SEARCH_FIELD_ATTENDEE = 1<<4,
-};
-
-/**
- * @}
- */
-
-/**
- * @addtogroup common
- * @{
- * brief
- *             calendar_svc_struct_new's argument
- */
-#define CAL_STRUCT_TYPE                                          /**< CAL_STRUCT_TYPE */
-#define CAL_STRUCT_CALENDAR "calendar"         /**< CAL_STRUCT_CALENDAR */
-#define CAL_STRUCT_SCHEDULE "schedule"         /**< CAL_STRUCT_SCHEDULE */
-#define CAL_STRUCT_TODO                "todo"                  /**< CAL_STRUCT_TASK */
-#define CAL_STRUCT_TIMEZONE    "timezone"              /**< CAL_STRUCT_TIMEZONE */
-#define CAL_STRUCT_UPDATED "updated"     /**< CAL_STRUCT_UPDATED */
-#define CALS_STRUCT_PERIOD_NORMAL_ONOFF "period_normal_onoff"
-#define CALS_STRUCT_PERIOD_ALLDAY_ONOFF "period_allday_onoff"
-#define CALS_STRUCT_PERIOD_NORMAL_BASIC "period_normal_basic"
-#define CALS_STRUCT_PERIOD_ALLDAY_BASIC "period_allday_basic"
-#define CALS_STRUCT_PERIOD_NORMAL_OSP "period_normal_osp"
-#define CALS_STRUCT_PERIOD_ALLDAY_OSP "period_allday_osp"
-#define CALS_STRUCT_PERIOD_NORMAL_LOCATION "period_normal_location"
-#define CALS_STRUCT_PERIOD_ALLDAY_LOCATION "period_allday_location"
-#define CALS_STRUCT_PERIOD_NORMAL_ALARM "period_normal_alarm"
-
-// id for all data read
-#define ALL_ACCOUNT_ID 0
-#define ALL_CALENDAR_ID 0
-
-// id for all data without visibility false
-#define ALL_VISIBILITY_ACCOUNT -2
-
-// id for local data read
-#define LOCAL_ACCOUNT_ID -1
-#define LOCAL_ALL_CALENDAR -1
-
-/* start deprecated */
-#define DEFAULT_CALENDAR_ID 1
-/* end deprecated, replace DEFAULT_EVENT_CALENDAR_ID */
-
-#define DEFAULT_EVENT_CALENDAR_ID 1
-#define DEFAULT_TODO_CALENDAR_ID 2
-
-// added val 2012.07.30
-#define CALS_TODO_NO_DUE_DATE INT64_MAX
-
-/**
- * @}
- */
-
-/**
- * @addtogroup common
- * @{
- * brief
- *             calendar_svc_struct_xxx()'s argument
- */
-#define CAL_TABLE_INT_INDEX "index"
-#define CAL_TABLE_TXT_CALENDAR_ID "calendar_id"
-#define CAL_TABLE_TXT_UID "uid"
-#define CAL_TABLE_TXT_LINK "link"
-#define CAL_TABLE_INT_UPDATED "updated"
-#define CAL_TABLE_TXT_NAME "name"
-#define CAL_TABLE_TXT_DESCRIPTION "description"
-#define CAL_TABLE_TXT_AUTHOR "author"
-#define CAL_TABLE_TXT_COLOR "color"
-#define CAL_TABLE_INT_HIDDEN "hidden"
-#define CAL_TABLE_INT_SELECTED "selected"
-#define CAL_TABLE_TXT_LOCATION "location"
-#define CAL_TABLE_INT_LOCALE "locale"
-#define CAL_TABLE_INT_COUNTRY "country"
-#define CAL_TABLE_INT_TIME_ZONE "time_zone"
-#define CAL_TABLE_TXT_TIME_ZONE_LABEL "timezone_label"
-#define CAL_TABLE_INT_DISPLAY_ALL_TIMEZONES "display_all_timezones"
-#define CAL_TABLE_INT_DATE_FIELD_ORDER "date_field_order"
-#define CAL_TABLE_INT_FROMAT_24HOUR_TIME "format_24hour_time"
-#define CAL_TABLE_INT_WEEK_START "week_start"
-#define CAL_TABLE_INT_DEFAULT_CAL_MODE "default_cal_mode"
-#define CAL_TABLE_INT_CUSTOM_CAL_MODE "custom_cal_mode"
-#define CAL_TABLE_TXT_USER_LOCATION "user_location"
-#define CAL_TABLE_TXT_WEATHER "weather"
-#define CAL_TABLE_INT_SHOW_DECLINED_EVENTS "show_declined_events"
-#define CAL_TABLE_INT_HIDE_INVITATIONS "hide_invitations"
-#define CAL_TABLE_INT_ALTERNATE_CALENDAR "alternate_calendar"
-#define CAL_TABLE_INT_VISIBILITY "visibility"
-#define CAL_TABLE_INT_PROJECTION "projection"
-#define CAL_TABLE_INT_SEQUENCE "sequence"
-#define CAL_TABLE_INT_SUPRESS_REPLY_NOTIFICATIONS "suppress_reply_notifications"
-#define CAL_TABLE_INT_SYNC_EVENT "sync_event"
-#define CAL_TABLE_INT_TIMES_CLEANED "times_cleaned"
-#define CAL_TABLE_INT_GUESTS_CAN_MODIFY "guests_can_modify"
-#define CAL_TABLE_INT_GUESTS_CAN_INVITE_OTHERS "guests_can_invite_others"
-#define CAL_TABLE_INT_GUESTS_CAN_SEE_GUESTS "guests_can_see_guests"
-#define CAL_TABLE_INT_ACCESS_LEVEL "access_level"
-#define CAL_TABLE_INT_SYNC_STATUS "sync_status"
-#define CAL_TABLE_INT_IS_DELETED "is_deleted"
-#define CAL_TABLE_INT_ACCOUNT_ID "account_id"
-#define CAL_TABLE_INT_SENSITIVITY "sensitivity"
-#define CAL_TABLE_INT_STORE_TYPE "store_type" /**< #cals_calendar_store_type */
-
-/**
- * @}
- */
-
-/**
- * @addtogroup common
- * @{
- * brief
- *             calendar_svc_struct_xxx()'s argument
- */
-#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 */
-/**
- * @}
- */
-
-
-
-/**
- * @addtogroup common
- * @{
- * brief
- *             calendar_svc_struct_xxx()'s argument
- */
-#define CAL_VALUE_INT_INDEX                              "id"                                  /**< Record index */
-#define CAL_VALUE_INT_ACCOUNT_ID                         "account_id"                  /**< account id */
-#define CAL_VALUE_INT_TYPE                               "type"                                /**< Calendar component type */
-#define CAL_VALUE_TXT_CATEGORIES "categories" /**< Category of schedule */
-#define CAL_VALUE_TXT_EXDATE "exdate" /**< Exdate */
-#define CAL_VALUE_TXT_SUMMARY                            "summary"                             /**< Summary, appointment, task: subject, birthday:Name */
-#define CAL_VALUE_TXT_DESCRIPTION                        "description"                 /**< Description,appointment, task: description, anniversary,holiday:occasion*/
-#define CAL_VALUE_TXT_LOCATION                           "location"                            /**< Location */
-#define CAL_VALUE_INT_MISSED                             "missed"                                /**< Miss alarm flag */
-#define CAL_VALUE_INT_TASK_STATUS                        "task_status"                 /**< current task status #cals_status_t */
-#define CAL_VALUE_INT_PRIORITY                           "priority"                            /**< Priority */
-#define CAL_VALUE_INT_TIMEZONE                           "timezone"                            /**< deprecated - timezone of task */
-#define CAL_VALUE_INT_FILE_ID                            "file_id"                             /**< file id for attach or alarm tone*/
-#define CAL_VALUE_INT_CONTACT_ID                         "contact_id"                  /**< contact id for birthday in contact list */
-#define CAL_VALUE_INT_BUSY_STATUS                        "busy_status"                 /**< ACS, G : Flag of busy or not */
-#define CAL_VALUE_INT_SENSITIVITY                        "sensitivity"                 /**< iCal:CLASS #cals_sensitivity_t */
-#define CAL_VALUE_TXT_UID                                        "uid"                                   /**< ACS, G : Unique ID of the meeting item */
-#define CAL_VALUE_INT_CALENDAR_TYPE                      "calendar_type"               /**< ACS, G : Type(all,phone,google) of calendar */
-#define CAL_VALUE_TXT_ORGANIZER_NAME             "organizer_name"              /**< ACS, G : Name of organizer(author) */
-#define CAL_VALUE_TXT_ORGANIZER_EMAIL            "organizer_email"             /**< ACS, G : Email of organizer */
-#define CAL_VALUE_INT_MEETING_STATUS             "meeting_status"              /**< ACS, G : The status of the meeting. */
-#define CAL_VALUE_TXT_GCAL_ID                            "gcal_id"                             /**< G : Server id of calendar */
-#define CAL_VALUE_INT_DELETED                            "deleted"                             /**< G : Flag for deleted */
-#define CAL_VALUE_TXT_UPDATED                            "updated"                             /**< G : Updated time stamp */
-#define CAL_VALUE_INT_LOCATION_TYPE                      "location_type"               /**< G : Location type */
-#define CAL_VALUE_TXT_LOCATION_SUMMARY           "location_summary"    /**< G : A simple string value that can be used as a representation of this location */
-#define CAL_VALUE_TXT_ETAG                                       "etag"                                        /**< G : ETAG of this event */
-#define CAL_VALUE_INT_CALENDAR_ID                        "calendar_id"                 /**< G : id to map from calendar table */
-#define CAL_VALUE_INT_SYNC_STATUS                        "sync_status"                 /**< G : Indication for event entry whether added/ modified/ deleted */
-#define CAL_VALUE_TXT_EDIT_URL                           "edit_uri"    /**< G : EditUri for google calendar */
-#define CAL_VALUE_TXT_GEDERID                            "gevent_id"                           /**< G : Server id of an event */
-#define CAL_VALUE_INT_DST                                        "dst"                                   /**< dst of event */
-#define CAL_VALUE_INT_ORIGINAL_EVENT_ID                  "original_event_id" /**< original event id for recurrency exception */
-#define CAL_VALUE_INT_CALENDAR_INDEX      "calendar_index"   /**< specific calendar id - will be remove */
-#define CAL_VALUE_DBL_LATITUDE         "latitude"      /**< latitude */
-#define CAL_VALUE_DBL_LONGITUDE        "longitude"     /**< longitude */
-#define CAL_VALUE_INT_EMAIL_ID                           "email_id"                    /**< email id */
-#define CAL_VALUE_INT_AVAILABILITY                       "availability"
-#define CAL_VALUE_LLI_CREATED_TIME "created_time"
-#define CAL_VALUE_LLI_COMPLETED_TIME "completed_time"
-#define CAL_VALUE_INT_PROGRESS "progress"
-#define CAL_VALUE_INT_IS_DELETED "is_deleted"/**< In deleting action, this is set 1 and will be deleted after sync */
-
-#define CAL_VALUE_INT_CAL_TYPE                           "cal_type" /**< deprecated */
-
-/**
- * @}
- */
-
-
-/**
- * @addtogroup common
- * @{
- * brief
- *             attendee cal_value's detail field
- */
-#define CAL_VALUE_LST_ATTENDEE_LIST         "attendee_list"     /**< attendee's detail information set */
-#define CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME                     "attendee_name"                 /**< attendee_name */
-#define CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL              "attendee_email"                      /**< attendee_email */
-#define CAL_VALUE_TXT_ATTENDEE_DETAIL_NUMBER           "attendee_number"                       /**< attendee_email */
-#define CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS           "attendee_status"                       /**< #cal_event_attendee_status_type_t */
-#define CAL_VALUE_INT_ATTENDEE_DETAIL_TYPE                     "attendee_type"                 /**< #cal_event_attendee_type_t */
-#define CAL_VALUE_INT_ATTENDEE_DETAIL_CT_INDEX         "attendee_ct_index"             /**< contact db index for reference */
-#define CAL_VALUE_INT_ATTENDEE_ROLE                                    "attendee_role" /**< #cal_event_attendee_role_type_t */
-#define CAL_VALUE_INT_ATTENDEE_RSVP                                    "attendee_rsvp"
-#define CAL_VALUE_TXT_ATTENDEE_GROUP                           "attendee_group"
-#define CAL_VALUE_TXT_ATTENDEE_DELEGATOR_URI           "attendee_delegator_uri"
-#define CAL_VALUE_TXT_ATTENDEE_DELEGATE_URI                    "attendee_delegate_uri"
-#define CAL_VALUE_TXT_ATTENDEE_UID                                     "attendee_uid"
-
-/**
- * @}
- */
-
-#define CAL_VALUE_LST_ALARM                            "alarm"    /**< exception's detail information set */
-#define CAL_VALUE_LLI_ALARMS_TIME                                      "alarm_time"                    /**< alarm time */
-#define CAL_VALUE_INT_ALARMS_TICK                                      "remind_tick"                   /**< Alarms before remindTick */
-#define CAL_VALUE_INT_ALARMS_TICK_UNIT                         "remind_tick_unit"      /**< Remind tick unit */
-#define CAL_VALUE_TXT_ALARMS_TONE                                      "alarm_tone"                    /**< Alert Sound File Name */
-#define CAL_VALUE_TXT_ALARMS_DESCRIPTION "alarm_description"                   /**< Alert description */
-#define CAL_VALUE_INT_ALARMS_TYPE                                      "alarm_type"                    /**< Alert type(see 'cal_alert_type_t') */
-#define CAL_VALUE_INT_ALARMS_ID                                                "alarm_id"                              /**< Alarm id */
-
-/**
- * @}
- */
-
-
-
-/**
- * @addtogroup common
- * @{
- * brief
- *             delete flag in detail list
- */
-
-#define CAL_VALUE_INT_DETAIL_DELETE     "is_deleted" /**< delete setting in detail list*/
-
-/**
- * @}
- */
-
-
-
-/**
- * @addtogroup common
- * @{
- * brief
- *             calendar_svc_value_xxx()'s argument for timezone
- */
-/* type for timezone information save */
-
-#define CAL_TZ_VALUE_INT_INDEX                                                 "index"
-#define CAL_TZ_VALUE_INT_TZ_OFFSET                                             "tz_offset_from_gmt"
-
-#define CAL_TZ_VALUE_TXT_STD_NAME                                              "standard_name"
-#define CAL_TZ_VALUE_INT_STD_START_MONTH                               "std_start_month"
-#define CAL_TZ_VALUE_INT_STD_START_POSITION_OF_WEEK            "std_start_position_of_week"
-#define CAL_TZ_VALUE_INT_STD_START_DAY                                 "std_start_day"
-#define CAL_TZ_VALUE_INT_STD_START_HOUR                                        "std_start_hour"
-#define CAL_TZ_VALUE_INT_STD_BIAS                                              "standard_bias"
-
-#define CAL_TZ_VALUE_TXT_DST_NAME                                              "day_light_name"
-#define CAL_TZ_VALUE_INT_DST_START_MONTH                               "day_light_start_month"
-#define CAL_TZ_VALUE_INT_DST_START_POSITION_OF_WEEK            "day_light_start_position_of_week"
-#define CAL_TZ_VALUE_INT_DST_START_DAY                                 "day_light_start_day"
-#define CAL_TZ_VALUE_INT_DST_START_HOUR                                        "day_light_start_hour"
-#define CAL_TZ_VALUE_INT_DST_BIAS                                              "day_light_bias"
-
-/**
- * @}
- */
-
-
-
-/**
- * @ingroup CALENDAR_SVC
- * @defgroup service_management service_management
- * @brief
- *             calendar service module management
- */
-
-/**
- * @fn int calendar_svc_connect(void);
- *   This function opens database,it is must be called before other data operaion.
- *
- * @ingroup service_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre none
- * @post calendar_svc_close() should be called when leave.
- * @code
-    #include <calendar-svc-provider.h>
-    void sample_code()
-    {
-       //connect to database
-       calendar_svc_connect();
-
-       //..do some operation to database
-
-       //close database
-       calendar_svc_close();
-    }
- * @endcode
- * @see calendar_svc_close().
- */
-int calendar_svc_connect(void);
-
-/**
- * @fn int calendar_svc_close(void);
- *   This function closes database,it is must be called when leave.
- *
- * @ingroup service_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre the database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-               //connect to database
-       calendar_svc_connect();
-
-       //..do some operation to database
-
-       //close database
-       calendar_svc_close();
-   }
- * @endcode
- * @see calendar_svc_connect().
- */
-int calendar_svc_close(void);
-
-/**
- * @fn int calendar_svc_begin_trans(void);
- * This function start db transaction,it is coninient for user do many operaion once.
- *
- * @ingroup service_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post calendar_svc_end_trans() should be called when leave
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-               //connect to database
-       calendar_svc_connect();
-
-               // begin transaction
-               calendar_svc_begin_trans();
-
-       //..do some operation to database
-
-       // end transaction
-               calendar_svc_end_trans();
-
-       //close database
-       calendar_svc_close();
-
-   }
- * @endcode
- * @see calendar_svc_end_trans().
- */
-int calendar_svc_begin_trans(void);
-
-/**
- * @fn int calendar_svc_end_trans(bool is_success);
- * This function finishes database transaction of calendar service.
- * If it returns error, the transaction has been rollbacked.
- * When transction is success, it returns the last contacts version.
- *
- * @ingroup service_management
- * @param[in] is_success Commit changes if #true. Otherwise, no changes will be made on the database.
- * @return CAL_SUCCESS or the last calendar version(when success) on success,
- *         Negative value(#cal_error) on error
- * @exception None.
- * @remarks None.
- * @pre database connected and calendar_svc_begin_trans() is called.
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-               //connect to database
-       calendar_svc_connect();
-
-               // begin transaction
-               calendar_svc_begin_trans();
-
-       //..do some operation to database
-
-       // end transaction
-               calendar_svc_end_trans(true);
-
-       //close database
-       calendar_svc_close();
-
-   }
- * @endcode
- * @see calendar_svc_begin_trans().
- */
-int calendar_svc_end_trans(bool is_success);
-
-
-/**
- * @fn int calendar_svc_subscribe_db_change (const char *data_type,void(*cb)(void *), void *user_data);
- * This function registers callback function in receiver,it is convenient for user receive noti from database.
- *
- * @ingroup service_management
- * @param[in]  datatype for subscribe detail db change
- * @param[in]  cb Fuction pointer of calendar notification callback
- * @param[in]  user_data when cb function is called, user_data will be passed.
- * @return   This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   #include <glib.h>
-
-   int received_cb (void *user_data)
-   {
-         if(NULL != user_data)
-         {
-               printf("enter received_cb:%s\n",(char*)user_data);
-         }
-   }
-
-   void sample_code()
-   {
-      //connect database
-      calendar_svc_connect();
-
-      char* user_data = "Get a noti!\n";
-       calendar_svc_subscribe_db_change (CAL_STRUCT_SCHEDULE,received_cb, user_data);
-
-         GMainLoop* loop = g_main_loop_new(NULL,TRUE);
-
-         //close database
-         calendar_svc_close();
-   }
- * @endcode
- * @see calendar_svc_unsubscribe_db_change().
- */
-int calendar_svc_subscribe_db_change (const char *data_type,void(*cb)(void *), void *user_data);
-
-
-int calendar_svc_subscribe_change (void(*cb)(void *), void *user_data);
-
-
-/**
- * @fn int calendar_svc_unsubscribe_db_change (const char *data_type,void(*cb)(void *));
- * This function deregisters callback function in receiver,it is convenient for user unscribe some receive noti from database.
- *
- * @ingroup service_management
- * @param[in]  datatype for subscribe detail db change
- * @param[in]  cb Fuction pointer of calendar notification callback
- * @return   This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre calendar_svc_subscribe_change called
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-
-   int received_cb (void *user_data)
-   {
-         if(NULL != user_data)
-         {
-               printf("enter received_cb:%s\n",(char*)user_data);
-         }
-   }
-
-   void sample_code()
-   {
-       //connect database
-          calendar_svc_connect();
-
-          char* user_data = "Get a noti!\n";
-          calendar_svc_unsubscribe_db_change (CAL_STRUCT_SCHEDULE,received_cb, user_data);
-
-          cal_struct * event = calendar_svc_struct_new(CAL_STRUCT_SCHEDULE);
-          calendar_svc_insert(event);
-
-          GMainLoop* loop = g_main_loop_new(NULL,TRUE);
-          g_main_loop_run(loop);
-
-          //...
-
-          //close database
-          calendar_svc_close();
-          calendar_svc_unsubscribe_db_change (CAL_STRUCT_SCHEDULE,received_cb);
-   }
- * @endcode
- * @see calendar_svc_subscribe_change().
- */
-int calendar_svc_unsubscribe_db_change (const char *data_type,void(*cb)(void *));
-
-
-int calendar_svc_unsubscribe_change (void(*cb)(void *));
-
-
-
-/**
- * @defgroup event_management event_management
- * @ingroup CALENDAR_SVC
- * @brief
- *             major data access api
- */
-
-
-/**
- * @fn int calendar_svc_insert(cal_struct *record);
- * This function insert records to database,user can save event through calling it.
- *
- * @ingroup event_management
- * @param[in] record calendar data for add
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks event should .
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-         //connect to database
-         calendar_svc_connect();
-
-         //create the variable
-         cal_struct* event = calendar_svc_struct_new("schedule");
-
-         //insert the event
-         calendar_svc_insert(event);
-
-         //close database
-         calendar_svc_close();
-   }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_insert(cal_struct *record);
-
-
-
-/**
- * @fn int calendar_svc_update(cal_struct *record);
- * This function updates record to database,it is convenient for user to update some record.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] record calendar data for update
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-         cal_struct* event = NULL;
-         int index = 1;
-
-         //connect to database
-         calendar_svc_connect();
-
-         //get the record whose index is 1
-         calendar_svc_get("schedule",index,NULL,&event);
-
-         //modify the summary
-         calendar_svc_struct_set_str(event,"summary","weekend");
-
-         //update
-         calendar_svc_update(event);
-
-         //free
-         calendar_svc_free(&evnet);
-
-         //close database
-         calendar_svc_close();
-   }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_update(cal_struct *record);
-
-/**
- * @fn int calendar_svc_delete(const char *data_type,int index);
- * This function delete records from database,it is convenient for user to delete some record.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] data_type sepecific record type
- * @param[in] index event db index
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-         int index = 1;
-
-         //connect to database
-         calendar_svc_connect();
-
-         //delete the record whose index is 1
-         calendar_svc_delete("schedule",index);
-
-         //free
-         calendar_svc_free(&evnet);
-
-         //close database
-         calendar_svc_close();
-   }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_delete(const char *data_type,int index);
-
-/**
- * @fn int calendar_svc_delete_all(int account_id,const char *data_type);
- * This function delete all records from database,it is convenient for user to delete all of records.
- * local account deletes data immediately but the others set is_deleted parameter 1.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] account_id account db index
- * @param[in] data_type detail data type(eg. CAL_STRUCT_CALENDAR,CAL_STRUCT_SCHEDULE, NULL), if null delete all data by account_id
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-         //connect to database
-         calendar_svc_connect();
-
-         //delete the all records of schudule_table
-         calendar_svc_delete_all(0,"schedule");
-
-         //close database
-         calendar_svc_close();
-   }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_delete_all(int account_id,const char *data_type);
-
-/**
- * @fn int calendar_svc_delete_account(int account_id);
- * This function delete all records from database,it is convenient for user to delete all of records according to account.
- * local account deletes data immediately but the others set is_deleted parameter 1.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] account_id account db index
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-         //connect to database
-         calendar_svc_connect();
-
-         //delete the all records of schudule_table
-         calendar_svc_delete_account(0);
-
-         //close database
-         calendar_svc_close();
-   }
- * @endcode
- * @see detail_management module
- */
-
-int calendar_svc_delete_account(int account_id);
-
-
-/**
- * @fn int calendar_svc_clean_after_sync(int calendar_id);
- * This function clean deleted(marked) all records from database,which is used to remove data from database after sync operation.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] account_id calendar id
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-         //connect to database
-         calendar_svc_connect();
-
-         //delete the all records from schudule_table
-         calendar_svc_clean_after_sync(0);
-
-         //close database
-         calendar_svc_close();
-   }
- * @endcode
- * @see detail_management module
- */
-
-int calendar_svc_clean_after_sync(int calendar_id);
-
-/**
- * @fn int calendar_svc_get(const char *data_type,int index,const char *field_list, cal_struct **record);
- * This function get records from database,user can get event from database through calling it.
- *
- * @ingroup event_management
- * @return This function returns inserted contact id or error code on failure.
- * @param[in] data_type sepecific record type
- * @param[in] index db index
- * @param[in] field_list specific field list(eg. "summary,description"), if NULL, all field is returned.
- * @param[out] record calendar data , it should be free by calendar_svc_struct_free
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks event should .
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-         int index = 1;
-         cal_struct* event = NULL;
-
-         //connect to database
-         calendar_svc_connect();
-
-         //get the record whose index is 1
-         calendar_svc_get("schedule",index,NULL, &event);
-
-         //free the space
-         calendar_svc_struct_free(&event);
-
-         //close database
-         calendar_svc_close();
-   }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_get(const char *data_type,int index,const char *field_list, cal_struct **record);
-
-/**
- * @fn int calendar_svc_get_count(int account_id,int calendar_id,const char *data_type);
- * This function get count of records from database,user can get the count through calling it.
- *
- * @ingroup event_management
- * @return Integer value, or 0 if no value is obtained
- * @param[in] account_id account db index
- * @param[in] calendar_id calendar id(will be support phase 2)
- * @param[in] data_type data_type(CAL_STRUCT_CALENDAR or CAL_STRUCT_SCHEDULE)
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks event should .
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-         int count = -1;
-
-         //connect to database
-         calendar_svc_connect();
-
-         //get the count of all
-         count = calendar_svc_get_count(0,0,"shchedule");
-
-         //close database
-         calendar_svc_close();
-   }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_get_count(int account_id,int calendar_id,const char *data_type);
-
-int calendar_svc_calendar_get_count(int account_id);
-int calendar_svc_event_get_count(int calendar_id);
-int calendar_svc_todo_get_count(int calendar_id);
-
-/**
- * @fn int calendar_svc_get_all(int account_id,int calendar_id,const char *data_type, cal_iter **iter);
- * This function get all records from database,it is convenient for user to get all of the reocrds once.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] account_id account db index
- * @param[in] calendar_id calendar id. If account_id is set, the account_id will be ignore.
- * @param[in] data_type data_type(CAL_STRUCT_CALENDAR or CAL_STRUCT_SCHEDULE)
- * @param[out] iter calendar data
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks event should .
- * @pre database connected
- * @post call calendar_svc_iter_remove() when leave
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-         cal_iter *iter = NULL;
-
-         //connect to database
-         calendar_svc_connect();
-
-         //get all records
-         calendar_svc_get_all(0,0,"schedule", &iter);
-
-         //free
-         calendar_svc_iter_remove(&iter);
-
-         //close database
-         calendar_svc_close();
-   }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_get_all(int account_id,int calendar_id,const char *data_type, cal_iter **iter);
-
-/**
- * @fn int calendar_svc_event_get_changes(int calendar_id, int version, cal_iter **iter);
- * This function provides the iterator to get all changes later than the version.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] calendar_id calendar ID
- * @param[in] version version number
- * @param[out] iter interation struct for list travel
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   #include <stdio.h>
-   void sample_code()
-   {
-      int ret;
-      cal_struct *cs;
-      cal_iter *it;
-      int id, type, ver;
-
-      calendar_svc_event_get_changes(1, 0, &it);
-
-      while (calendar_svc_iter_next(it) == CAL_SUCCESS) {
-         cs = NULL;
-         ret = calendar_svc_iter_get_info(it, &cs);
-         if (ret != CAL_SUCCESS) {
-            printf("calendar_svc_iter_get_info failed (%d)\n", ret);
-            return -1;
-         }
-         id = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_ID);
-         type = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_TYPE);
-         ver = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_VERSION);
-         printf("type = %d id = %d ver = %d\n", id, type, ver);
-         calendar_svc_struct_free(&cs);
-      }
-      calendar_svc_iter_remove(&it);
-   }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_event_get_changes(int calendar_id, int version, cal_iter **iter);
-
-/**
- * @fn int calendar_svc_todo_get_changes(int calendar_id, int version, cal_iter **iter);
- * This function provides the iterator to get all changes later than the version.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] calendar_id calendar ID
- * @param[in] version version number
- * @param[out] iter interation struct for list travel
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   #include <stdio.h>
-   void sample_code()
-   {
-      int ret;
-      cal_struct *cs;
-      cal_iter *it;
-      int id, type, ver;
-
-      calendar_svc_todo_get_changes(1, 0, &it);
-
-      while (calendar_svc_iter_next(it) == CAL_SUCCESS) {
-         cs = NULL;
-         ret = calendar_svc_iter_get_info(it, &cs);
-         if (ret != CAL_SUCCESS) {
-            printf("calendar_svc_iter_get_info failed (%d)\n", ret);
-            return -1;
-         }
-         id = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_ID);
-         type = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_TYPE);
-         ver = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_VERSION);
-         printf("type = %d id = %d ver = %d\n", id, type, ver);
-         calendar_svc_struct_free(&cs);
-      }
-      calendar_svc_iter_remove(&it);
-   }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_todo_get_changes(int calendar_id, int version, cal_iter **iter);
-
-int calendar_svc_convert_id_to_uid(const char *data_type,int index,char **uid);
-
-/**
- * @fn int calendar_svc_iter_get_info(cal_iter *iter, cal_struct **row_record);
- * This function get cal_value by cal_iter,it is convenient for user to get event from iter.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] iter interation struct for list travel
- * @param[out] row_record detail information
- * @exception None.
- * @remarks row_record should be free with calendar_svc_struct_free
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-         cal_iter *iter = NULL;
-         cal_struct* evnet = NULL;
-
-         //connect to database
-         calendar_svc_connect();
-
-         //get all records
-         calendar_svc_get_all(0,0,"schedule", &iter);
-
-         //get events
-         calendar_svc_iter_get_info(iter, &event);
-
-         //free
-         calendar_svc_iter_remove(&iter);
-
-         //close database
-         calendar_svc_close();
-   }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_iter_get_info(cal_iter *iter, cal_struct **row_record);
-
-
-/**
- * @fn int calendar_svc_iter_next(cal_iter *iter);
- * This function get cal_value by cal_iter,it is convenient for user to get record one by one.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] iter interation struct for list travel
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-         cal_iter *iter = NULL;
-         cal_struct* evnet = NULL;
-
-         //connect to database
-         calendar_svc_connect();
-
-         //get all records
-         calendar_svc_get_all(0,0,"schedule", &iter);
-
-         //get events
-         calendar_svc_iter_get_info(iter, &event);
-
-         //get next event
-         calendar_svc_iter_next(iter);
-         calendar_svc_iter_get_info(iter, &event);
-
-         //free
-         calendar_svc_iter_remove(&iter);
-
-         //close database
-         calendar_svc_close();
-   }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_iter_next(cal_iter *iter);
-
-
-/**
- * @fn int calendar_svc_iter_remove(cal_iter **iter);
- * This function remove db iteration struct,it is convenient for user to avoid memory leak.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] iter interation struct for list travel
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @code
-   #include <calendar-svc-provider.h>
-   void sample_code()
-   {
-         cal_iter *iter = NULL;
-
-         //connect to database
-         calendar_svc_connect();
-
-         //get all records
-         calendar_svc_get_all(0,0,"schedule", &iter);
-
-         //free
-         calendar_svc_iter_remove(&iter);
-
-         //close database
-         calendar_svc_close();
-   }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_iter_remove(cal_iter **iter);
-
-/**
- * @defgroup detail_management detail_management
- * @ingroup CALENDAR_SVC
- * @brief
- *             deatil field access api
- */
-
-
-/**
- * @fn cal_struct * calendar_svc_struct_new(const char *data_type);
- * This function alloc calendar struct,it is convenient for user to create an event.
- *
- * @ingroup detail_management
- * @return This function returns allocated event struct
- * @param[in] data_type (eg.CAL_EVENT_TYPE_SCHEDULE,CAL_EVENT_TYPE_CALENDAR..)
- * @exception None.
- * @remarks it should be free with calendar_svc_struct_free
- * @pre cal_struct variable is defined.
- * @post None.
- * @remarks None.
- * @code
-   #include <calendar_svc_provider.h>
-   void sample_code()
-   {
-       //connect to database
-       calendar_svc_connect();
-
-       //create variable
-    cal_struct * event = calendar_svc_struct_new("schedule");
-
-    //free the space
-    calendar_svc_struct_free(&event);
-
-       //close the database
-       calendar_svc_close();
-   }
- * @endcode
- * @see calendar_svc_struct_free().
- */
-cal_struct * calendar_svc_struct_new(const char *data_type);
-
-/**
- * @fn int calendar_svc_struct_free(cal_struct **record);
- * This function is used to free space malloced to cal_struct variable,it is convenient for user to avoid memory leak when using cal_struct.
- *
- * @ingroup detail_management
- * @param[in] record Point to alloced address
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @pre cal_struct variable is defined.
- * @post None.
- * @remarks None.
- * @code
-   #include <calendar_svc_provider.h>
-   void sample_code()
-   {
-       //connect to database
-       calendar_svc_connect();
-
-       //create variable
-    cal_struct * event = calendar_svc_struct_new("schedule");
-
-    //free the space
-    calendar_svc_struct_free(&event);
-
-       //close the database
-       calendar_svc_close();
-   }
- * @endcode
- * @see common, CAL_STRUCT_TYPE , calendar_svc_struct_new.
- */
-int calendar_svc_struct_free(cal_struct **record);
-
-
-/**
- * @fn int calendar_svc_struct_get_str(cal_struct* record, const char* field);
- * This function gets the point of string value of the calendar service value,it is convenient for user get the value needed without knowing the detail of the struct.
- *
- * @ingroup detail_management
- * @param[in] record Point to The calendar struct
- * @param[in] field The index of the string value in calendar service value.
- * @return string value(should not be freed), or NULL if no value is obtained
- * @remarks if parent cal_struct is destroyed, return string is not valid.
- * @pre cal_struct varibale is defined.
- * @post none
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               char* summary = NULL;
-               index = 1;
-               cal_struct* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //get the record
-               calendar_svc_get("schedule",index,NULL,&event);
-
-               //get the str value
-               summary = calendar_svc_struct_get_str(event,CAL_VALUE_TXT_SUMMARY);
-
-               //free space
-               calendar_svc_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_struct_set_str().
- */
-char *calendar_svc_struct_get_str(cal_struct* record, const char *field);
-
-/**
- * @fn int calendar_svc_struct_get_int(cal_struct* record, const char* field);
- * This function gets Integer value of the calendar service value,it is convenient for user get the value needed without knowing the detail of the struct.
- *
- * @ingroup detail_management
- * @param[in] record Point to The calendar struct
- * @param[in] field The index of the integer value in calendar service value.
- * @return Integer value, or 0 if no value is obtained
- * @remarks none
- * @pre cal_struct varibale is defined.
- * @post none
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               int account_id = 0;
-               index = 1;
-               cal_struct* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //get the record
-               calendar_svc_get("schedule",index,NULL,&event);
-
-               //get the int value
-               account_id = calendar_svc_struct_get_int(event,CAL_VALUE_INT_ACCOUNT_ID);
-
-               //free space
-               calendar_svc_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_struct_set_int().
- */
-int calendar_svc_struct_get_int(cal_struct* record, const char *field);
-
-
-/**
- * @fn double calendar_svc_struct_get_double(cal_struct* record, const char* field);
- * This function gets double value of the calendar service value,it is convenient for user get the value needed without knowing the detail of the struct.
- *
- * @ingroup detail_management
- * @param[in] record Point to The calendar struct
- * @param[in] field The index of the integer value in calendar service value.
- * @return double value, or 0.0 if no value is obtained
- * @remarks none
- * @pre cal_struct varibale is defined.
- * @post none
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               double latitude = 0.0;
-               index = 1;
-               cal_struct* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //get the record
-               calendar_svc_get("schedule",index,NULL,&event);
-
-               //get the double value
-               latitude = calendar_svc_struct_get_double(event,CAL_VALUE_DBL_LATITUDE);
-
-               //free space
-               calendar_svc_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_struct_set_double().
- */
-double calendar_svc_struct_get_double(cal_struct* record, const char *field);
-
-
-/**
- * @fn int calendar_svc_struct_set_double(cal_struct* record, const char* field,double value);
- * This function sets double value of the calendar service value,it is convenient for user set the value without knowing the detail of the struct.
- *
- * @ingroup detail_management
- * @param[in] record Point to The calendar struct
- * @param[in] field The index of the integer value in calendar service value.
- * @param[in] value The dobule value to be set.
- * @return Integer value, or 0 if no value is obtained
- * @remarks none.
- * @pre cal_struct variable is defined.
- * @post the corresponding value of cal_struct is set.
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               double latitude = 3.14;
-               index = 0;
-               cal_struct* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //create a cal_struct variable
-               event = calendar_svc_struct_new("schedule");
-
-               //set the double value
-               calendar_svc_set_double(event,CAL_VALUE_DBL_LATITUDE,latitude);
-
-               //insert the record
-               index = calendar_svc_insert(event);
-
-               //free the space
-               calendar_svc_struct_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_struct_get_double().
- */
-int calendar_svc_struct_set_double(cal_struct* record, const char *field,double value);
-
-
-/**
- * @fn int calendar_svc_struct_set_int(cal_struct* record, const char* field, int intval);
- * This function sets integer value to the calendar service value,it is convenient for user set the value without knowing the detail of the struct.
- *
- * @ingroup detail_management
- * @param[in] record Point to The calendar struct
- * @param[in] field The index of the integer value in calendar service value.
- * @param[in] intval The integer value to be set.
- * @return     This function returns CAL_SUCCESS or error code on failure.
- * @remarks none.
- * @pre cal_struct variable is defined.
- * @post the corresponding value of cal_struct is set.
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               int account_id = 1;
-               index = 0;
-               cal_struct* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //create a cal_struct variable
-               event = calendar_svc_struct_new("schedule");
-
-               //set the int value
-               calendar_svc_set_int(event,CAL_VALUE_INT_ACCOUNT_ID,account_id);
-
-               //insert the record
-               index = calendar_svc_insert(event);
-
-               //free the space
-               calendar_svc_struct_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_struct_get_int().
- */
-int calendar_svc_struct_set_int(cal_struct* record, const char *field, int intval);
-
-/**
- * @fn int calendar_svc_struct_set_str(cal_struct* record, const char* field, const char *strval);
- * This function sets string value to the calendar service value,it is convenient for user set the value without knowing the detail of the struct.
- * If it is in struct, free old string and copy strval to struct.
- *
- * @ingroup detail_management
- * @param[in] record Point to The calendar struct
- * @param[in] field The index of the string value in calendar service value.
- * @param[in] strval The string value to be set.
- * @return     This function returns CAL_SUCCESS or error code on failure.
- * @remarks none.
- * @pre cal_struct variable is defined.
- * @post the corresponding value of cal_struct is set.
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               char* summary = "party";
-               index = 0;
-               cal_struct* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //create a cal_struct variable
-               event = calendar_svc_struct_new("schedule");
-
-               //set the string value
-               calendar_svc_set_str(event,CAL_VALUE_TXT_SUMMARY,summary);
-
-               //insert the record
-               index = calendar_svc_insert(event);
-
-               //free the space
-               calendar_svc_struct_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_struct_get_str().
- */
-int calendar_svc_struct_set_str(cal_struct* record, const char *field, const char *strval);
-
-
-/**
- * @fn int calendar_svc_struct_get_list(cal_struct* record, const char* field, GList** retlist);
- * This function gets the point of glib double-linked list in the calendar service struct,it is convenient for user get the value without knowing the detail of the struct.
- *
- * @ingroup detail_management
- * @param[in] record structure A calendar service struct
- * @param[in] field The index of the glib singly-linked list in calendar service struct.
- * @param[out] retlist the glib singly-linked list requested with field(should not be freed or removed)
- * @return     This function returns CAL_SUCCESS or error code on failure.
- * @remarks if parent cal_struct is destroyed, retlist is not valid.
- * @pre cal_struct variable is defined.
- * @post none.
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               GList* list = NULL;
-               index = 1;
-               cal_struct* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //get the record
-               calendar_svc_get("schedule",index,NULL,&event);
-
-               //get the list
-               calendar_svc_struct_get_list(event,"attendee_list",&list);
-
-               //free the space
-               calendar_svc_struct_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_struct_store_list().
- */
-int calendar_svc_struct_get_list(cal_struct* record,const char *field, GList** retlist);
-
-/**
- * @fn int calendar_svc_struct_store_list(cal_struct* record, const char* field, GList* list)
- * This function sets the glib double-linked list to the calendar service struct,it is convenient for user set the value.
- * \n Values(cal_value) of the list are moved to the calendar service struct. But the list is copied.
- *
- * @ingroup detail_management
- * @param[in] record structure A calendar service struct
- * @param[in] field The index of the glib singly-linked list in calendar service struct.
- * @param[in] list the glib singly-linked list to be set
- * @return     This function returns CAL_SUCCESS or error code on failure.
- * @remarks if parent cal_struct is destroyed, GSList is not valid.
- * @pre cal_struct variable is defined.
- * @post none.
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               GList* list = NULL;
-               index = 1;
-               cal_struct* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //create the event
-               event = calendar_svc_struct_new("schedule");
-
-               //set the list
-               calendar_svc_struct_store_list(event,"attendee_list",list);
-
-               //free the space
-               calendar_svc_struct_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_struct_get_list().
- */
-int calendar_svc_struct_store_list(cal_struct* record,const char *field, GList* list);
-
-/**
- * @fn int calendar_svc_value_new(const char* val_type);
- * Allocate, initialize and return a new calendar service value,it is convenient for user to create a calendar service value.
- *
- * @ingroup detail_management
- * @param[in] val_type The type of calendar service value
- * @return The pointer of New calendar service value, NULL on error
- * @remarks none.
- * @pre none.
- * @post none.
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               GList* list = NULL;
-               index = 1;
-               cal_value* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //create the event
-               event = calendar_svc_value_new("attendee_list");
-
-               //set the list
-               list = g_list_append(list,event);
-               calendar_svc_struct_store_list(event,"attendee_list",list);
-
-               //free the space
-               calendar_svc_value_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_value_free().
- */
-cal_value* calendar_svc_value_new(const char *val_type);
-
-/**
- * @fn int calendar_svc_value_free(cal_value** value);
- * A destructor for calendar service value,,it is convenient for user to free the space allocated.
- * If it is in struct, return CAL_ERR_ARG_INVALID.
- *
- * @ingroup detail_management
- * @param[in] value A calendar service value
- * @return     This function returns CAL_SUCCESS or error code on failure.
- * @remarks none.
- * @pre cal_value variable is defined.
- * @post none.
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               GList* list = NULL;
-               index = 1;
-               cal_value* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //create the event
-               event = calendar_svc_value_new("attendee_list");
-
-               //set the list
-               list = g_list_append(list,event);
-               calendar_svc_struct_store_list(event,"attendee_list",list);
-
-               //free the space
-               calendar_svc_value_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_value_new().
- */
-int calendar_svc_value_free(cal_value** value);
-
-/**
- * @fn int calendar_svc_value_set_int(cal_value* value, const char* field, int intval);
- * This function sets integer value to the calendar service value,it is convenient for user set value of cal_value varible.
- *
- * @ingroup detail_management
- * @param[in] value The calendar service value
- * @param[in] field The index of the integer value in calendar service value.
- * @param[in] intval The integer value to be set.
- * @return     This function returns CAL_SUCCESS or error code on failure.
- * @remarks none.
- * @pre cal_value variable is defined.
- * @post none.
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               GList* list = NULL;
-               index = 1;
-               cal_value* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //create the event
-               event = calendar_svc_value_new("attendee_list");
-               calendar_svc_value_set_int(event,"attendee_status",1);
-
-               //set the list
-               list = g_list_append(list,event);
-               calendar_svc_struct_store_list(event,"attendee_list",list);
-
-               //free the space
-               calendar_svc_value_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_value_get_int().
- */
-int calendar_svc_value_set_int(cal_value* value, const char *field, int intval);
-
-int calendar_svc_value_set_lli (cal_value *value, const char *field, long long int llival);
-long long int calendar_svc_value_get_lli (cal_value *value, const char *field);
-/**
- * @fn int calendar_svc_value_set_str(cal_value* value, const char* field, const char *strval);
- * This function sets string value to the calendar service value,it is convenient for user set value of cal_value varible.
- * If it is in struct, free old string and copy strval to struct.
- *
- * @ingroup detail_management
- * @param[in] value The calendar service value
- * @param[in] field The index of the string value in calendar service value.
- * @param[in] strval The string value to be set.
- * @return     This function returns CAL_SUCCESS or error code on failure.
- * @remarks none.
- * @pre cal_value variable is defined.
- * @post none.
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               GList* list = NULL;
-               index = 1;
-               cal_value* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //create the event
-               event = calendar_svc_value_new("attendee_list");
-               calendar_svc_value_set_str(event,"attendee_name","Max");
-
-               //set the list
-               list = g_list_append(list,event);
-               calendar_svc_struct_store_list(event,"attendee_list",list);
-
-               //free the space
-               calendar_svc_value_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_value_get_str().
- */
-int calendar_svc_value_set_str(cal_value* value, const char *field, const char *strval);
-
-
-/**
- * @fn int calendar_svc_value_get_int(cal_value* value, const char* field);
- * This function gets Integer value of the calendar service value,it is convenient for user get value of cal_value varible.
- *
- * @ingroup detail_management
- * @param[in] value The calendar service value
- * @param[in] field The index of the integer value in calendar service value.
- * @return Integer value, or 0 if no value is obtained
- * @remarks none.
- * @pre cal_value variable is defined.
- * @post none.
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               int type = 0;
-               cal_value* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //create the event
-               event = calendar_svc_value_new(CAL_VALUE_LST_ATTENDEE_LIST);
-
-               //get the type value
-               type = calendar_svc_value_get_int(event,
-                       CAL_VALUE_INT_ATTENDEE_DETAIL_TYPE);
-
-               //free the space
-               calendar_svc_value_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_value_set_int().
- */
-int calendar_svc_value_get_int(cal_value* value, const char *field);
-
-/**
- * @fn char* calendar_svc_value_get_str(cal_value* value, const char* field);
- * This function gets the point of string value of the calendar service value,it is convenient for user get value of cal_value varible.
- *
- * @ingroup detail_management
- * @param[in] value The calendar service value
- * @param[in] field The index of the string value in calendar service value.
- * @return string value(should not be freed), or NULL if no value is obtained
- * @remarks none.
- * @pre cal_value variable is defined.
- * @post none.
- * @code
-       #include <calendar-svc-provider.h>
-       void sample_code()
-       {
-               char* name = "money";
-               cal_value* event = NULL;
-
-               //connect to database
-               calendar_svc_connect();
-
-               //create the event
-               event = calendar_svc_value_new(CAL_VALUE_LST_ATTENDEE_LIST);
-
-               //get the event_id value
-               name = calendar_svc_value_get_str(event,
-                       CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME);
-
-               //free the space
-               calendar_svc_value_free(&event);
-
-               //close database
-               calendar_svc_close();
-       }
- * @endcode
- * @see calendar_svc_value_set_str().
- */
-char *calendar_svc_value_get_str(cal_value* value, const char *field);
-
-/**
- * @fn int calendar_svc_util_convert_event_to_vcs (cal_struct *record,char **raw_data,int *data_size);
- * This function converts data (cal_struct(event) to raw_data(vcal format)),it is convenient for user to convert.
- *
- * @ingroup utilities
- * @param[in] record      original record type
- * @param[out] raw_data            vcalendar event raw data
- * @param[out] data_size          raw_data buf size
- * @return      This function returns CAL_SUCCESS or error code on failure.
- * @remarks none
- * @pre none.
- * @post none
- * @code
-       #include <calendar_svc_provider.h>
-       void sample_code()
-       {
-               char raw_data = NULL;
-               int data_size = 0;
-
-               //connect to database
-               calendar_svc_connect();
-
-               cal_struct* event = NULL;
-
-               //get the record
-               calendar_svc_get("schedule",1,NULL,&event);
-
-               //convert
-               calendar_svc_util_convert_event_to_vcs (event,&raw_data,&data_size);
-
-               calendar_svc_struct_free(&event);
-
-               //close to database
-               calendar_svc_close();
-       }
- * @endcode
- */
-DEPRECATED int calendar_svc_util_convert_event_to_vcs (cal_struct *record,char **raw_data,int *data_size);
-
-
-/**
- * @fn int calendar_svc_find_event_list(int account_id,const char* search_type,const void* search_value, cal_iter **iter);
- * This function get records from database by search param,it is convenient for user to get records according to some condition.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] account_id account db index
- * @param[in] search_type event search type(eg. CAL_VALUE_SUMMARY or CAL_VALUE_DESCRIPTION,..)
- * @param[in] search_value event search value(eg. "weekly report", etc.. ), it can be integer value(eg. 1 or 2.. etc)
- * @param[out] iter interation struct for list travel
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @code
-  #include <calendar-svc-provider.h>
-  void sample_code()
-  {
-        cal_iter *iter = NULL;
-
-        //connect to database
-        calendar_svc_connect();
-
-        //find event whose summary including string like "party"
-        calendar_svc_find_event_list(0,"summary","party", &iter);
-
-        //free
-        calendar_svc_iter_remove(&iter);
-
-        //close database
-        calendar_svc_close();
-  }
- * @endcode
- * @see detail_management module
- * @deprecated it will replacement calendar_svc_find_list
- */
-int calendar_svc_find_event_list(int account_id,const char *search_type,const void* search_value, cal_iter **iter);
-
-/**
- * @fn int calendar_svc_event_search(int field, const char *keyword, cal_iter **iter);
- * #calendar_svc_event_search searches events including the keyword in given fields.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] field fields where the keyword is searched.  #SEARCHFIELD
- * @param[in] keyword keyword to be searched
- * @param[out] iter interation struct for list travel
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @code
-  #include <calendar-svc-provider.h>
-  void sample_code()
-  {
-       int ret;
-       cal_struct *cs;
-       cal_iter *it;
-       char *summary;
-       char *desc;
-       int id;
-
-       calendar_svc_connect();
-       int search_field;
-
-       search_field = CALS_SEARCH_FIELD_NONE;
-       search_field |= CALS_SEARCH_FIELD_SUMMARY;
-       search_field |= CALS_SEARCH_FIELD_DESCRIPTION;
-       search_field |= CALS_SEARCH_FIELD_LOCATION;
-       search_field |= CALS_SEARCH_FIELD_ATTENDEE;
-
-       ret = calendar_svc_event_search(search_field, "Hello", &it);
-       if (ret < 0)
-               return -1;
-
-       while (calendar_svc_iter_next(it) == CAL_SUCCESS) {
-               cs = NULL;
-               ret = calendar_svc_iter_get_info(it, &cs);
-               if (ret != CAL_SUCCESS) {
-                       printf("calendar_svc_iter_get_info failed (%d)\n", ret);
-                       return -1;
-               }
-
-               id = calendar_svc_struct_get_int(cs, CAL_VALUE_INT_INDEX);
-               summary = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_SUMMARY);
-               desc = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_DESCRIPTION);
-               printf("type = %d id = %s desc = %s\n", id, summary, desc);
-               calendar_svc_struct_free(&cs);
-       }
-
-       calendar_svc_iter_remove(&it);
-
-       calendar_svc_close();
-
-       return 0;
-  }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_event_search(int field, const char *keyword, cal_iter **iter);
-
-/**
- * @fn int calendar_svc_smartsearch_excl(const char *keyword, int offset, int limit, cal_iter **iter)
- * Search events by keyword with database offset and limit option.
- * This function is provided for Smartsearch application exclusively.
- *
- * @ingroup event_management
- * @return CAL_SUCCESS or negative error code on failure.
- * @param[in] field fields where the keyword is searched, #SEARCHFIELD
- * @param[in] keyword keyword to be searched
- * @param[in] offset offset to omit some searching results
- * @param[in] limit limit of the number of results. If negative, no limit is applied.
- * @param[out] iter interation struct for list travel
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @see detail_management module
- */
-int calendar_svc_smartsearch_excl(const char *keyword, int offset, int limit, cal_iter **iter);
-
-/**
- * @fn int calendar_svc_todo_search(int field, const char *keyword, cal_iter **iter);
- * #calendar_svc_event_search searches TO-DOs including the keyword in given fields.
- *
- * @ingroup event_management
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @param[in] field fields where the keyword is searched, #SEARCHFIELD
- * @param[in] keyword keyword to be searched
- * @param[out] iter interation struct for list travel
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @exception None.
- * @remarks None.
- * @pre database connected
- * @post none
- * @code
-  #include <calendar-svc-provider.h>
-  void sample_code()
-  {
-       int ret;
-       cal_struct *cs;
-       cal_iter *it;
-       char *summary;
-       char *desc;
-       int id;
-
-       calendar_svc_connect();
-       int search_field;
-
-       search_field = CALS_SEARCH_FIELD_NONE;
-       search_field |= CALS_SEARCH_FIELD_SUMMARY;
-       search_field |= CALS_SEARCH_FIELD_DESCRIPTION;
-       search_field |= CALS_SEARCH_FIELD_LOCATION;
-       search_field |= CALS_SEARCH_FIELD_ATTENDEE;
-
-       ret = calendar_svc_todo_search(search_field, "Hello", &it);
-       if (ret < 0)
-               return -1;
-
-       while (calendar_svc_iter_next(it) == CAL_SUCCESS) {
-               cs = NULL;
-               ret = calendar_svc_iter_get_info(it, &cs);
-               if (ret != CAL_SUCCESS) {
-                       printf("calendar_svc_iter_get_info failed (%d)\n", ret);
-                       return -1;
-               }
-
-               id = calendar_svc_struct_get_int(cs, CAL_VALUE_INT_INDEX);
-               summary = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_SUMMARY);
-               desc = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_DESCRIPTION);
-               printf("type = %d id = %s desc = %s\n", id, summary, desc);
-               calendar_svc_struct_free(&cs);
-       }
-
-       calendar_svc_iter_remove(&it);
-
-       calendar_svc_close();
-
-       return 0;
-  }
- * @endcode
- * @see detail_management module
- */
-int calendar_svc_todo_search(int field, const char *keyword, cal_iter **iter);
-
-/**
- * @fn int calendar_svc_read_schedules(const char *stream, GList **schedules);
- * This function reads schedules and provides schedule list.
- *
- * @ingroup event management
- * @param[in] stream vcalendar(ver1.0) icalendar(ver2.0) stream
- * @param[out] schedules schedule list which data is cal_struct
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @remarks none
- * @pre none
- * @post none
- * @code
-       #include <stdio.h>
-       #include <stdlib.h>
-       #include <calendar-svc-provider.h>
-
-       void sample_code()
-       {
-               int ret, len = 0;
-               char *vals;
-               char *stream = NULL;
-               char buf[1024];
-               time_t tt;
-               cal_struct *cs = NULL;
-               GList *l, *schedules = NULL;
-               buf_size = 1024;
-               FILE *file;
-
-               file = fopen(path, "r");
-               if (file == NULL) {
-                       printf("failed to open\n");
-                       return -1;
-               }
-               stream = malloc(1024);
-               while (fgets(buf, sizeof(buf), file)) {
-                       if (len + sizeof(buf) < buf_size) {
-                               len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
-
-                       } else {
-                               char *new_stream;
-                               buf_size *= 2;
-                               new_stream = realloc(stream, buf_size);
-                               if (new_stream) {
-                                       stream = new_stream;
-                               } else {
-                                       free(stream);
-                                       fclose(file);
-                                       printf("out of memory\n");
-                                       return NULL;
-                               }
-                               len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
-                       }
-               }
-               fclose(file);
-
-               ret = calendar_svc_read_schedules(stream, &schedules);
-               if (ret < 0) {
-                       printf("Failed to read schedules(errno:%d)\n", ret);
-                       return -1;
-               }
-
-               if (schedules == NULL) {
-                       printf("No schedules\n");
-                       return -1;
-               }
-
-               l = schedules;
-               while (l) {
-                       cs = l->data;
-                       if (cs == NULL) {
-                               l = g_list_next(l);
-                               continue;
-                       }
-                       vals = NULL;
-                       vals = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_SUMMARY);
-                       printf("summary:%s\n", vals);
-
-                       l = g_list_next(l);
-               }
-               if (stream) free(stream);
-               return 0;
-       }
- * @endcode
- * @see calendar_svc_write_schedules().
- */
-int calendar_svc_read_schedules(const char *stream, GList **schedules);
-
-/**
- * @fn int calendar_svc_calendar_import(const char *path, int calendar_id);
- * This function import vcalendar(ver 1.0), icalendar(ver 2.0) to calendar DB.
- *
- * @ingroup event management
- * @param[in] path file path
- * @param[out] calendar_id calendar id
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @remarks none
- * @pre none
- * @post none
- * @code
-       #include <stdio.h>
-       #include <stdlib.h>
-       #include <calendar-svc-provider.h>
-
-       int sample_code())
-       {
-               int r;
-               int calendar_id = 1;
-               char *path = "/opt/media/test.ics";
-
-       calendar_svc_connect();
-               ret = calendar_svc_calendar_import(path, calendar_id);
-               if (ret != CAL_SUCCESS) {
-                       printf("Failed to import path(%s) to id(%d)\n", path, calendar_id);
-                       return -1;
-               }
-       calendar_svc_close();
-               return 0;
-       }
- * @endcode
- * @see calendar_svc_calendar_export().
- */
-int calendar_svc_calendar_import(const char *path, int calendar_id);
-
-/**
- * @fn int calendar_svc_write_schedules(GList *schedules, char **stream);
- * This function writes schedules to stream.
- *
- * @ingroup event management
- * @param[in] schedules schedule list which data is cal_struct
- * @param[out] stream vcalendar(ver1.0) icalendar(ver2.0) stream
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @remarks none
- * @pre none
- * @post none
- * @code
-       #include <stdio.h>
-       #include <stdlib.h>
-       #include <calendar-svc-provider.h>
-
-       int main(int argc, char **argv)
-       {
-               int ret;
-               char *stream;
-               GList *schedules = NULL;
-               cal_struct *cs = NULL;
-
-               cs = calendar_svc_struct_new(CAL_STRUCT_CALENDAR);
-               if (cs == NULL) {
-                       printf("Failed to calloc\n");
-                       return-1;
-               }
-               calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_SUMMARY, "title");
-               // set data in cs...
-
-               schedules = g_list_append(schedules, cs);
-
-               ret = calendar_svc_write_schedules(schedules, &stream);
-               if (ret != CAL_SUCCESS) {
-                       printf("Failed to read schedules(errno:%d)\n", ret);
-                       return -1;
-               }
-
-               if (stream == NULL) {
-                       printf("stream is NULL\n");
-                       return -1;
-               }
-
-               if (stream) free(stream);
-               return 0;
-       }
- * @endcode
- * @see calendar_svc_read_schedules().
- */
-int calendar_svc_write_schedules(GList *schedules, char **stream);
-
-/**
- * @fn int calendar_svc_calendar_export(int calendar_id, const char *path);
- * This function export calendar DB to file.
- *
- * @ingroup event management
- * @param[in] calendar_id calendar id
- * @param[out] path file path
- * @return This function returns CAL_SUCCESS or error code on failure.
- * @remarks none
- * @pre none
- * @post none
- * @code
-       #include <stdio.h>
-       #include <stdlib.h>
-       #include <calendar-svc-provider.h>
-
-       int sample_code())
-       {
-               int r;
-               int calendar_id = 1;
-               char *path = "/opt/media/test.ics";
-
-       calendar_svc_connect();
-               r = calendar_svc_calendar_export(calendar_id, path);
-               if (r != CAL_SUCCESS) {
-                       printf("Failed to export schedules\n");
-                       return -1;
-               }
-
-       calendar_svc_close();
-               return 0;
-       }
- * @endcode
- * @see calendar_svc_calendar_import().
- */
-int calendar_svc_calendar_export(int calendar_id, const char *path);
-
-#define CALS_VALUE_INT_DTSTART_TYPE "dtstart_type"
-#define CALS_VALUE_LLI_DTSTART_UTIME "dtstart_utime"
-#define CALS_VALUE_INT_DTSTART_YEAR "dtstart_year"
-#define CALS_VALUE_INT_DTSTART_MONTH "dtstart_month"
-#define CALS_VALUE_INT_DTSTART_MDAY "dtstart_mday"
-#define CALS_VALUE_TXT_DTSTART_TZID "dtstart_tzid"
-#define CALS_VALUE_INT_DTEND_TYPE "dtend_type"
-#define CALS_VALUE_LLI_DTEND_UTIME "dtend_utime"
-#define CALS_VALUE_INT_DTEND_YEAR "dtend_year"
-#define CALS_VALUE_INT_DTEND_MONTH "dtend_month"
-#define CALS_VALUE_INT_DTEND_MDAY "dtend_mday"
-#define CALS_VALUE_TXT_DTEND_TZID "dtend_tzid"
-#define CALS_VALUE_LLI_LASTMOD "last_mod"
-
-#define CALS_VALUE_INT_RRULE_FREQ "freq"
-#define CALS_VALUE_INT_RRULE_ID "rrule_id"
-#define CALS_VALUE_INT_RRULE_RANGE_TYPE "range_type"   //endless, until, count
-#define CALS_VALUE_INT_RRULE_UNTIL_TYPE "until_type"   //until by utc, until by local date
-#define CALS_VALUE_LLI_RRULE_UNTIL_UTIME "until_utime"  //unix time
-#define CALS_VALUE_INT_RRULE_UNTIL_YEAR "until_year"
-#define CALS_VALUE_INT_RRULE_UNTIL_MONTH "until_month"
-#define CALS_VALUE_INT_RRULE_UNTIL_MDAY "until_mday"
-#define CALS_VALUE_INT_RRULE_COUNT "count"
-#define CALS_VALUE_INT_RRULE_INTERVAL "interval"
-#define CALS_VALUE_TXT_RRULE_BYSECOND "bysecond"
-#define CALS_VALUE_TXT_RRULE_BYMINUTE "byminute"
-#define CALS_VALUE_TXT_RRULE_BYHOUR "byhour"
-#define CALS_VALUE_TXT_RRULE_BYDAY "byday"
-#define CALS_VALUE_TXT_RRULE_BYMONTHDAY "bymonthday"
-#define CALS_VALUE_TXT_RRULE_BYYEARDAY "byyearday"
-#define CALS_VALUE_TXT_RRULE_BYWEEKNO "byweekno"
-#define CALS_VALUE_TXT_RRULE_BYMONTH "bymonth"
-#define CALS_VALUE_TXT_RRULE_BYSETPOS "bysetpos"
-#define CALS_VALUE_INT_RRULE_WKST "wkst"
-
-/* 0x00 ~0x06 used cal_struct_type */
-enum {
-       CALS_LIST_PERIOD_NORMAL_ONOFF = 0x07,
-       CALS_LIST_PERIOD_ALLDAY_ONOFF,
-       CALS_LIST_PERIOD_NORMAL_BASIC,
-       CALS_LIST_PERIOD_ALLDAY_BASIC,
-       CALS_LIST_PERIOD_NORMAL_OSP = 0x100,
-       CALS_LIST_PERIOD_ALLDAY_OSP,
-       CALS_LIST_PERIOD_NORMAL_LOCATION,
-       CALS_LIST_PERIOD_ALLDAY_LOCATION,
-       CALS_LIST_PERIOD_NORMAL_ALARM,
-       CALS_LIST_PERIOD_ALLDAY_ALARM,
-};
-
-#define CALS_LIST_PERIOD_NORMAL_ONOFF_INT_EVENTID CAL_VALUE_INT_INDEX
-#define CALS_LIST_PERIOD_NORMAL_ONOFF_INT_DTSTART_TYPE CALS_VALUE_INT_DTSTART_TYPE
-#define CALS_LIST_PERIOD_NORMAL_ONOFF_LLI_DTSTART_UTIME CALS_VALUE_LLI_DTSTART_UTIME
-#define CALS_LIST_PERIOD_NORMAL_ONOFF_INT_DTEND_TYPE CALS_VALUE_INT_DTEND_TYPE
-#define CALS_LIST_PERIOD_NORMAL_ONOFF_LLI_DTEND_UTIME CALS_VALUE_LLI_DTEND_UTIME
-
-#define CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_EVENTID CAL_VALUE_INT_INDEX
-#define CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_TYPE CALS_VALUE_INT_DTSTART_TYPE
-#define CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_YEAR CALS_VALUE_INT_DTSTART_YEAR
-#define CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_MONTH CALS_VALUE_INT_DTSTART_MONTH
-#define CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_MDAY CALS_VALUE_INT_DTSTART_MDAY
-#define CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTEND_TYPE CALS_VALUE_INT_DTEND_TYPE
-#define CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTEND_YEAR CALS_VALUE_INT_DTEND_YEAR
-#define CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTEND_MONTH CALS_VALUE_INT_DTEND_MONTH
-#define CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTEND_MDAY CALS_VALUE_INT_DTEND_MDAY
-
-#define CALS_LIST_PERIOD_NORMAL_BASIC_INT_EVENTID CAL_VALUE_INT_INDEX
-#define CALS_LIST_PERIOD_NORMAL_BASIC_INT_DTSTART_TYPE CALS_VALUE_INT_DTSTART_TYPE
-#define CALS_LIST_PERIOD_NORMAL_BASIC_LLI_DTSTART_UTIME CALS_VALUE_LLI_DTSTART_UTIME
-#define CALS_LIST_PERIOD_NORMAL_BASIC_INT_DTEND_TYPE CALS_VALUE_INT_DTEND_TYPE
-#define CALS_LIST_PERIOD_NORMAL_BASIC_LLI_DTEND_UTIME CALS_VALUE_LLI_DTEND_UTIME
-#define CALS_LIST_PERIOD_NORMAL_BASIC_TXT_SUMMARY CAL_VALUE_TXT_SUMMARY
-#define CALS_LIST_PERIOD_NORMAL_BASIC_TXT_LOCATION CAL_VALUE_TXT_LOCATION
-
-#define CALS_LIST_PERIOD_ALLDAY_BASIC_INT_EVENTID CAL_VALUE_INT_INDEX
-#define CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_TYPE CALS_VALUE_INT_DTSTART_TYPE
-#define CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_YEAR CALS_VALUE_INT_DTSTART_YEAR
-#define CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_MONTH CALS_VALUE_INT_DTSTART_MONTH
-#define CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_MDAY CALS_VALUE_INT_DTSTART_MDAY
-#define CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_TYPE CALS_VALUE_INT_DTEND_TYPE
-#define CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_YEAR CALS_VALUE_INT_DTEND_YEAR
-#define CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_MONTH CALS_VALUE_INT_DTEND_MONTH
-#define CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_MDAY CALS_VALUE_INT_DTEND_MDAY
-#define CALS_LIST_PERIOD_ALLDAY_BASIC_TXT_SUMMARY CAL_VALUE_TXT_SUMMARY
-#define CALS_LIST_PERIOD_ALLDAY_BASIC_TXT_LOCATION CAL_VALUE_TXT_LOCATION
-
-#define CALS_LIST_PERIOD_NORMAL_OSP_INT_EVENTID CAL_VALUE_INT_INDEX
-#define CALS_LIST_PERIOD_NORMAL_OSP_INT_DTSTART_TYPE CALS_VALUE_INT_DTSTART_TYPE
-#define CALS_LIST_PERIOD_NORMAL_OSP_LLI_DTSTART_UTIME CALS_VALUE_LLI_DTSTART_UTIME
-#define CALS_LIST_PERIOD_NORMAL_OSP_INT_DTEND_TYPE CALS_VALUE_INT_DTEND_TYPE
-#define CALS_LIST_PERIOD_NORMAL_OSP_LLI_DTEND_UTIME CALS_VALUE_LLI_DTEND_UTIME
-#define CALS_LIST_PERIOD_NORMAL_OSP_TXT_SUMMARY CAL_VALUE_TXT_SUMMARY
-#define CALS_LIST_PERIOD_NORMAL_OSP_TXT_LOCATION CAL_VALUE_TXT_LOCATION
-#define CALS_LIST_PERIOD_NORMAL_OSP_INT_CALENDAR_ID CAL_VALUE_INT_CALENDAR_ID
-#define CALS_LIST_PERIOD_NORMAL_OSP_TXT_DESCRIPTION CAL_VALUE_TXT_DESCRIPTION
-#define CALS_LIST_PERIOD_NORMAL_OSP_INT_BUSY_STATUS CAL_VALUE_INT_BUSY_STATUS
-#define CALS_LIST_PERIOD_NORMAL_OSP_INT_STATUS CAL_VALUE_INT_MEETING_STATUS
-#define CALS_LIST_PERIOD_NORMAL_OSP_INT_PRIORITY CAL_VALUE_INT_PRIORITY
-#define CALS_LIST_PERIOD_NORMAL_OSP_INT_VISIBILITY CAL_VALUE_INT_SENSITIVITY
-#define CALS_LIST_PERIOD_NORMAL_OSP_INT_IS_RECURRING CALS_VALUE_INT_RRULE_ID
-
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_EVENTID CAL_VALUE_INT_INDEX
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_TYPE CALS_VALUE_INT_DTSTART_TYPE
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_YEAR CALS_VALUE_INT_DTSTART_YEAR
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_MONTH CALS_VALUE_INT_DTSTART_MONTH
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_MDAY CALS_VALUE_INT_DTSTART_MDAY
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_TYPE CALS_VALUE_INT_DTEND_TYPE
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_YEAR CALS_VALUE_INT_DTEND_YEAR
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_MONTH CALS_VALUE_INT_DTEND_MONTH
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_MDAY CALS_VALUE_INT_DTEND_MDAY
-#define CALS_LIST_PERIOD_ALLDAY_OSP_TXT_SUMMARY CAL_VALUE_TXT_SUMMARY
-#define CALS_LIST_PERIOD_ALLDAY_OSP_TXT_LOCATION CAL_VALUE_TXT_LOCATION
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_CALENDAR_ID CAL_VALUE_INT_CALENDAR_ID
-#define CALS_LIST_PERIOD_ALLDAY_OSP_TXT_DESCRIPTION CAL_VALUE_TXT_DESCRIPTION
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_BUSY_STATUS CAL_VALUE_INT_BUSY_STATUS
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_STATUS CAL_VALUE_INT_MEETING_STATUS
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_PRIORITY CAL_VALUE_INT_PRIORITY
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_VISIBILITY CAL_VALUE_INT_SENSITIVITY
-#define CALS_LIST_PERIOD_ALLDAY_OSP_INT_IS_RECURRING CALS_VALUE_INT_RRULE_ID
-
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_INT_EVENTID CAL_VALUE_INT_INDEX
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_INT_DTSTART_TYPE CALS_VALUE_INT_DTSTART_TYPE
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_LLI_DTSTART_UTIME CALS_VALUE_LLI_DTSTART_UTIME
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_INT_DTEND_TYPE CALS_VALUE_INT_DTEND_TYPE
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_LLI_DTEND_UTIME CALS_VALUE_LLI_DTEND_UTIME
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_TXT_SUMMARY CAL_VALUE_TXT_SUMMARY
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_TXT_LOCATION CAL_VALUE_TXT_LOCATION
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_INT_CALENDAR_ID CAL_VALUE_INT_CALENDAR_ID
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_TXT_DESCRIPTION CAL_VALUE_TXT_DESCRIPTION
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_INT_BUSY_STATUS CAL_VALUE_INT_BUSY_STATUS
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_INT_STATUS CAL_VALUE_INT_MEETING_STATUS
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_INT_PRIORITY CAL_VALUE_INT_PRIORITY
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_INT_VISIBILITY CAL_VALUE_INT_SENSITIVITY
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_INT_IS_RECURRING CALS_VALUE_INT_RRULE_ID
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_DBL_LATITUDE CAL_VALUE_DBL_LATITUDE
-#define CALS_LIST_PERIOD_NORMAL_LOCATION_DBL_LONGITUDE CAL_VALUE_DBL_LONGITUDE
-
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_EVENTID CAL_VALUE_INT_INDEX
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTSTART_TYPE CALS_VALUE_INT_DTSTART_TYPE
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTSTART_YEAR CALS_VALUE_INT_DTSTART_YEAR
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTSTART_MONTH CALS_VALUE_INT_DTSTART_MONTH
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTSTART_MDAY CALS_VALUE_INT_DTSTART_MDAY
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTEND_TYPE CALS_VALUE_INT_DTEND_TYPE
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTEND_YEAR CALS_VALUE_INT_DTEND_YEAR
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTEND_MONTH CALS_VALUE_INT_DTEND_MONTH
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTEND_MDAY CALS_VALUE_INT_DTEND_MDAY
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_TXT_SUMMARY CAL_VALUE_TXT_SUMMARY
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_TXT_LOCATION CAL_VALUE_TXT_LOCATION
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_CALENDAR_ID CAL_VALUE_INT_CALENDAR_ID
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_TXT_DESCRIPTION CAL_VALUE_TXT_DESCRIPTION
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_BUSY_STATUS CAL_VALUE_INT_BUSY_STATUS
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_STATUS CAL_VALUE_INT_MEETING_STATUS
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_PRIORITY CAL_VALUE_INT_PRIORITY
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_VISIBILITY CAL_VALUE_INT_SENSITIVITY
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_IS_RECURRING CALS_VALUE_INT_RRULE_ID
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_DBL_LATITUDE CAL_VALUE_DBL_LATITUDE
-#define CALS_LIST_PERIOD_ALLDAY_LOCATION_DBL_LONGITUDE CAL_VALUE_DBL_LONGITUDE
-
-#define CALS_LIST_PERIOD_NORMAL_ALARM_INT_EVENTID CAL_VALUE_INT_INDEX
-#define CALS_LIST_PERIOD_NORMAL_ALARM_INT_CALENDAR_ID CAL_VALUE_INT_CALENDAR_ID
-#define CALS_LIST_PERIOD_NORMAL_ALARM_INT_DTSTART_TYPE CALS_VALUE_INT_DTSTART_TYPE
-#define CALS_LIST_PERIOD_NORMAL_ALARM_LLI_DTSTART_UTIME CALS_VALUE_LLI_DTSTART_UTIME
-#define CALS_LIST_PERIOD_NORMAL_ALARM_INT_DTEND_TYPE CALS_VALUE_INT_DTEND_TYPE
-#define CALS_LIST_PERIOD_NORMAL_ALARM_LLI_DTEND_UTIME CALS_VALUE_LLI_DTEND_UTIME
-#define CALS_LIST_PERIOD_NORMAL_ALARM_LLI_ALARM_UTIME CAL_VALUE_LLI_ALARMS_TIME
-#define CALS_LIST_PERIOD_NORMAL_ALARM_INT_ALARM_ID CAL_VALUE_INT_ALARMS_ID
-
-enum cals_day {
-       CALS_SUNDAY,
-       CALS_MONDAY,
-       CALS_TUESDAY,
-       CALS_WEDNESDAY,
-       CALS_THURSDAY,
-       CALS_FRIDAY,
-       CALS_SATURDAY,
-       CALS_NODAY,
-};
-
-enum cals_freq {
-       CALS_FREQ_ONCE = 0x0,
-       CALS_FREQ_YEARLY,
-       CALS_FREQ_MONTHLY,
-       CALS_FREQ_WEEKLY,
-       CALS_FREQ_DAILY,
-       CALS_FREQ_HOURLY,
-       CALS_FREQ_MINUTELY,
-       CALS_FREQ_SECONDLY,
-};
-
-enum cals_time_type {
-       CALS_TIME_UTIME,
-       CALS_TIME_LOCALTIME,
-};
-
-enum cals_range {
-       CALS_RANGE_UNTIL,
-       CALS_RANGE_COUNT,
-       CALS_RANGE_NONE,
-};
-
-int calendar_svc_event_get_normal_list_by_period(int calendar_id, int op_code,
-               long long int start, long long int end, cal_iter **iter);
-
-int calendar_svc_event_get_allday_list_by_period(int calendar_id, int op_code,
-               int dtstart_year, int dtstart_mon, int dtstart_day,
-               int dtend_year, int dtend_mon, int dtend_day, cal_iter **iter);
-
-int calendar_svc_struct_set_lli(cal_struct *record, const char *field, long long int llival);
-
-long long int calendar_svc_struct_get_lli(cal_struct *record, const char *field);
-
-int calendar_svc_todo_get_list_by_period(int calendar_id,
-               long long int due_from, long long int dueto, int priority, int status, cal_iter **iter);
-int calendar_svc_todo_get_count_by_period(int calendar_id,
-               long long int due_from, long long int dueto, int priority, int status, int *count);
-int calendar_svc_event_delete_normal_instance(int event_id, long long int dtstart_utime);
-int calendar_svc_event_delete_allday_instance(int event_id, int dtstart_year, int dtstart_month, int dtstart_mday);
-#ifdef __cplusplus
-}
-#endif
-
-/**
- * deprecated
- */
-typedef enum
-{
-       CAL_STATUS_FREE = 0,               /**< deprecated */
-       CAL_STATUS_TENTATIVE,             /**< deprecated */
-       CAL_STATUS_BUSY,                     /**< deprecated */
-       CAL_STATUS_OUROFOFFICE,           /**< deprecated */
-       CAL_STATUS_CONFIRM,               /**< deprecated */
-       CAL_STATUS_DENIED,                /**< deprecated */
-} cal_status_type_t;
-
-#endif /* __CALENDAR_SVC_H__ */
-
diff --git a/include/calendar-svc-struct.h b/include/calendar-svc-struct.h
deleted file mode 100755 (executable)
index 4ba2f06..0000000
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __CALENDAR_SVC_STRUCT_H__
-#define __CALENDAR_SVC_STRUCT_H__
-
-
-/**
- * @defgroup CALENDAR_SVC Calendar Service
- * @section intro 2.0 calendar engine
- * - this document maded for calendar service
- * - this document contain api signature & usage
- *
- * @section CREATEINFO author infomation
- * - author      :   heungjae jeong(hj98.jeong@samsung.com)
- * - date                 :   2010/09/06
- *
- * @section DEPENDENCY DEPENDENCY
- * - GLIB
- *
- * @section MODIFYINFO Revision history
- * - maximus/2010-09-06          : make api signature
- * - maximus/2010-09-16       : add calendar type & exception date, change api name(remove _event)
- * - maximus/2010-09-16       : add utility function(for vcalendar)
- *
- *
- */
-
-
-/**
- *cal_struct is an opaque type, it must be used via accessor functions.
- *@ingroup common
- *@see also:
- * calendar_svc_struct_new(), calendar_svc_struct_free()
- * calendar_svc_struct_get_value(), calendar_svc_struct_get_list(),
- * calendar_svc_struct_store_value(), calendar_svc_struct_store_list()
- */
-typedef struct _cal_struct cal_struct;
-
-
-/**
- * cal_value is an opaque type, it must be
- * used via accessor functions.
- * @ingroup common
- * @see calendar_svc_struct_new(), calendar_svc_struct_free()
- */
-typedef struct _cal_value cal_value;
-
-
-
-/**
- * cal_struct is an opaque type, it must be used via accessor functions.
- * @ingroup common
- * @see calendar_svc_find_event_list(), calendar_svc_event_get_changes()
- *      calendar_svc_get_event_by_period(), calendar_svc_iter_get_info(),
- *      calendar_svc_iter_next(), calendar_svc_iter_remove()
- */
-typedef struct _cal_iter cal_iter;
-
-
-
-/**
- * @defgroup example example
- * @ingroup CALENDAR_SVC
- * @li
- *      insert example
- * @code
-   void insert_test(void)
-   {
-      cal_struct *event=NULL;
-      cal_value *attendee1=NULL,*attendee2=NULL;
-      GList *attendee_list=NULL;
-
-      calendar_svc_connect();
-      event = calendar_svc_struct_new(CAL_STRUCT_SCHEDULE);
-
-      calendar_svc_struct_set_str(event, CAL_VALUE_TXT_SUMMARY, "weekly meeting");
-      calendar_svc_struct_set_str(event, CAL_VALUE_TXT_DESCRIPTION, "review : project status");
-      calendar_svc_struct_set_str(event, CAL_VALUE_TXT_LOCATION, "meeting room #1");
-
-      attendee1 = calendar_svc_value_new(CAL_VALUE_LST_ATTENDEE_LIST);
-      if(attendee1) {
-         calendar_svc_value_set_str(attendee1, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME, "heungjae jeong");
-         calendar_svc_value_set_str(attendee1, CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL, "id@domain.com");
-         calendar_svc_value_set_int(attendee1, CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS, 1);
-      }
-      attendee_list = g_list_append(attendee_list, attendee1);
-
-      attendee2 = calendar_svc_value_new(CAL_VALUE_LST_ATTENDEE_LIST);
-      if(attendee2) {
-         calendar_svc_value_set_str(attendee2, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME, "boncheol gu");
-         calendar_svc_value_set_str(attendee2, CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL, "id@domain.com");
-         calendar_svc_value_set_str(attendee2, CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS, 0);
-      }
-      attendee_list = g_list_append(attendee_list, attendee2);
-
-      calendar_svc_struct_store_list(event, CAL_VALUE_LST_ATTENDEE_LIST, attendee_list);
-
-      calendar_svc_insert(event);
-      calendar_svc_struct_free(&event);
-
-      calendar_svc_close();
-   }
- * @endcode
- */
-
-/**
- * @addtogroup example
- * @li
- *      update example
- * @code
-   void update_test(void)
-   {
-      cal_struct *event=NULL;
-      cal_value *attendee1,*attendee2;
-      GList *attendee_list=NULL;
-      char * attendee_name = NULL;
-
-      calendar_svc_connect();
-
-      calendar_svc_get(CAL_STRUCT_SCHEDULE,1,&event)
-
-      calendar_svc_struct_set_str(event, CAL_VALUE_TXT_SUMMARY, "weekly meeting2");
-
-      attendee_list = calendar_svc_struct_get_list(event,CAL_VALUE_LST_ATTENDEE_LIST);
-
-      while(attendee_list)
-      {
-
-         attendee1 = attendee_list->data;
-
-         attendee_name = calendar_svc_value_get_str(attendee2, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME);
-
-         if(strcmp(attendee_name,"boncheol gu")==0)
-         {
-            calendar_svc_value_set_str(attendee1, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME,"boncheol gu2");
-         }
-         else if(strcmp(attendee_name,"heungjae jeong")==0)
-         {
-            calendar_svc_value_set_int(attendee1, CAL_VALUE_INT_DETAIL_DELETE,true); // set delete flag
-         }
-      }
-
-      attendee2 = calendar_svc_value_new(CAL_VALUE_LST_ATTENDEE_LIST);
-      if(attendee2) {
-         calendar_svc_value_set_str(attendee2, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME, "jihwa park");
-         calendar_svc_value_set_str(attendee2, CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL, "id@domain.com");
-      }
-      attendee_list = g_list_append(attendee_list, attendee2);
-
-      calendar_svc_struct_store_list(event, CAL_VALUE_LST_ATTENDEE_LIST, attendee_list);
-
-      calendar_svc_update(event);
-      calendar_svc_struct_free(&event);
-
-      calendar_svc_close();
-   }
- * @endcode
- */
-
-
-/**
- * @addtogroup example
- * @li
- *      get list/delete example
- * @code
-   void delete_test(void)
-   {
-      cal_struct *event=NULL;
-      cal_value *attendee1=NULL,*attendee2=NULL;
-      GList *attendee_list=NULL;
-      cal_iter *iter=NULL;
-      int ret = 0;
-      int index = 0;
-         int version = 0;
-
-      calendar_svc_connect();
-
-      calendar_svc_event_get_changes(0, version, &iter);
-      ret = calendar_svc_iter_next(iter);
-      while(CAL_SUCCESS == ret)
-      {
-         calendar_svc_iter_get_info(iter, &event);
-         index = calendar_svc_struct_get_int(event,CAL_VALUE_INT_INDEX);
-
-         calendar_svc_delete(CAL_STRUCT_SCHEDULE,index);
-
-         calendar_svc_struct_free(&event);
-         ret = calendar_svc_iter_next(iter);
-      }
-
-      calendar_svc_iter_remove(&iter);
-      calendar_svc_close();
-   }
- * @endcode
- */
-
-
-
-/**
- * @addtogroup example
- * @li
- *      get event example
- * @code
-
-   void get_test(void)
-   {
-      int index, ret=-1;
-      cal_struct *event = NULL;
-      cal_value *name;
-      GList *get_list, *cursor;
-      index = 1;
-      char *summary;
-      ui_event_t appEvent={0,};
-
-      ret = calendar_svc_get(CAL_STRUCT_SCHEDULE,index,CAL_VALUE_MAIN_FILED, &event);
-
-      summary = calendar_svc_struct_get_str(event, CAL_VALUE_TXT_SUMMARY);
-      strncpy(appEvent.summay,summary,sizeof(appEvent.summay)-1);
-
-
-      get_list = NULL;
-      calendar_svc_struct_get_list(event, CAL_VALUE_LST_ATTENDEE_LIST, &get_list);
-
-      cursor = get_list;
-      for(;cursor;cursor=g_slist_next(cursor))
-      {
-         DBG("number Type = %d",
-            calendar_svc_value_get_int((cal_value*)cursor->data, CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS));
-
-         DBG("Number = %s\n",
-            calendar_svc_value_get_str((cal_value*)cursor->data, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME));
-      }
-
-      calendar_svc_struct_free(&event);
-
-   }
-* @endcode
-*/
-
-
-#endif /* __CALENDAR_SVC_STRUCT_H__ */
-
diff --git a/include/calendar.h b/include/calendar.h
new file mode 100644 (file)
index 0000000..451f0a4
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __TIZEN_SOCIAL_CALENDAR_H__
+#define __TIZEN_SOCIAL_CALENDAR_H__
+
+#include <calendar_errors.h>
+#include <calendar_view.h>
+#include <calendar_db.h>
+#include <calendar_filter.h>
+#include <calendar_list.h>
+#include <calendar_query.h>
+#include <calendar_record.h>
+#include <calendar_service.h>
+#include <calendar_vcalendar.h>
+#include <calendar_reminder.h>
+
+#endif /* __TIZEN_SOCIAL_CALENDAR_H__ */
diff --git a/include/calendar_db.h b/include/calendar_db.h
new file mode 100644 (file)
index 0000000..70e0daa
--- /dev/null
@@ -0,0 +1,939 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_SOCIAL_CALENDAR_DB_H__
+#define __TIZEN_SOCIAL_CALENDAR_DB_H__
+
+#include <calendar_types.h>
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file calendar_db.h
+ */
+
+/**
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_DATABASE_MODULE
+ * @{
+ */
+
+/**
+ * @brief Called when a designated view changes.
+ * @since_tizen 2.3
+ *
+ * @param[in]   view_uri   The view URI
+ * @param[in]   user_data  The user data passed from the callback registration function
+ *
+ * @see calendar_db_add_changed_cb()
+ */
+typedef void (*calendar_db_changed_cb)(const char* view_uri, void* user_data);
+
+/**
+ * @brief Inserts a record into the calendar database.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   record     The record handle
+ * @param[out]  record_id  The record ID
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_FILE_NO_SPACE       File system is full
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_NO_DATA             Data does not exist
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_update_record()
+ * @see calendar_db_delete_record()
+ * @see calendar_db_get_record()
+ */
+int calendar_db_insert_record( calendar_record_h record, int* record_id );
+
+/**
+ * @brief Gets a record from the calendar database.
+ *
+ * @details This function creates a new record handle from the calendar database by the given @a record_id. \n
+ *          @a record will be created and filled with record information.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.read
+ *
+ * @remarks You must release @a record using calendar_record_destroy().
+ *
+ * @param[in]   view_uri    The view URI of a record
+ * @param[in]   record_id   The record ID
+ * @param[out]  record      The record handle associated with the record ID
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_FILE_NO_SPACE       File system is full
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_DB_RECORD_NOT_FOUND Database not found
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_NO_DATA             Data does not exist
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_record_destroy()
+ */
+int calendar_db_get_record( const char* view_uri, int record_id, calendar_record_h* record );
+
+/**
+ * @brief Updates a record in the calendar database.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   record    The record handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_DB_RECORD_NOT_FOUND Database not found
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_NO_DATA             Data does not exist
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_insert_record()
+ * @see calendar_db_delete_record()
+ * @see calendar_db_get_record()
+ */
+int calendar_db_update_record( calendar_record_h record );
+
+/**
+ * @brief Deletes a record from the calendar database with related child records.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   view_uri    The view URI of a record
+ * @param[in]   record_id   The record ID to be deleted
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_DB_RECORD_NOT_FOUND Database not found
+ * @retval  #CALENDAR_ERROR_FILE_NO_SPACE       File system is full
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_NO_DATA             Data does not exist
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_insert_record()
+ */
+int calendar_db_delete_record( const char* view_uri, int record_id );
+
+/**
+ * @brief Retrieves all records as a list.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.read
+ *
+ * @remarks You must release @a record_list using calendar_list_destroy().
+ *
+ * @param[in]   view_uri        The view URI to get records from
+ * @param[in]   offset          The index from which results are received
+ * @param[in]   limit           The maximum number of results(value 0 is used for all records)
+ * @param[out]  record_list     The record list
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_NO_DATA             Data does not exist
+ *
+ * @pre    calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_list_destroy()
+ */
+int calendar_db_get_all_records( const char* view_uri, int offset, int limit, calendar_list_h* record_list );
+
+/**
+ * @brief Retrieves records using a query handle.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.read
+ *
+ * @remarks You must release @a record_list using calendar_list_destroy().
+ *
+ * @param[in]   query           The query handle used to filter results
+ * @param[in]   offset          The index from which results are received
+ * @param[in]   limit           The maximum number of results(value 0 is used for all records)
+ * @param[out]  record_list     The record list
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                           Successful
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_NO_DATA             Data does not exist
+ *
+ * @pre    calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_list_destroy()
+ */
+int calendar_db_get_records_with_query( calendar_query_h query, int offset, int limit, calendar_list_h* record_list );
+
+/**
+ * @brief Gets the record count of a specific view.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.read
+ *
+ * @param[in]   view_uri        The view URI to get records from
+ * @param[out]  count           The number of records
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_NO_DATA             Data does not exist
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre     This function requires an open connection to the calendar service using calendar_connect2().
+ *
+ * @see calendar_connect()
+ */
+int calendar_db_get_count( const char* view_uri, int *count );
+
+/**
+ * @brief Gets the record count with a query handle.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.read
+ *
+ * @param[in]   query    The query handle used for filtering the results
+ * @param[out]  count    The number of records
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_NO_DATA             Data does not exist
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre    This function requires an open connection to the calendar service using calendar_connect2().
+ *
+ * @see calendar_connect2()
+ */
+int calendar_db_get_count_with_query( calendar_query_h query, int *count );
+
+/**
+ * @brief Inserts multiple records into the calendar database as a batch operation.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   record_list         The record list handle
+ * @param[out]  record_id_array            The array of record IDs
+ * @param[out]  count                      The number of record IDs
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_FILE_NO_SPACE       File system is full
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_NO_DATA             Data does not exist
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_update_records()
+ * @see calendar_db_delete_records()
+ */
+int calendar_db_insert_records( calendar_list_h record_list, int** record_id_array, int* count);
+
+/**
+ * @brief Updates multiple records into the calendar database as a batch operation.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   record_list       The record list handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_NO_DATA             Data does not exist
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_DB_RECORD_NOT_FOUND Database not found
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_insert_records()
+ * @see calendar_db_delete_records()
+ */
+int calendar_db_update_records( calendar_list_h record_list);
+
+/**
+ * @brief   Deletes multiple records with related child records from the calendar database as a batch operation.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   view_uri            The view URI of the records to delete
+ * @param[in]   record_id_array     The record IDs to delete
+ * @param[in]   count               The number of records
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_DB_RECORD_NOT_FOUND Database not found
+ * @retval  #CALENDAR_ERROR_FILE_NO_SPACE       File system is full
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_insert_records()
+ * @see calendar_db_delete_records()
+ */
+int calendar_db_delete_records(const char* view_uri, int record_id_array[], int count);
+
+/**
+ * @brief      Gets the current calendar database version.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.read
+ *
+ * @param[out]  calendar_db_version    The calendar database version
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                 Successful
+ * @retval     #CALENDAR_ERROR_INVALID_PARAMETER    Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED            Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED    Permission denied. This application does not have the privilege to call this method.
+ * @retval  ##CALENDAR_ERROR_DB_RECORD_NOT_FOUND Database not found
+ * @retval  #CALENDAR_ERROR_IPC                  Unknown IPC error
+ *
+ * @pre     This function requires an open connection to the calendar service using calendar_connect().
+ *
+ * @see calendar_connect()
+ * @see calendar_db_get_changes_by_version()
+ */
+int calendar_db_get_current_version(int* calendar_db_version);
+
+/**
+ * @brief Registers a callback function to be invoked when a record changes.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.read
+ *
+ * @remarks If successive change notification produced on the view_uri are identical,
+ * then they are coalesced into a single notification if the older notification has not yet been called
+ * because default main loop is doing something.
+ * But, it means that a callback function is not called to reliably count of change.
+ * This API supports only @ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_book view, @ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_event view,
+ * @ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_todo view.
+ *
+ * @param[in]   view_uri    The view URI of the record to subscribe for change notifications
+ * @param[in]   callback    The callback function to register
+ * @param[in]  user_data   The user data to be passed to the callback function
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval     #CALENDAR_ERROR_NONE                Successful
+ * @retval     #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_SYSTEM              Error from another modules
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ *
+ * @pre            This function requires an open connection to the calendar service using calendar_connect().
+ * @post    calendar_db_changed_cb() will be invoked when the designated view changes.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_changed_cb()
+ * @see calendar_db_remove_changed_cb()
+ */
+int calendar_db_add_changed_cb(const char* view_uri, calendar_db_changed_cb callback, void* user_data );
+
+/**
+ * @brief Unregisters a callback function.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.read
+ *
+ * @param[in]   view_uri    The view URI of the record to subscribe for change notifications
+ * @param[in]   callback    The callback function to register
+ * @param[in]  user_data   The user data to be passed to the callback function
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval     #CALENDAR_ERROR_NONE                Successful
+ * @retval     #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_SYSTEM              Error from another modules
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ *
+ * @pre            This function requires an open connection to the calendar service using calendar_connect().
+ *
+ * @see calendar_connect()
+ * @see calendar_db_changed_cb()
+ * @see calendar_db_add_changed_cb()
+ */
+int calendar_db_remove_changed_cb( const char* view_uri, calendar_db_changed_cb callback, void* user_data );
+
+/**
+ * @brief Retrieves records with the given calendar database version.
+ *
+  * @details This function finds all the changed records since the given @a calendar_db_version.
+  *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.read
+ *
+ * @remarks You must release @a change_record_list using calendar_list_destroy().
+ *
+ * @param[in]   view_uri                    The view URI to get records from
+ * @param[in]   calendar_book_id            The calendar book ID to filter
+ * @param[in]   calendar_db_version         The calendar database version
+ * @param[out]  record_list                 The record list
+ * @param[out]  current_calendar_db_version The current calendar database version
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_DB_RECORD_NOT_FOUND Database not found
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ *
+ * @pre    calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_list_destroy()
+ */
+int calendar_db_get_changes_by_version(const char* view_uri, int calendar_book_id, int calendar_db_version, calendar_list_h* record_list, int *current_calendar_db_version );
+
+/**
+ * @brief Inserts a vcalendar stream into the calendar database.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   vcalendar_stream     The vcalendar stream
+ * @param[out]  record_id_array      The record IDs to delete
+ * @param[out]  count                The number of record ID arrays
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_NO_DATA             Data does not exist
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_FILE_NO_SPACE       File system is full
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_replace_vcalendars()
+ */
+int calendar_db_insert_vcalendars(const char* vcalendar_stream, int **record_id_array, int *count);
+
+/**
+ * @brief Replaces a vcalendar stream in the calendar database.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   vcalendar_stream     The vcalendar stream
+ * @param[in]   record_id_array      The record IDs to replace
+ * @param[in]   count                The number of record ID arrays
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_NO_DATA             Data does not exist
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_DB_RECORD_NOT_FOUND Database not found
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ *
+ * @pre     This function requires an open connection to the calendar service by calendar_connect().
+ *
+ * @see calendar_connect()
+ * @see calendar_db_replace_vcalendars()
+ */
+int calendar_db_replace_vcalendars(const char* vcalendar_stream, int *record_id_array, int count);
+
+/**
+ * @brief Replaces a record in the calendar database.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   record        The record handle
+ * @param[in]   record_id     The record ID
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_FILE_NO_SPACE       File system is full
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_update_record()
+ * @see calendar_db_delete_record()
+ * @see calendar_db_get_record()
+ */
+int calendar_db_replace_record(calendar_record_h record, int record_id);
+
+/**
+ * @brief Replaces multiple records in the calendar database as a batch operation.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   record_list         The record list handle
+ * @param[in]   record_id_array     The record IDs
+ * @param[in]   count               The number of record ID arrays
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_FILE_NO_SPACE       File system is full
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_update_records()
+ * @see calendar_db_delete_records()
+ * @see calendar_db_replace_record()
+ */
+int calendar_db_replace_records(calendar_list_h record_list, int *record_id_array, int count);
+
+/**
+ * @brief Gets the last successful change version of the database on the current connection.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.read
+ *
+ * @param[out]  last_change_version   The calendar database version on the current connection
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ *
+ * @pre     This function requires an open connection to the calendar service using calendar_connect().
+ *
+ * @see calendar_connect()
+ * @see calendar_db_get_current_version()
+ */
+int calendar_db_get_last_change_version(int* last_change_version);
+
+/**
+ * @brief Retrieves changed exception records since the given calendar database version.
+ *        Exceptions are the modified or deleted instances in a recurring event.
+ *
+ * @details This function finds all the changed records since the given @a calendar_db_version.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.read
+ *
+ * @remarks You must release @a change_record_list using calendar_list_destroy().
+ *
+ * @param[in]   view_uri               The view URI to get records from
+ * @param[in]   original_event_id      The original event ID
+ * @param[in]   calendar_db_version    The calendar database version starting from which to get records
+ * @param[out]  list                          The record list
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_list_destroy()
+ */
+int calendar_db_get_changes_exception_by_version(const char* view_uri, int original_event_id, int calendar_db_version, calendar_list_h* list);
+
+/**
+ * @internal
+ * @brief Called to get the result of a batch operation.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   error                  Error code for the batch operation
+ * @param[in]   user_data              The user data passed from the batch operation
+ *
+ * @return  @c true to continue with the next iteration of the loop or @c false to break out of the loop
+ *
+ * @pre calendar_db_update_records_async() will invoke this callback.
+ *
+ * @see calendar_db_update_records_async()
+ */
+typedef void (*calendar_db_result_cb)( int error, void *user_data);
+
+/**
+ * @internal
+ * @brief Called to get the result of a batch operation.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   error           Error code for the batch operation
+ * @param[in]   record_id_array The record IDs for the batch operation
+ * @param[in]   count           The number of record ID array
+ * @param[in]   user_data       The user data passed from the batch operation
+ *
+ * @return  @c true to continue with the next iteration of the loop or @c false to break out of the loop
+ *
+ * @pre calendar_db_insert_records_async() will invoke this callback.
+ *
+ * @see calendar_db_insert_records_async()
+ */
+typedef void (*calendar_db_insert_result_cb)( int error, int* record_id_array, int count, void *user_data);
+
+/**
+ * @internal
+ * @brief Inserts multiple records to the calendar database as a batch operation.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   record_list         The record list handle
+ * @param[in]   callback            The callback function to invoke, lets you know the result of the batch operation
+ * @param[in]   user_data           The user data to be passed to the callback function
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_update_records()
+ * @see calendar_db_delete_records()
+ * @see calendar_db_insert_result_cb()
+ */
+int calendar_db_insert_records_async(calendar_list_h record_list, calendar_db_insert_result_cb callback, void *user_data);
+
+/**
+ * @internal
+ * @brief Updates multiple records in the calendar database as a batch operation.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   record_list         The record list handle
+ * @param[in]   callback            The callback function to invoke, lets you know result of the batch operation
+ * @param[in]   user_data           The user data to be passed to the callback function
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_insert_records()
+ * @see calendar_db_delete_records()
+ * @see calendar_db_result_cb()
+ */
+int calendar_db_update_records_async(calendar_list_h record_list, calendar_db_result_cb callback, void *user_data);
+
+/**
+ * @internal
+ * @brief Deletes multiple records with related child records from the calendar database as a batch operation .
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   view_uri            The view URI of the records to delete
+ * @param[in]   record_id_array     The record IDs to delete
+ * @param[in]   count                          The number of records
+ * @param[in]   callback            The callback function to be invoked which lets you know the result of the batch operation
+ * @param[in]   user_data           The user data to be passed to the callback function
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_insert_records()
+ * @see calendar_db_delete_records()
+ * @see calendar_db_result_cb()
+ */
+int calendar_db_delete_records_async(const char* view_uri, int record_id_array[], int count, calendar_db_result_cb callback, void *user_data);
+
+/**
+ * @internal
+ * @brief Inserts a vcalendar stream to the calendar database.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   vcalendar_stream                The vcalendar stream
+ * @param[in]   callback                        The callback function to be invoked which lets you know result of batch operation
+ * @param[in]   user_data                       The user data to be passed to the callback function
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_replace_vcalendars()
+ * @see calendar_db_insert_result_cb
+ */
+int calendar_db_insert_vcalendars_async(const char* vcalendar_stream, calendar_db_insert_result_cb callback, void *user_data);
+
+/**
+ * @internal
+ * @brief Replaces a vcalendar stream in the calendar database.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   vcalendar_stream                The vcalendar stream
+ * @param[in]   record_id_array                 The record IDs to replace
+ * @param[in]   count                           The number of record ID array
+ * @param[in]   callback                        The callback function to be invoked which lets you know result of batch operation
+ * @param[in]   user_data                       The user data to be passed to the callback function
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_replace_vcalendars()
+ */
+int calendar_db_replace_vcalendars_async(const char* vcalendar_stream, int *record_id_array, int count, calendar_db_result_cb callback, void *user_data);
+
+/**
+ * @internal
+ * @brief Replaces multiple records in the calendar database as a batch operation.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+ *
+ * @param[in]   record_list         The record list handle
+ * @param[in]   record_id_array     The record IDs
+ * @param[in]   count               The number of record ID array
+ * @param[in]   callback            The callback function to invoke which lets you know result of batch operation
+ * @param[in]   user_data           The user data to be passed to the callback function
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre     calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ * @see calendar_db_update_records()
+ * @see calendar_db_delete_records()
+ * @see calendar_db_replace_record()
+ * @see calendar_db_result_cb
+ */
+int calendar_db_replace_records_async(calendar_list_h record_list, int *record_id_array, int count, calendar_db_result_cb callback, void *user_data);
+
+/**
+ * @brief Cleans the data after sync.
+ *
+ * @since_tizen 2.3
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.write
+
+ * @param[in]   calendar_book_id       The calendar book ID
+ * @param[in]   calendar_db_version         The calendar database version
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                       Successful
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY              Out of memory
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval  #CALENDAR_ERROR_DB_FAILED                  Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied
+ * @retval  #CALENDAR_ERROR_FILE_NO_SPACE       File system is full
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_NO_DATA             Data does not exist
+ *
+ * @pre    calendar_connect() should be called to open a connection to the calendar service.
+ *
+ * @see calendar_connect()
+ */
+int calendar_db_clean_after_sync( int calendar_book_id, int calendar_db_version );
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_SOCIAL_CALENDAR_DB_H__ */
+
diff --git a/include/calendar_errors.h b/include/calendar_errors.h
new file mode 100644 (file)
index 0000000..6d74096
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_SOCIAL_CALENDAR_ERROR_H__
+#define __TIZEN_SOCIAL_CALENDAR_ERROR_H__
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file calendar_errors.h
+ */
+
+/**
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_COMMON_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumeration for calendar errors.
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_ERROR_NONE                 = TIZEN_ERROR_NONE,                     /**< Successful */
+       CALENDAR_ERROR_OUT_OF_MEMORY        = TIZEN_ERROR_OUT_OF_MEMORY,            /**< Out of memory */
+       CALENDAR_ERROR_INVALID_PARAMETER    = TIZEN_ERROR_INVALID_PARAMETER,        /**< Invalid parameter */
+       CALENDAR_ERROR_NO_DATA              = TIZEN_ERROR_NO_DATA,                  /**< Requested data does not exist */
+       CALENDAR_ERROR_NOW_IN_PROGRESS      = TIZEN_ERROR_NOW_IN_PROGRESS,          /**< Operation now in progress */
+       CALENDAR_ERROR_ALREADY_IN_PROGRESS  = TIZEN_ERROR_ALREADY_IN_PROGRESS,      /**< Operation already in progress */
+       CALENDAR_ERROR_NOT_PERMITTED        = TIZEN_ERROR_NOT_PERMITTED,            /**< Operation not permitted */
+       CALENDAR_ERROR_FILE_NO_SPACE        = TIZEN_ERROR_FILE_NO_SPACE_ON_DEVICE,      /**< FS is full */
+       CALENDAR_ERROR_PERMISSION_DENIED    = TIZEN_ERROR_PERMISSION_DENIED,        /**< Permission denied */
+       CALENDAR_ERROR_DB_FAILED            = TIZEN_ERROR_CALENDAR | 0x02,                      /**< No access to the database */
+       CALENDAR_ERROR_ITERATOR_END         = TIZEN_ERROR_CALENDAR | 0x04,          /**< Iterator is on the last position */
+       CALENDAR_ERROR_DB_RECORD_NOT_FOUND  = TIZEN_ERROR_CALENDAR | 0x05,          /**< Database not found */
+       CALENDAR_ERROR_IPC                  = TIZEN_ERROR_CALENDAR | 0xBF,          /**< Unknown IPC error */
+       CALENDAR_ERROR_SYSTEM               = TIZEN_ERROR_CALENDAR | 0xEF,          /**< Error from another modules */
+} calendar_error_e;
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_SOCIAL_CALENDAR_ERROR_H__ */
+
diff --git a/include/calendar_filter.h b/include/calendar_filter.h
new file mode 100644 (file)
index 0000000..000608b
--- /dev/null
@@ -0,0 +1,222 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_SOCIAL_CALENDAR_FILTER_H__
+#define __TIZEN_SOCIAL_CALENDAR_FILTER_H__
+
+#include <calendar_types.h>
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file calendar_filter.h
+ */
+
+/**
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_FILTER_MODULE
+ * @{
+ */
+
+/**
+ * @brief Creates a filter handle.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks You must release @a filter using calendar_filter_destroy().
+ *
+ * @param[in]   view_uri     The view URI of a filter
+ * @param[out]  filter       The filter handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre     calendar_connect() should be called to initialize.
+ *
+ * @see calendar_filter_destroy()
+ */
+int calendar_filter_create( const char* view_uri, calendar_filter_h* filter );
+
+/**
+ * @brief Destroys a filter handle.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   filter   The filter handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @see calendar_filter_create()
+ */
+int    calendar_filter_destroy( calendar_filter_h filter );
+
+/**
+ * @brief Adds a condition for the string type property.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   filter          The filter handle
+ * @param[in]   property_id     The property ID to add a condition
+ * @param[in]   match           The match flag
+ * @param[in]   match_value     The match value
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @see calendar_filter_add_operator()
+ */
+int    calendar_filter_add_str( calendar_filter_h filter, unsigned int property_id, calendar_match_str_flag_e match, const char* match_value );
+
+/**
+ * @brief Adds a condition for the integer type property.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   filter          The filter handle
+ * @param[in]   property_id     The property ID to add a condition
+ * @param[in]   match           The match flag
+ * @param[in]   match_value     The match value
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @see calendar_filter_add_operator()
+ */
+int    calendar_filter_add_int( calendar_filter_h filter, unsigned int property_id, calendar_match_int_flag_e match, int match_value );
+
+/**
+ * @brief Adds a condition for the double type property.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   filter          The filter handle
+ * @param[in]   property_id     The property ID to add a condition
+ * @param[in]   match           The match flag
+ * @param[in]   match_value     The match value
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @see calendar_filter_add_operator()
+ */
+int    calendar_filter_add_double( calendar_filter_h filter, unsigned int property_id, calendar_match_int_flag_e match, double match_value );
+
+/**
+ * @brief Adds a condition for the long long int type property.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   filter          The filter handle
+ * @param[in]   property_id     The property ID to add a condition
+ * @param[in]   match           The match flag
+ * @param[in]   match_value     The match value
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @see calendar_filter_add_operator()
+ */
+int    calendar_filter_add_lli( calendar_filter_h filter, unsigned int property_id, calendar_match_int_flag_e match, long long int match_value );
+
+/**
+ * @brief Adds a condition for the calendar_time_s type property.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   filter          The filter handle
+ * @param[in]   property_id     The property ID to add a condition
+ * @param[in]   match           The match flag
+ * @param[in]   match_value     The match value
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @see calendar_filter_add_operator()
+ */
+int    calendar_filter_add_caltime( calendar_filter_h filter, unsigned int property_id, calendar_match_int_flag_e match, calendar_time_s match_value );
+
+/**
+ * @brief Adds a child filter to a parent filter.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   parent_filter      The parent filter handle
+ * @param[in]   child_filter       The child filter handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @see calendar_filter_add_operator()
+ */
+int calendar_filter_add_filter( calendar_filter_h parent_filter, calendar_filter_h child_filter);
+
+/**
+ * @brief Adds an operator between conditions.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   filter          The filter handle
+ * @param[in]   operator_type   The operator type
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @see calendar_filter_add_str()
+ * @see calendar_filter_add_int()
+ * @see calendar_filter_add_double()
+ * @see calendar_filter_add_caltime()
+ * @see calendar_filter_add_filter()
+ */
+int calendar_filter_add_operator( calendar_filter_h filter, calendar_filter_operator_e operator_type );
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_SOCIAL_CALENDAR_FILTER_H__ */
+
diff --git a/include/calendar_internal.h b/include/calendar_internal.h
new file mode 100644 (file)
index 0000000..98d7bb1
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __TIZEN_SOCIAL_CALENDAR_INTERNAL_H__
+#define __TIZEN_SOCIAL_CALENDAR_INTERNAL_H__
+
+#endif //__TIZEN_SOCIAL_CALENDAR_INTERNAL_H__
+
+
diff --git a/include/calendar_list.h b/include/calendar_list.h
new file mode 100644 (file)
index 0000000..3174b11
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_SOCIAL_CALENDAR_LIST_H__
+#define __TIZEN_SOCIAL_CALENDAR_LIST_H__
+
+#include <calendar_types.h>
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_LIST_MODULE
+ * @{
+ */
+
+/**
+ * @brief Creates a calendar list handle.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks You must release @a calendar_list using calendar_list_destroy().
+ *
+ * @param[out]  out_list   The calendar list handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @see calendar_list_destroy()
+ */
+int calendar_list_create( calendar_list_h* out_list );
+
+/**
+ * @brief Destroys a calendar list handle and releases all its resources.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   list            The calendar list handle
+ * @param[in]   delete_record   If @c true, child records are destroyed automatically,
+ *                              otherwise @c false
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                   Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER      Invalid parameter
+ *
+ * @see calendar_list_create()
+ */
+int calendar_list_destroy( calendar_list_h list, bool delete_record );
+
+
+/**
+ * @brief Retrieves the number of calendar entities in a calendar list.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  list     The calendar list handle
+ * @param[out] count    The count of the calendar entity
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @see calendar_list_add()
+ */
+int calendar_list_get_count( calendar_list_h list, int *count );
+
+/**
+ * @brief Adds a record to the calendar list.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  list    The calendar list handle
+ * @param[in]  record  The record handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @see calendar_list_remove()
+ */
+int calendar_list_add( calendar_list_h list, calendar_record_h record );
+
+/**
+ * @brief Removes a record from the calendar list.
+ * @details If the record is the current record, then the current record is changed to the next record.\n
+ *          If the record is the last record then the current record will be @c NULL.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  list    The calendar list handle
+ * @param[in]  record  The record handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NO_DATA             Requested data does not exist
+ *
+ * @see calendar_list_add()
+ */
+int calendar_list_remove( calendar_list_h list, calendar_record_h record );
+
+/**
+ * @brief Retrieves a record from the calendar list.
+ * @details The default current record is the first record.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks You MUST NOT destroy the @a record handle.
+ *          It is destroyed automatically when the @a list is destroyed.
+ *
+ * @param[in]  list        The calendar list handle
+ * @param[out] record      The record handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NO_DATA             Requested data does not exist
+ */
+int calendar_list_get_current_record_p( calendar_list_h list, calendar_record_h* record );
+
+/**
+ * @brief Moves a calendar list to the previous position.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  list  The calendar list handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NO_DATA             Requested data does not exist
+ *
+ * @see calendar_list_next()
+ */
+int calendar_list_prev( calendar_list_h list );
+
+/**
+ * @brief Moves a calendar list to the next position.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  list  The calendar list handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NO_DATA             Requested data does not exist
+ *
+ * @see calendar_list_prev()
+ */
+int calendar_list_next( calendar_list_h list );
+
+/**
+ * @brief Moves a calendar list to the first position.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  list  The calendar list handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @see calendar_list_last()
+ */
+int calendar_list_first( calendar_list_h list );
+
+/**
+ * @brief Moves a calendar list to the last position.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  list  The calendar list handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @see calendar_list_first()
+ */
+int calendar_list_last( calendar_list_h list );
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_SOCIAL_CALENDAR_LIST_H__ */
+
diff --git a/include/calendar_query.h b/include/calendar_query.h
new file mode 100644 (file)
index 0000000..7ef9423
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_SOCIAL_CALENDAR_QUERY_H__
+#define __TIZEN_SOCIAL_CALENDAR_QUERY_H__
+
+#include <calendar_types.h>
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file calendar_query.h
+ */
+
+/**
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_QUERY_MODULE
+ * @{
+ */
+
+/**
+ * @brief Creates a query handle.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks You must release @a query using calendar_query_destroy().
+ *
+ * @param[in]   view_uri   The view URI of a query
+ * @param[out]  query     The filter handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ *
+ * @pre     calendar_connect() should be called to initialize.
+ *
+ * @see calendar_query_destroy()
+ */
+int calendar_query_create( const char* view_uri, calendar_query_h* query );
+
+/**
+ * @brief Destroys a query handle.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in] query   The query handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE               Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER  Invalid parameter
+ *
+ * @see calendar_query_create()
+ */
+int calendar_query_destroy( calendar_query_h query );
+
+/**
+ * @brief Adds property IDs for projection.
+ *
+ * @details Property IDs can be of one of the properties of view_uri which is used in calendar_query_create().
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   query               The query handle
+ * @param[in]   property_id_array   The property ID array
+ * @param[in]   count               The number of property IDs
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ */
+int calendar_query_set_projection(calendar_query_h query, unsigned int property_id_array[], int count);
+
+/**
+ * @brief Sets the "distinct" option for projection.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   query   The query handle
+ * @param[in]   set     If @c true it is set,
+ *                      otherwise if @c false it is unset
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ */
+int calendar_query_set_distinct(calendar_query_h query, bool set);
+
+/**
+ * @brief Sets the filter for a query.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  query    The query handle
+ * @param[in]  filter   The filter handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NO_DATA             Requested data does not exist
+ *
+ * @see calendar_query_add_operator()
+ */
+int calendar_query_set_filter(calendar_query_h query, calendar_filter_h filter);
+
+/**
+ * @brief Sets the sort mode for a query.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   query           The query handle
+ * @param[in]   property_id     The property ID to sort
+ * @param[in]   is_ascending    If @c true it sorts in the ascending order,
+ *                              otherwise if @c false it sorts in the descending order
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ */
+int calendar_query_set_sort(calendar_query_h query, unsigned int property_id, bool is_ascending);
+
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_SOCIAL_CALENDAR_QUERY_H__ */
+
diff --git a/include/calendar_record.h b/include/calendar_record.h
new file mode 100644 (file)
index 0000000..7bae078
--- /dev/null
@@ -0,0 +1,447 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_SOCIAL_CALENDAR_RECORD_H__
+#define __TIZEN_SOCIAL_CALENDAR_RECORD_H__
+
+#include <calendar_types.h>
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file calendar_record.h
+ */
+
+/**
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_RECORD_MODULE
+ * @{
+ */
+
+/**
+ * @brief Creates a record handle.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks You must release @a record using calendar_record_destroy().
+ *
+ * @param[in]  view_uri    The view URI
+ * @param[out] out_record  The record handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ *
+ * @pre     calendar_connect() should be called to initialize.
+ *
+ * @see calendar_record_destroy()
+ */
+int calendar_record_create( const char* view_uri, calendar_record_h* out_record );
+
+/**
+ * @brief Destroys a record handle and releases all its resources.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  record              The record handle
+ * @param[in]  delete_child    If @c true, child records are destroyed automatically,
+ *                              otherwise @c false
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                 Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER    Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED        Operation not permitted
+ *
+ * @see calendar_record_create()
+ */
+int calendar_record_destroy( calendar_record_h record, bool delete_child );
+
+/**
+ * @brief Makes a clone of a record handle.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks You must release @a cloned_record using calendar_record_destroy().
+ *
+ * @param[in]  record          The record handle
+ * @param[out] out_record      The cloned record handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                    Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER       Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED           Operation not permitted
+ *
+ * @see calendar_record_destroy()
+ */
+int calendar_record_clone( calendar_record_h record, calendar_record_h* out_record );
+
+/**
+ * @brief Gets a URI string from a record.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   record   The record handle
+ * @param[out]  uri      The URI of the record
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                 Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER    Invalid parameter
+ */
+int calendar_record_get_uri_p( calendar_record_h record, char** uri );
+
+/**
+ * @brief Gets a string from a record.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks You must release @a value using free().
+ *
+ * @param[in]   record        The record handle
+ * @param[in]   property_id   The property ID
+ * @param[out]  out_str       The result value
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ *
+ * @see calendar_record_get_str_p()
+ * @see calendar_record_set_str()
+ */
+int calendar_record_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
+
+/**
+ * @brief Gets a string pointer from a record.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks You MUST NOT release @a value.
+ *
+ * @param[in]   record         The record handle
+ * @param[in]   property_id       The property ID
+ * @param[out]  out_str        The result value
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ *
+ * @see calendar_record_get_str()
+ * @see calendar_record_set_str()
+ */
+int calendar_record_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
+
+/**
+ * @brief Gets an integer value from a record.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   record          The record handle
+ * @param[in]   property_id     The property ID
+ * @param[out]  out_value       The result value
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ *
+ * @see calendar_record_set_int()
+ */
+int calendar_record_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
+
+/**
+ * @brief Gets a double value from a record.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   record          The record handle
+ * @param[in]   property_id     The property ID
+ * @param[out]  out_value       The result value
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ *
+ * @see calendar_record_set_double()
+ */
+int calendar_record_get_double( calendar_record_h record, unsigned int property_id, double* out_value );
+
+/**
+ * @brief Gets a long long integer value from a record.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   record          The record handle
+ * @param[in]   property_id        The property ID
+ * @param[out]  out_value       The result value
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ *
+ * @see calendar_record_set_lli()
+ */
+int calendar_record_get_lli( calendar_record_h record, unsigned int property_id, long long int* out_value );
+
+/**
+ * @brief Gets a calendar_caltime_s value from a record.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   record          The record handle
+ * @param[in]   property_id     The property ID
+ * @param[out]  out_value       The result value
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ *
+ * @see calendar_record_set_caltime()
+ */
+int calendar_record_get_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s* out_value );
+
+/**
+ * @brief Sets a string to a record.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  record          The record handle
+ * @param[in]  property_id     The property ID
+ * @param[in]  value           The value to be set
+ *
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ * @retval      #CALENDAR_ERROR_NONE                  Successful
+ * @retval      #CALENDAR_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval     #CALENDAR_ERROR_NOT_PERMITTED         Operation not permitted
+ *
+ * @see calendar_record_get_str()
+ * @see calendar_record_get_str_p()
+ */
+int calendar_record_set_str( calendar_record_h record, unsigned int property_id, const char* value );
+
+/**
+ * @brief Sets an integer value to a record.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  record          The record handle
+ * @param[in]  property_id         The property ID
+ * @param[in]  value           The value to be set
+ *
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ * @retval      #CALENDAR_ERROR_NONE                  Successful
+ * @retval      #CALENDAR_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval     #CALENDAR_ERROR_NOT_PERMITTED         Operation not permitted
+ *
+ * @see calendar_record_get_int()
+ */
+int calendar_record_set_int( calendar_record_h record, unsigned int property_id, int value );
+
+/**
+ * @brief Sets a double value to a record.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  record          The record handle
+ * @param[in]  property_id     The property ID
+ * @param[in]  value           The value to be set
+ *
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ * @retval      #CALENDAR_ERROR_NONE                  Successful
+ * @retval      #CALENDAR_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval     #CALENDAR_ERROR_NOT_PERMITTED         Operation not permitted
+ *
+ * @see calendar_record_get_double()
+ */
+int calendar_record_set_double( calendar_record_h record, unsigned int property_id, double value );
+
+/**
+ * @brief Sets a long long integer value to a record.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  record          The record handle
+ * @param[in]  property_id     The property ID
+ * @param[in]  value           The value to be set
+ *
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ * @retval      #CALENDAR_ERROR_NONE                  Successful
+ * @retval      #CALENDAR_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval     #CALENDAR_ERROR_NOT_PERMITTED         Operation not permitted
+ *
+ * @see calendar_record_get_lli()
+ */
+int calendar_record_set_lli( calendar_record_h record, unsigned int property_id, long long int value );
+
+/**
+ * @brief Sets a calendar_time_s value to a record.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  record          The record handle
+ * @param[in]  property_id     The property ID
+ * @param[in]  value           The value to be set
+ *
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ * @retval      #CALENDAR_ERROR_NONE                  Successful
+ * @retval      #CALENDAR_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval     #CALENDAR_ERROR_NOT_PERMITTED         Operation not permitted
+ *
+ * @see calendar_record_get_caltime()
+ */
+int calendar_record_set_caltime( calendar_record_h record, unsigned int property_id, calendar_time_s value );
+
+/**
+ * @brief Adds a child record to the parent record.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  record          The parent record handle
+ * @param[in]  property_id     The property ID
+ * @param[in]  child_record    The handle of the child record to be added to the parent record
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                  Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER     Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED                Operation not permitted
+ *
+ * @see calendar_record_remove_child_record()
+ */
+int calendar_record_add_child_record( calendar_record_h record, unsigned int property_id, calendar_record_h child_record );
+
+/**
+ * @brief Removes a child record from the parent record.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  record        The parent record handle
+ * @param[in]  property_id       The property ID
+ * @param[in]  child_record  The handle of the child record to be removed from the parent record
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED              Operation not permitted
+ *
+ * @see calendar_record_add_child_record()
+ */
+int calendar_record_remove_child_record( calendar_record_h record, unsigned int property_id, calendar_record_h child_record );
+
+/**
+ * @brief Gets the number of child records in a record.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  record          The parent record handle
+ * @param[in]  property_id         The property ID
+ * @param[out] count           The child record count
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ *
+ * @see calendar_record_add_child_record()
+ * @see calendar_record_remove_child_record()
+ */
+int calendar_record_get_child_record_count( calendar_record_h record, unsigned int property_id,unsigned int* count );
+
+/**
+ * @brief Gets a child record handle pointer from the parent record.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks You MUST NOT release @a child_record. \n It is released when the parent record handle is destroyed.
+ *
+ * @param[in]   record          The record handle
+ * @param[in]   property_id        The property ID
+ * @param[in]   index           The index of the child record
+ * @param[out]  child_record    The child record handle pointer
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ *
+ * @see calendar_record_add_child_record()
+ * @see calendar_record_remove_child_record()
+ * @see calendar_record_get_child_record_count()
+ */
+int calendar_record_get_child_record_at_p( calendar_record_h record, unsigned int property_id, int index, calendar_record_h* child_record );
+
+/**
+ * @brief Makes a clone of a given record's child record list.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks You must release @a cloned_list using calendar_list_destroy().
+ *
+ * @param[in]   record          The record handle
+ * @param[in]   property_id     The property ID
+ * @param[out]  out_list           The cloned list handle
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ *
+ * @see calendar_list_destroy()
+ */
+int calendar_record_clone_child_record_list( calendar_record_h record, unsigned int property_id, calendar_list_h* out_list );
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_SOCIAL_CALENDAR_RECORD_H__ */
+
diff --git a/include/calendar_reminder.h b/include/calendar_reminder.h
new file mode 100644 (file)
index 0000000..99b419a
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_SOCIAL_CALENDAR_REMINDER_H__
+#define __TIZEN_SOCIAL_CALENDAR_REMINDER_H__
+
+#include <calendar_types.h>
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file calendar_reminder.h
+ */
+
+/**
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_REMINDER_MODULE
+ * @{
+ */
+
+/**
+ * @brief Called when an alarm is alerted.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   param  Value string like id=value&time=value&tick=value&unit=value&type=value
+ * @param[in]   user_data   The user data passed from the callback registration function
+ *
+ * @see calendar_reminder_add_cb()
+ */
+typedef void (*calendar_reminder_cb)(const char *param, void* user_data);
+
+/**
+ * @brief Adds a callback to get a notification when an alarm alerts.
+ *
+ * @since_tizen 2.3
+ *
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/calendar.read
+ *
+ * @param[in]   callback     The callback to be added
+ * @param[in]   user_data       The user data
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE            Successful
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY   Out of memory
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED   Operation not permitted
+ * @retval  #CALENDAR_ERROR_IPC             Unknown IPC error
+ *
+ * @see calendar_reminder_remove_cb()
+ */
+int calendar_reminder_add_cb(calendar_reminder_cb callback, void *user_data);
+
+/**
+ * @brief Removes a callback to get a notification when an alarm alerts.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]   callback       The callback to be removed
+ * @param[in]   user_data      The user data
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE        Successful
+ * @retval  #CALENDAR_ERROR_DB_FAILED   Database operation failure
+ *
+ * @see calendar_reminder_add_cb()
+ */
+int calendar_reminder_remove_cb(calendar_reminder_cb callback, void *user_data);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_SOCIAL_CALENDAR_REMINDER_H__ */
+
diff --git a/include/calendar_service.h b/include/calendar_service.h
new file mode 100644 (file)
index 0000000..9134ef2
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __TIZEN_SOCIAL_CALENDAR_SERVICE_H__
+#define __TIZEN_SOCIAL_CALENDAR_SERVICE_H__
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file calendar_service.h
+ */
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @defgroup CAPI_SOCIAL_CALENDAR_SVC_COMMON_MODULE Common
+ * @brief The calendar common API provides the set of definitions and interfaces to initialize and deinitialize.
+ *
+ * @section CAPI_SOCIAL_CALENDAR_SVC_COMMON_MODULE_HEADER Required Header
+ *  \#include <calendar.h>
+ *
+ * <BR>
+ * @{
+ */
+
+/**
+ * @brief Connects to the calendar service.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Opening the connection is necessary to access the calendar database and perform operations such as fetching, inserting, or updating records.\n
+ *          The execution of calendar_connect() and calendar_disconnect() could slow down your application, so you are recommended not to call them frequently.
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_SYSTEM              Error from another modules
+ *
+ * @see  calendar_disconnect()
+ */
+int calendar_connect(void);
+
+/**
+ * @brief Disconnects from the calendar service.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks If there is no opened connection, this function returns #CALENDAR_ERROR_DB_FAILED.
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ *
+ * @see calendar_connect()
+ */
+int calendar_disconnect(void);
+
+/**
+ * @brief Connects to the calendar service on a thread.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Opening a connection is necessary to access the calendar database and perform operations such as fetching, inserting, or updating records.\n
+ *          On a thread environment with calendar_connect(), request in one thread could fail, while another request connection is working in the other thread.
+ *          To prevent request failure, calendar_connect_on_thread() is recommended.
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE               Successful
+ * @retval  #CALENDAR_ERROR_DB_FAILED          Database operation failure
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED  Permission denied. This application does not have the privilege to call this method
+ *
+ * @see  calendar_disconnect_on_thread()
+ */
+int calendar_connect_on_thread(void);
+
+/**
+ * @brief Disconnects from the calendar service on a thread.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks If there is no opened connection, this function returns #CALENDAR_ERROR_DB_FAILED.
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ *
+ * @see calendar_connect_on_thread()
+ */
+int calendar_disconnect_on_thread(void);
+
+/**
+ * @brief Connects to the calendar service.
+ *
+ * @since_tizen 2.3
+ *
+ * @remarks Opening a connection is necessary to access the calendar database and perform operations such as fetching, inserting, or updating records.\n
+ *          Before the calendar-service daemon is ready, if you call calendar_connect(), it could fail.
+ *          It is recommended to call this API with #CALENDAR_CONNECT_FLAG_RETRY flags in such a situation.
+ *
+ * @param[in]   flags  calendar_connect_flag
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                           Successful
+ * @retval  #CALENDAR_ERROR_DB_FAILED           Database operation failure
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NOT_PERMITTED       Operation not permitted
+ * @retval  #CALENDAR_ERROR_PERMISSION_DENIED   Permission denied. This application does not have the privilege to call this method.
+ * @retval  #CALENDAR_ERROR_IPC                 Unknown IPC error
+ * @retval  #CALENDAR_ERROR_SYSTEM              Error from another modules
+ *
+ * @see  calendar_disconnect(), CALENDAR_CONNECT_FLAG_RETRY
+ */
+int calendar_connect_with_flags(unsigned int flags);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_SOCIAL_CALENDAR_SERVICE_H__ */
+
diff --git a/include/calendar_types.h b/include/calendar_types.h
new file mode 100644 (file)
index 0000000..db49506
--- /dev/null
@@ -0,0 +1,527 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_SOCIAL_CALENDAR_TYPES_H__
+#define __TIZEN_SOCIAL_CALENDAR_TYPES_H__
+
+#include <stdint.h>
+#include <tizen.h>
+#include <calendar_errors.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#define _CALENDAR_HANDLE(A) typedef struct __##A* A;
+
+#define _CALENDAR_BEGIN_VIEW() \
+               typedef struct{ \
+                       const char* _uri;
+#define _CALENDAR_PROPERTY_INT(property_id_name)        unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_STR(property_id_name)        unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_DOUBLE(property_id_name)     unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_LLI(property_id_name)        unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_CALTIME(property_id_name)    unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_CHILD_MULTIPLE(property_id_name) unsigned int property_id_name;
+#define _CALENDAR_END_VIEW(name) } name##_property_ids; \
+    extern API const name##_property_ids name;
+
+#define _CALENDAR_BEGIN_READ_ONLY_VIEW() \
+        typedef struct{ \
+            const char* _uri;
+#define _CALENDAR_PROPERTY_PROJECTION_INT(property_id_name)        unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_PROJECTION_STR(property_id_name)        unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_PROJECTION_DOUBLE(property_id_name)     unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_PROJECTION_LLI(property_id_name)        unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_PROJECTION_CALTIME(property_id_name)    unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_FILTER_INT(property_id_name)        unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_FILTER_STR(property_id_name)        unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_FILTER_DOUBLE(property_id_name)     unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_FILTER_LLI(property_id_name)        unsigned int property_id_name;
+#define _CALENDAR_PROPERTY_FILTER_CALTIME(property_id_name)    unsigned int property_id_name;
+#define _CALENDAR_END_READ_ONLY_VIEW(name) } name##_property_ids; \
+    extern API const name##_property_ids name;
+
+_CALENDAR_HANDLE( calendar_record_h )
+_CALENDAR_HANDLE( calendar_filter_h )
+_CALENDAR_HANDLE( calendar_list_h )
+_CALENDAR_HANDLE( calendar_query_h )
+
+
+/**
+ * @file calendar_types.h
+ */
+
+/**
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_DATABASE_MODULE
+ * @{
+ */
+/**
+ * @brief Definition for a calendar connect flag.
+ *
+ * @since_tizen 2.3
+ */
+#define CALENDAR_CONNECT_FLAG_NONE         0x00000000
+/**
+ * @brief Definition for a calendar connect flag.
+ *
+ * @since_tizen 2.3
+ */
+#define CALENDAR_CONNECT_FLAG_RETRY        0x00000001
+
+/**
+ * @brief Definition for a default event calendar book database ID.
+ *
+ * @since_tizen 2.3
+ */
+#define DEFAULT_EVENT_CALENDAR_BOOK_ID           1
+
+/**
+ * @brief Definition for a default to-do calendar book database ID.
+ *
+ * @since_tizen 2.3
+ */
+#define DEFAULT_TODO_CALENDAR_BOOK_ID            2
+
+/**
+ * @brief Definition for a default birthday calendar book database ID.
+ *
+ * @since_tizen 2.3
+ */
+#define DEFAULT_BIRTHDAY_CALENDAR_BOOK_ID        3
+
+/**
+ * @brief Definition for no due date of a to-do.
+ *
+ * @since_tizen 2.3
+ */
+#define CALENDAR_TODO_NO_DUE_DATE   INT64_MAX
+
+/**
+ * @brief Definition for no start date of a to-do.
+ *
+ * @since_tizen 2.3
+ */
+#define CALENDAR_TODO_NO_START_DATE (-INT64_MAX)
+
+/**
+ * @brief Definition for no until of a record.
+ *
+ * @since_tizen 2.3
+ */
+#define CALENDAR_RECORD_NO_UNTIL    INT64_MAX
+
+/**
+ * @brief Definition for no coordinate(latitude/longitude) of a record.
+ *
+ * @since_tizen 2.3
+ */
+#define CALENDAR_RECORD_NO_COORDINATE 1000.0
+
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_FILTER_MODULE
+ * @{
+ */
+
+/**
+ * @brief Definition for all calendar books.
+ *
+ * @since_tizen 2.3
+ */
+#define CALENDAR_BOOK_FILTER_ALL                    -1
+
+/**
+ * @brief Enumeration for the filter match type of a string.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_MATCH_EXACTLY,                 /**< Full string, case-sensitive */
+       CALENDAR_MATCH_FULLSTRING,              /**< Full string, case-insensitive */
+       CALENDAR_MATCH_CONTAINS,                /**< Sub string, case-insensitive */
+       CALENDAR_MATCH_STARTSWITH,              /**< Start with, case-insensitive */
+       CALENDAR_MATCH_ENDSWITH,                /**< End with, case-insensitive */
+       CALENDAR_MATCH_EXISTS,                  /**< IS NOT NULL */
+       CALENDAR_MATCH_STR_MAX        /**< Calendar match string flag max enum count */
+} calendar_match_str_flag_e;
+
+/**
+ * @brief Enumeration for the filter match type of an integer.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_MATCH_EQUAL,                                   /**< '=' */
+       CALENDAR_MATCH_GREATER_THAN,                    /**< '>' */
+       CALENDAR_MATCH_GREATER_THAN_OR_EQUAL,   /**< '>=' */
+       CALENDAR_MATCH_LESS_THAN,                               /**< '<' */
+       CALENDAR_MATCH_LESS_THAN_OR_EQUAL,              /**< '<=' */
+       CALENDAR_MATCH_NOT_EQUAL,               /**< '<>', this flag can yield poor performance */
+       CALENDAR_MATCH_NONE,                                            /**< IS NULL */
+       CALENDAR_MATCH_INT_MAX                                  /**< Calendar match integer flag max enum count */
+} calendar_match_int_flag_e;
+
+/**
+ * @brief Enumeration for a filter operator.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum {
+       CALENDAR_FILTER_OPERATOR_AND,   /**< AND */
+       CALENDAR_FILTER_OPERATOR_OR,            /**< OR */
+       CALENDAR_FILTER_OPERATOR_MAX    /**< Calendar filter operator max enum count */
+} calendar_filter_operator_e;
+
+/**
+ * @}
+ */
+
+/**
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_RECORD_MODULE
+ * @{
+ */
+
+/**
+ * @brief Enumeration for the calendar book type.
+ *
+ * @details "OR"ing is supported.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+    CALENDAR_BOOK_TYPE_NONE          = 0,       /**< Default calendar book type */
+    CALENDAR_BOOK_TYPE_EVENT         = 1<<0,        /**< Event calendar book type */
+    CALENDAR_BOOK_TYPE_TODO          = 1<<1     /**< To-do calendar book type */
+} calendar_book_type_e;
+
+/**
+ * @brief Enumeration for the calendar sensitivity type.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+    CALENDAR_SENSITIVITY_PUBLIC          = 0,  /**< Public Sensitivity */
+    CALENDAR_SENSITIVITY_PRIVATE,                              /**< Private Sensitivity */
+    CALENDAR_SENSITIVITY_CONFIDENTIAL                  /**< Confidential Sensitivity */
+} calendar_sensitivity_e;
+
+/**
+ * @brief Enumeration for the attendee status.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_ATTENDEE_STATUS_PENDING        = 0,    /**< Pending status */
+       CALENDAR_ATTENDEE_STATUS_ACCEPTED,                      /**< Accepted status */
+       CALENDAR_ATTENDEE_STATUS_DECLINED,                      /**< Declined status */
+       CALENDAR_ATTENDEE_STATUS_TENTATIVE,                     /**< Tentative status */
+       CALENDAR_ATTENDEE_STATUS_DELEGATED,                     /**< Delegated status */
+       CALENDAR_ATTENDEE_STATUS_COMPLETED,                     /**< Completed status */
+       CALENDAR_ATTENDEE_STATUS_IN_PROCESS,                    /**< In process status */
+       CALENDAR_ATTENDEE_STATUS_MAX,    /**< Calendar attendee status max enum count */
+}calendar_attendee_status_e;
+
+/**
+ * @brief Enumeration for the attendee role.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT  = 0,    /**< Participation is required */
+       CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT,                 /**< Accepted status */
+       CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT,                 /**< Non-Participant */
+       CALENDAR_ATTENDEE_ROLE_CHAIR,                                   /**< Chairperson */
+       CALENDAR_ATTENDEE_ROLE_MAX,    /**< Calendar attendee role max enum count */
+}calendar_attendee_role_e;
+
+/**
+ * @brief Enumeration for the attendee cutype.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_ATTENDEE_CUTYPE_INDIVIDUAL = 0,        /**< Individual cutype */
+       CALENDAR_ATTENDEE_CUTYPE_GROUP,             /**< Group cutype */
+       CALENDAR_ATTENDEE_CUTYPE_RESOURCE,          /**< Resource cutype */
+       CALENDAR_ATTENDEE_CUTYPE_ROOM,              /**< Room cutype */
+       CALENDAR_ATTENDEE_CUTYPE_UNKNOWN,           /**< Unknown cutype */
+       CALENDAR_ATTENDEE_CUTYPE_MAX,    /**< Calendar attendee cutype max enum count */
+}calendar_attendee_cutyep_e;
+
+/**
+ * @brief Enumeration for the alarm time unit type of an event, such as minutes, hours, days, and so on.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+    CALENDAR_ALARM_NONE = -1,                  /**< No reminder set */
+    CALENDAR_ALARM_TIME_UNIT_SPECIFIC = 1,     /**< Specific in seconds */
+    CALENDAR_ALARM_TIME_UNIT_MINUTE = 60,      /**< Alarm time unit in minutes */
+    CALENDAR_ALARM_TIME_UNIT_HOUR = 3600,      /**< Alarm time unit in hours */
+    CALENDAR_ALARM_TIME_UNIT_DAY = 86400,      /**< Alarm time unit in days */
+    CALENDAR_ALARM_TIME_UNIT_WEEK = 604800,    /**< Alarm time unit in weeks */
+} calendar_alarm_time_unit_type_e;
+
+/**
+ * @brief Enumeration for the alarm action.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_ALARM_ACTION_AUDIO = 0, /**< Audio action */
+       CALENDAR_ALARM_ACTION_DISPLAY,   /**< Display action */
+       CALENDAR_ALARM_ACTION_EMAIL,     /**< Email action */
+       CALENDAR_ALARM_ACTION_MAX,    /**< Calenar alarm action max enum count */
+}calendar_alarm_action_e;
+
+/**
+ * @brief Enumeration for the frequency of an event's recurrence.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+    CALENDAR_RECURRENCE_NONE,           /**< No recurrence event */
+    CALENDAR_RECURRENCE_DAILY,          /**< An event occurs every day */
+    CALENDAR_RECURRENCE_WEEKLY,         /**< An event occurs on the same day of every week \n According to the week flag, the event will recur every day of the week */
+    CALENDAR_RECURRENCE_MONTHLY,        /**< An event occurs on the same day of every month */
+    CALENDAR_RECURRENCE_YEARLY         /**< An event occurs on the same day of every year */
+} calendar_recurrence_frequency_e;
+
+/**
+ * @brief Enumeration for the event status.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+    CALENDAR_EVENT_STATUS_NONE         = 0x01,         /**< No status */
+    CALENDAR_EVENT_STATUS_TENTATIVE    = 0x02,         /**< The event is tentative */
+    CALENDAR_EVENT_STATUS_CONFIRMED    = 0x04,         /**< The event is confirmed */
+    CALENDAR_EVENT_STATUS_CANCELLED    = 0x08          /**< The event is canceled */
+}calendar_event_status_e;
+
+/**
+ * @brief Enumeration for the busy status of an event.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+    CALENDAR_EVENT_BUSY_STATUS_FREE = 0,               /**< The free status */
+    CALENDAR_EVENT_BUSY_STATUS_BUSY,                   /**< The busy status */
+    CALENDAR_EVENT_BUSY_STATUS_UNAVAILABLE,            /**< The unavailable status */
+    CALENDAR_EVENT_BUSY_STATUS_TENTATIVE               /**< The tentative status */
+}calendar_event_busy_status_e;
+/**
+ * @brief Enumeration for the calendar event item's priority.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_EVENT_PRIORITY_NONE            = 0x01, /**< No priority */
+       CALENDAR_EVENT_PRIORITY_LOW         = 0x08,     /**< Low priority */
+       CALENDAR_EVENT_PRIORITY_NORMAL          = 0x04, /**< Normal priority */
+       CALENDAR_EVENT_PRIORITY_HIGH            = 0x02, /**< High priority */
+} calendar_event_priority_e;
+
+/**
+ * @brief Enumeration for the calendar to-do item's priority.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_TODO_PRIORITY_NONE                     = 0x01, /**< No priority */
+       CALENDAR_TODO_PRIORITY_LOW          = 0x08,     /**< Low priority */
+       CALENDAR_TODO_PRIORITY_NORMAL           = 0x04, /**< Normal priority */
+       CALENDAR_TODO_PRIORITY_HIGH                     = 0x02, /**< High priority */
+} calendar_todo_priority_e;
+
+/**
+ * @brief Enumeration for the status of a to-do.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+    CALENDAR_TODO_STATUS_NONE                  = 0x0100,       /**< No status */
+    CALENDAR_TODO_STATUS_NEEDS_ACTION  = 0x0200,       /**< Needs action status */
+    CALENDAR_TODO_STATUS_COMPLETED             = 0x0400,       /**< Completed status */
+    CALENDAR_TODO_STATUS_IN_PROCESS            = 0x0800,       /**< Work in process status */
+    CALENDAR_TODO_STATUS_CANCELED              = 0x1000        /**< Canceled status */
+} calendar_todo_status_e;
+
+/**
+ * @brief Enumeration for the time type.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_TIME_UTIME = 0,                        /**< Unix time */
+       CALENDAR_TIME_LOCALTIME,                        /**< Local time */
+} calendar_time_type_e;
+
+/**
+ * @brief Enumeration for the range type.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_RANGE_UNTIL,           /**< Range until */
+       CALENDAR_RANGE_COUNT,           /**< Range count */
+       CALENDAR_RANGE_NONE,            /**< No range */
+} calendar_range_type_e;
+
+/**
+ * @brief Enumeration for the system type.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_SYSTEM_NONE,                              /**< Locale's default calendar */
+       CALENDAR_SYSTEM_GREGORIAN,                         /**< Locale's default calendar */
+       CALENDAR_SYSTEM_EAST_ASIAN_LUNISOLAR, /**< East asian lunisolar calendar */
+} calendar_system_type_e;
+
+/**
+ * @brief Enumeration for the meeting status.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_MEETING_STATUS_NOTMEETING = 0,   /**< No meeting */
+       CALENDAR_MEETING_STATUS_MEETING,                                  /**< Meeting exists */
+       CALENDAR_MEETING_STATUS_RECEIVED,                         /**< Meeting received */
+       CALENDAR_MEETING_STATUS_CANCELED,                         /**< Meeting canceled */
+} calendar_meeting_status_e;
+
+/**
+ * @brief Enumeration for weekdays.
+ * @details Same value as UCalendarDaysOfWeek in ICU.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_SUNDAY = 1,                    /**< Sunday */
+       CALENDAR_MONDAY,                                /**< Monday */
+       CALENDAR_TUESDAY,                               /**< Tuesday */
+       CALENDAR_WEDNESDAY,                             /**< Wednesday */
+       CALENDAR_THURSDAY,                              /**< Thursday */
+       CALENDAR_FRIDAY,                                /**< Friday */
+       CALENDAR_SATURDAY,                              /**< Saturday */
+}calendar_days_of_week_e;
+
+/**
+ * @brief Enumeration for the modified status of a record.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+    CALENDAR_RECORD_MODIFIED_STATUS_INSERTED = 0,              /**< The record is inserted */
+    CALENDAR_RECORD_MODIFIED_STATUS_UPDATED,                           /**< The record is updated */
+    CALENDAR_RECORD_MODIFIED_STATUS_DELETED                            /**< The record is deleted */
+}calendar_record_modified_status_e;
+
+/**
+ * @brief The structure of time.
+ *
+ * @since_tizen 2.3
+ */
+typedef struct
+{
+    calendar_time_type_e type; /**< type */
+    union {
+        long long int utime;   /**< utime */
+        struct {
+            int year;                  /**< year */
+            int month;                 /**< month */
+            int mday;                  /**< mday */
+            int hour;                  /**< hour */
+            int minute;                        /**< minute */
+            int second;                        /**< second */
+                       bool is_leap_month;     /**< leap month */
+        }date;
+    }time;
+}calendar_time_s;
+
+/**
+ * @brief Enumeration for the type of a record.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum
+{
+       CALENDAR_RECORD_TYPE_NONE = 0,                   /**< No record type */
+       CALENDAR_RECORD_TYPE_CALENDAR_BOOK,              /**< Book type */
+       CALENDAR_RECORD_TYPE_EVENT,                              /**< Event type */
+       CALENDAR_RECORD_TYPE_TODO,                                       /**< Todo type */
+}calendar_record_type_e;
+
+/**
+ * @brief Enumeration for the book mode.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum {
+       CALENDAR_BOOK_MODE_NONE = 0, /**< All modules can read and write records of this calendar_book */
+       CALENDAR_BOOK_MODE_RECORD_READONLY, /**< All modules can only read records of this calendar book */
+} calendar_book_mode_e;
+
+/**
+ * @brief Enumeration for the sync event type.
+ *
+ * @since_tizen 2.3
+ */
+typedef enum {
+       CALENDAR_BOOK_SYNC_EVENT_FOR_ME = 0,            /**< This book would not be synced to others except me */
+       CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_DELETE,  /**< This book would be sync to everyone and deleted events would be disappeared on time */
+       CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_REMAIN,  /**< This book would be sync to everyone but deleted events would be remained. deleted events is removed by calendar_db_clean_after_sync() API*/
+} calendar_book_sync_event_type_e;
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__TIZEN_SOCIAL_CALENDAR_TYPES_H__
diff --git a/include/calendar_vcalendar.h b/include/calendar_vcalendar.h
new file mode 100644 (file)
index 0000000..978aff6
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __TIZEN_SOCIAL_CALENDAR_VCALENDAR_H__
+#define __TIZEN_SOCIAL_CALENDAR_VCALENDAR_H__
+
+#include <calendar_view.h>
+
+#ifndef API
+#define API __attribute__ ((visibility("default")))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file calendar_vcalendar.h
+ */
+
+/**
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VCALENDAR_MODULE
+ * @{
+ */
+
+/**
+ * @brief Retrieves a vcalendar stream from a calendar list.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  calendar_list       The calendar list handle
+ * @param[out] vcalendar_stream    The vcalendar stream
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NO_DATA             Requested data does not exist
+ */
+int calendar_vcalendar_make_from_records(calendar_list_h calendar_list, char **vcalendar_stream);
+
+/**
+ * @brief Retrieves all calendars from a vcalendar stream.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  vcalendar_stream    The vcalendar stream
+ * @param[out] calendar_list       The calendar list handle
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval  #CALENDAR_ERROR_NO_DATA             Requested data does not exist
+ *
+ * @pre     calendar_connect() should be called to initialize.
+ *
+ */
+int calendar_vcalendar_parse_to_calendar(const char* vcalendar_stream, calendar_list_h *calendar_list);
+
+/**
+ * @brief Called to get a record handle of
+ * \ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_event or \ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_todo.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  record     The record handle (\ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_event or \ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_todo)
+ * @param[in]  user_data  The user data passed from the foreach function
+ *
+ * @return     @c true to continue with the next iteration of the loop,
+ *          otherwise @c false to break out of the loop
+ *
+ * @pre calendar_vcalendar_parse_to_calendar_foreach() will invoke this callback.
+ *
+ * @see calendar_vcalendar_parse_to_calendar_foreach()
+ * @see calendar_record_get_uri_p()
+ */
+typedef bool (*calendar_vcalendar_parse_cb)(calendar_record_h record, void *user_data);
+
+/**
+ * @brief Retrieves all events or to-dos
+ * (\ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_event or \ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_todo) from a vCalendar file.
+ *
+ * @since_tizen 2.3
+ *
+ * @param[in]  vcalendar_file_path     The file path of the vCalendar stream file
+ * @param[in]  callback                The callback function to be invoked
+ * @param[in]  user_data               The user data to be passed to the callback function
+ *
+ * @return  @c 0 on success,
+ *          otherwise a negative error value
+ * @retval  #CALENDAR_ERROR_NONE                Successful
+ * @retval  #CALENDAR_ERROR_OUT_OF_MEMORY       Out of memory
+ * @retval  #CALENDAR_ERROR_INVALID_PARAMETER   Invalid parameter
+ *
+ * @pre  calendar_connect() should be called to initialize.
+ *
+ * @post This function invokes calendar_vcalendar_parse_cb().
+ *
+ * @see  calendar_vcalendar_parse_cb()
+ * @see  calendar_record_get_uri_p()
+ */
+int calendar_vcalendar_parse_to_calendar_foreach(const char *vcalendar_file_path, calendar_vcalendar_parse_cb callback, void *user_data);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_SOCIAL_CALENDAR_VCALENDAR_H__ */
+
diff --git a/include/calendar_view.h b/include/calendar_view.h
new file mode 100644 (file)
index 0000000..b027b2b
--- /dev/null
@@ -0,0 +1,1096 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_SOCIAL_CALENDAR_VIEW_H__
+#define __TIZEN_SOCIAL_CALENDAR_VIEW_H__
+
+#include <calendar_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_book _calendar_book view
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     <th> Read, Write </th>
+ *     <th> Description </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td><td> read only </td><td> Identifier of this calendar book view </td></tr>
+ *     <tr><td> integer </td><td> id </td><td> read only </td><td> DB record ID of the calendar book </td></tr>
+ *     <tr><td> string </td><td> uid </td><td> read, write </td><td> Unique identifier </td></tr>
+ *     <tr><td> string </td><td> name </td><td> read, write </td><td> Calendar book name </td></tr>
+ *     <tr><td> string </td><td> description </td><td> read, write </td><td> Calendar book description </td></tr>
+ *     <tr><td> string </td><td> color </td><td> read, write </td><td> Calendar book color for UX </td></tr>
+ *     <tr><td> string </td><td> location </td><td> read, write </td><td> Location of the event </td></tr>
+ *     <tr><td> integer </td><td> visibility </td><td> read, write </td><td> Visibility of the calendar book for UX</td></tr>
+ *     <tr><td> integer </td><td> sync_event </td><td> read, write </td><td> </td>Currently NOT Used</tr>
+ *     <tr><td> integer </td><td> account_id </td><td> read, write once </td><td> Account for this calendar </td></tr>
+ *     <tr><td> integer </td><td> store_type </td><td> read, write </td><td> Type of calendar contents(refer to the @ref calendar_book_type_e) </td></tr>
+ *     <tr><td> string </td><td> sync_data1 </td><td> read, write </td><td> Generic data for use by syncing </td></tr>
+ *     <tr><td> string </td><td> sync_data2 </td><td> read, write </td><td> Generic data for use by syncing </td></tr>
+ *     <tr><td> string </td><td> sync_data3 </td><td> read, write </td><td> Generic data for use by syncing </td></tr>
+ *     <tr><td> string </td><td> sync_data4 </td><td> read, write </td><td> Generic data for use by syncing </td></tr>
+ *     <tr><td> integer </td><td> mode </td><td> read, write </td><td> Calendar book mode (refer to the @ref calendar_book_mode_e) </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_VIEW()
+       _CALENDAR_PROPERTY_INT( id )            // read_only
+       _CALENDAR_PROPERTY_STR( uid )
+       _CALENDAR_PROPERTY_STR( name )
+       _CALENDAR_PROPERTY_STR( description )
+       _CALENDAR_PROPERTY_STR( color )
+       _CALENDAR_PROPERTY_STR( location )
+       _CALENDAR_PROPERTY_INT( visibility )
+       _CALENDAR_PROPERTY_INT( sync_event )
+       _CALENDAR_PROPERTY_INT( account_id )
+       _CALENDAR_PROPERTY_INT( store_type )
+       _CALENDAR_PROPERTY_STR( sync_data1 )
+       _CALENDAR_PROPERTY_STR( sync_data2 )
+       _CALENDAR_PROPERTY_STR( sync_data3 )
+       _CALENDAR_PROPERTY_STR( sync_data4 )
+       _CALENDAR_PROPERTY_INT( mode )
+_CALENDAR_END_VIEW( _calendar_book )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_event _calendar_event view
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     <th> Read, Write </th>
+ *     <th> Description </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td><td> read only </td><td>Identifier of this event view</td></tr>
+ *     <tr><td> integer </td><td> id </td><td> read only </td><td>DB record ID of the event</td></tr>
+ *     <tr><td> integer </td><td> calendar_book_id </td><td> read, write </td><td>ID of the calendar book to which the event belongs</td></tr>
+ *     <tr><td> string </td><td> summary </td><td> read, write </td><td>The short description of the event</td></tr>
+ *     <tr><td> string </td><td> description </td><td> read, write </td><td>The description of the event</td></tr>
+ *     <tr><td> string </td><td> location </td><td> read, write </td><td>The location of the event</td></tr>
+ *     <tr><td> string </td><td> categories </td><td> read, write </td><td>The category of the event. For example APPOINTMENT, BIRTHDAY</td></tr>
+ *     <tr><td> string </td><td> exdate </td><td> read, write </td><td>The exception list of the event. If this event has a recurrence rule, the instance of the exdate is removed. Format is "YYYYMMDD"(allday event) or "YYYYMMDDTHHMMSS".  Multiple exceptions can be included with a comma  </td></tr>
+ *     <tr><td> integer </td><td> event_status </td><td> read, write </td><td>Refer to the @ref calendar_event_status_e</td></tr>
+ *     <tr><td> integer </td><td> priority </td><td> read, write </td><td></td>Refer to the @ref calendar_event_priority_e</tr>
+ *     <tr><td> integer </td><td> timezone </td><td> read, write </td><td>The timezone_id of the event if it exists. Refer to the @ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_timezone</td></tr>
+ *     <tr><td> integer </td><td> person_id </td><td> read, write </td><td>The person_id of the event if the event is a birthday. Refer to the contacts-service</td></tr>
+ *     <tr><td> integer </td><td> busy_status </td><td> read, write </td><td>Refer to the @ref calendar_event_busy_status_e</td></tr>
+ *     <tr><td> integer </td><td> sensitivity </td><td> read, write </td><td>Refer to the @ref calendar_sensitivity_e </td></tr>
+ *     <tr><td> string </td><td> uid </td><td> read, write </td><td>The unique ID of the event</td></tr>
+ *     <tr><td> string </td><td> organizer_name </td><td> read, write </td><td>The name of organizer of the event</td></tr>
+ *     <tr><td> string </td><td> organizer_email </td><td> read, write </td><td>The email address of the organizer of the event</td></tr>
+ *     <tr><td> integer </td><td> meeting_status </td><td> read, write </td><td>Refer to the @ref calendar_meeting_status_e</td></tr>
+ *     <tr><td> integer </td><td> original_event_id </td><td> read, write </td><td>The ID of the original event if the event is an exception.</td></tr>
+ *     <tr><td> double </td><td> latitude </td><td> read, write </td><td> The latitude of the location of the event</td></tr>
+ *     <tr><td> double </td><td> longitude </td><td> read, write </td><td> The longitude of the location of the event</td></tr>
+ *     <tr><td> integer </td><td> email_id </td><td> read, write </td><td>ID of the email_id. Refer to the email-service.</td></tr>
+ *     <tr><td> long long int </td><td> created_time </td><td> read, write </td><td> The time when the event is created</td></tr>
+ *     <tr><td> long long int </td><td> last_modified_time </td><td> read only </td><td>The time when the event is updated</td></tr>
+ *     <tr><td> integer </td><td> is_deleted </td><td> read only </td><td></td></tr>
+ *     <tr><td> integer </td><td> freq </td><td> read, write </td><td>The frequent type of event recurrence. Refer to the @ref calendar_recurrence_frequency_e</td></tr>
+ *     <tr><td> integer </td><td> range_type </td><td> read, write </td><td>Refer to the @ref calendar_range_type_e</td></tr>
+ *     <tr><td> calendar time </td><td> until_time </td><td> read, write </td><td>The end time of the event recurrence. If the range_type is @ref CALENDAR_RANGE_UNTIL</td></tr>
+ *     <tr><td> integer </td><td> count </td><td> read, write </td><td>The count of the event recurrence. If the range_type is @ref CALENDAR_RANGE_COUNT</td></tr>
+ *     <tr><td> integer </td><td> interval </td><td> read, write </td><td>The interval of the event recurrence</td></tr>
+ *     <tr><td> string </td><td> bysecond </td><td> read, write </td><td>The second list of the event recurrence. The value can be from 0 to 59. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> byminute </td><td> read, write </td><td>The minute list of the event recurrence. The value can be from 0 to 59. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> byhour </td><td> read, write </td><td>The hour list of the event recurrence. The value can be from 0 to 23. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> byday </td><td> read, write </td><td>The day list of the event recurrence. The value can be SU, MO, TU, WE, TH, FR, SA. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> bymonthday </td><td> read, write </td><td>The month day list of the event recurrence. The value can be from 1 to 31 and from -31 to -1. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> byyearday </td><td> read, write </td><td>The year day list of the event recurrence. The value can be from 1 to 366 and from -366 to -1. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> byweekno </td><td> read, write </td><td>The week number list of the event recurrence. The value can be from 1 to 53 and from -53 to -1. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> bymonth </td><td> read, write </td><td>The month list of the event recurrence. The value can be from 1 to 12. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> bysetpos </td><td> read, write </td><td>The position list of the event recurrence. The value can be from 1 to 366 and from -366 to -1. The list is seperated by commas</td></tr>
+ *     <tr><td> integer </td><td> wkst </td><td> read, write </td><td>The start day of the week. Refer to the @ref calendar_days_of_week_e</td></tr>
+ *     <tr><td> string </td><td> recurrence_id </td><td> read, write </td><td>RECURRENCE-ID of RFC #2445</td></tr>
+ *     <tr><td> string </td><td> rdate </td><td> read, write </td><td>RDATE of RFC #2445</td></tr>
+ *     <tr><td> integer </td><td> has_attendee </td><td> read only </td><td>Whether or not the event has an attendee list </td></tr>
+ *     <tr><td> integer </td><td> has_alarm </td><td> read only </td><td>Whether or not the event has an alarm list </td></tr>
+ *     <tr><td> integer </td><td> calendar_system_type </td><td> read, write </td><td>Refer to the @ref calendar_system_type_e</td></tr>
+ *     <tr><td> string </td><td> sync_data1 </td><td> read, write </td><td>The sync data of the event. If developer need to save some information related to the event, they can use this property</td></tr>
+ *     <tr><td> string </td><td> sync_data2 </td><td> read, write </td><td>The sync data of the event. If developer need to save some information related to the event, they can use this property</td></tr>
+ *     <tr><td> string </td><td> sync_data3 </td><td> read, write </td><td>The sync data of the event. If developer need to save some information related to the event, they can use this property</td></tr>
+ *     <tr><td> string </td><td> sync_data4 </td><td> read, write </td><td>The sync data of the event. If developer need to save some information related to the event, they can use this property</td></tr>
+ *     <tr><td> calendar time </td><td> start_time </td><td> read, write </td><td>The start time of the event</td></tr>
+ *     <tr><td> string </td><td> start_tzid </td><td> read, write </td><td></td>The timezone of the start_time</tr>
+ *     <tr><td> calendar time </td><td> end_time </td><td> read, write </td><td>The end time of the event</td></tr>
+ *     <tr><td> string </td><td> end_tzid </td><td> read, write </td><td>The timezone of the end_time</td></tr>
+ *     <tr><td> child list </td><td> calendar_alarm </td><td> read, write </td><td>The alarm list of the event. Refer to the @ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_alarm</td></tr>
+ *     <tr><td> child list </td><td> calendar_attendee </td><td> read, write </td><td>The attendee list of the event. Refer to the @ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_attendee</td></tr>
+ *     <tr><td> child list </td><td> exception </td><td> read, write </td><td>The exception mod event list of the event</td></tr>
+ *     <tr><td> child list </td><td> extended </td><td> read, write </td><td>The extended property list of the event. Refer to the @ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_extended_property</td></tr>
+ *     <tr><td> interger </td><td> is_allday </td><td> read only </td><td>The event is an allday event or not </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_VIEW()
+       _CALENDAR_PROPERTY_INT( id )                // read_only
+       _CALENDAR_PROPERTY_INT( calendar_book_id )
+       _CALENDAR_PROPERTY_STR( summary )
+       _CALENDAR_PROPERTY_STR( description )
+       _CALENDAR_PROPERTY_STR( location )
+       _CALENDAR_PROPERTY_STR( categories )
+       _CALENDAR_PROPERTY_STR( exdate )
+       _CALENDAR_PROPERTY_INT( event_status )
+       _CALENDAR_PROPERTY_INT( priority )
+       _CALENDAR_PROPERTY_INT( timezone )
+       _CALENDAR_PROPERTY_INT( person_id )
+       _CALENDAR_PROPERTY_INT( busy_status )
+       _CALENDAR_PROPERTY_INT( sensitivity )
+       _CALENDAR_PROPERTY_STR( uid )
+       _CALENDAR_PROPERTY_STR( organizer_name )
+       _CALENDAR_PROPERTY_STR( organizer_email )
+       _CALENDAR_PROPERTY_INT( meeting_status )
+       _CALENDAR_PROPERTY_INT( original_event_id )
+       _CALENDAR_PROPERTY_DOUBLE( latitude )
+       _CALENDAR_PROPERTY_DOUBLE( longitude )
+       _CALENDAR_PROPERTY_INT( email_id )
+       _CALENDAR_PROPERTY_LLI( created_time )
+       _CALENDAR_PROPERTY_LLI( last_modified_time ) // read_only
+       _CALENDAR_PROPERTY_INT( is_deleted )        // read_only
+       _CALENDAR_PROPERTY_INT( freq )
+       _CALENDAR_PROPERTY_INT( range_type )
+       _CALENDAR_PROPERTY_CALTIME( until_time )
+       _CALENDAR_PROPERTY_INT( count )
+       _CALENDAR_PROPERTY_INT( interval )
+       _CALENDAR_PROPERTY_STR( bysecond )
+       _CALENDAR_PROPERTY_STR( byminute )
+       _CALENDAR_PROPERTY_STR( byhour )
+       _CALENDAR_PROPERTY_STR( byday )
+       _CALENDAR_PROPERTY_STR( bymonthday )
+       _CALENDAR_PROPERTY_STR( byyearday )
+       _CALENDAR_PROPERTY_STR( byweekno )
+       _CALENDAR_PROPERTY_STR( bymonth )
+       _CALENDAR_PROPERTY_STR( bysetpos )
+       _CALENDAR_PROPERTY_INT( wkst )
+       _CALENDAR_PROPERTY_STR( recurrence_id )
+       _CALENDAR_PROPERTY_STR( rdate )
+       _CALENDAR_PROPERTY_INT( has_attendee )      // read_only
+       _CALENDAR_PROPERTY_INT( has_alarm )         // read_only
+       _CALENDAR_PROPERTY_INT( calendar_system_type )
+       _CALENDAR_PROPERTY_STR( sync_data1 )
+       _CALENDAR_PROPERTY_STR( sync_data2 )
+       _CALENDAR_PROPERTY_STR( sync_data3 )
+       _CALENDAR_PROPERTY_STR( sync_data4 )
+       _CALENDAR_PROPERTY_CALTIME( start_time )
+       _CALENDAR_PROPERTY_STR( start_tzid )
+       _CALENDAR_PROPERTY_CALTIME( end_time )
+       _CALENDAR_PROPERTY_STR( end_tzid )
+       _CALENDAR_PROPERTY_CHILD_MULTIPLE( calendar_alarm )
+       _CALENDAR_PROPERTY_CHILD_MULTIPLE( calendar_attendee )
+       _CALENDAR_PROPERTY_CHILD_MULTIPLE( exception )
+       _CALENDAR_PROPERTY_CHILD_MULTIPLE( extended )
+       _CALENDAR_PROPERTY_INT( is_allday )         // read only
+_CALENDAR_END_VIEW( _calendar_event )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_todo _calendar_todo view
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     <th> Read, Write </th>
+ *     <th> Description </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td><td> read only </td><td>Identifier of this todo view</td></tr>
+ *     <tr><td> integer </td><td> id </td><td> read only </td><td>DB record ID of the todo</td></tr>
+ *     <tr><td> integer </td><td> calendar_book_id </td><td> read, write </td><td>ID of the calendar book to which the todo belongs</td></tr>
+ *     <tr><td> string </td><td> summary </td><td> read, write </td><td>The short description of the todo</td></tr>
+ *     <tr><td> string </td><td> description </td><td> read, write </td><td>The description of the todo</td></tr>
+ *     <tr><td> string </td><td> location </td><td> read, write </td><td>The location of the todo</td></tr>
+ *     <tr><td> string </td><td> categories </td><td> read, write </td><td>The category of the todo. For example APPOINTMENT, BIRTHDAY</td></tr>
+ *     <tr><td> integer </td><td> todo_status </td><td> read, write </td><td>Refer to the @ref calendar_todo_status_e</td></tr>
+ *     <tr><td> integer </td><td> priority </td><td> read, write </td><td>Refer to the @ref calendar_todo_priority_e</td></tr>
+ *     <tr><td> integer </td><td> sensitivity </td><td> read, write </td><td>Refer to the @ref calendar_sensitivity_e </td></tr>
+ *     <tr><td> string </td><td> uid </td><td> read, write </td><td>The unique ID of the todo</td></tr>
+ *     <tr><td> double </td><td> latitude </td><td> read, write </td><td>The latitude of the location of the todo</td></tr>
+ *     <tr><td> double </td><td> longitude </td><td> read, write </td><td>The longitude of the location of the todo</td></tr>
+ *     <tr><td> long long int </td><td> created_time </td><td> read, write </td><td>The time when the todo is created</td></tr>
+ *     <tr><td> long long int </td><td> last_modified_time </td><td> read only </td><td>The time when the todo is updated</td></tr>
+ *     <tr><td> long long int </td><td> completed_time </td><td> read, write </td><td>The time when the todo is completed</td></tr>
+ *     <tr><td> integer </td><td> progress </td><td> read, write </td><td> The progression of the todo. The value can be from 0 to 100</td></tr>
+ *     <tr><td> integer </td><td> is_deleted </td><td> read only </td><td></td></tr>
+ *     <tr><td> integer </td><td> freq </td><td> read, write </td><td>The frequent type of todo recurrence. Refer to the @ref calendar_recurrence_frequency_e</td></tr>
+ *     <tr><td> integer </td><td> range_type </td><td> read, write </td><td>Refer to the @ref calendar_range_type_e</td></tr>
+ *     <tr><td> calendar time </td><td> until_time </td><td> read, write </td><td>The end time of the todo recurrence. If the range_type is CALENDAR_RANGE_UNTIL</td></tr>
+ *     <tr><td> integer </td><td> count </td><td> read, write </td><td>The count of the todo recurrence. If the range_type is CALENDAR_RANGE_COUNT</td></tr>
+ *     <tr><td> integer </td><td> interval </td><td> read, write </td><td>The interval of the todo recurrence</td></tr>
+ *     <tr><td> string </td><td> bysecond </td><td> read, write </td><td>The second list of the todo recurrence. The value can be from 0 to 59. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> byminute </td><td> read, write </td><td>The minute list of the todo recurrence. The value can be from 0 to 59. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> byhour </td><td> read, write </td><td>The hour list of the todo recurrence. The value can be from 0 to 23. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> byday </td><td> read, write </td><td>The day list of the todo recurrence. The value can be SU, MO, TU, WE, TH, FR, SA. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> bymonthday </td><td> read, write </td><td>The month day list of the todo recurrence. The value can be from 1 to 31 and from -31 to -1. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> byyearday </td><td> read, write </td><td>The year day list of the todo recurrence. The value can be from 1 to 366 and from -366 to -1. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> byweekno </td><td> read, write </td><td>The week number list of the todo recurrence. The value can be from 1 to 53 and from -53 to -1. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> bymonth </td><td> read, write </td><td>The month list of the todo recurrence. The value can be from 1 to 12. The list is seperated by commas</td></tr>
+ *     <tr><td> string </td><td> bysetpos </td><td> read, write </td><td>The position list of the todo recurrence. The value can be from 1 to 366 and from -366 to -1. The list is seperated by commas</td></tr>
+ *     <tr><td> integer </td><td> wkst </td><td> read, write </td><td>The start day of the week. Refer to the @ref calendar_days_of_week_e</td></tr>
+ *     <tr><td> integer </td><td> has_alarm </td><td> read only </td><td>Whether or not the todo has an alarm list </td></tr>
+ *     <tr><td> string </td><td> sync_data1 </td><td> read, write </td><td>The sync data of the todo. If developers need to save some information related to the todo, they can use this property</td></tr>
+ *     <tr><td> string </td><td> sync_data2 </td><td> read, write </td><td>The sync data of the todo. If developers need to save some information related to the todo, they can use this property</td></tr>
+ *     <tr><td> string </td><td> sync_data3 </td><td> read, write </td><td>The sync data of the todo. If developers need to save some information related to the todo, they can use this property</td></tr>
+ *     <tr><td> string </td><td> sync_data4 </td><td> read, write </td><td>The sync data of the todo. If developers need to save some information related to the todo, they can use this property</td></tr>
+ *     <tr><td> calendar time </td><td> start_time </td><td> read, write </td><td>The start time of the todo</td></tr>
+ *     <tr><td> string </td><td> start_tzid </td><td> read, write </td><td></td>The timezone of the start_time</tr>
+ *     <tr><td> calendar time </td><td> due_time </td><td> read, write </td><td>The due time of the todo</td></tr>
+ *     <tr><td> string </td><td> due_tzid </td><td> read, write </td><td>The timezone of the due_time</td></tr>
+ *     <tr><td> child list </td><td> calendar_alarm </td><td> read, write </td><td>The alarm list of the todo. Refer to the @ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_alarm</td></tr>
+ *     <tr><td> string </td><td> organizer_name </td><td> read, write </td><td>The name of the organizer of the event</td></tr>
+ *     <tr><td> string </td><td> organizer_email </td><td> read, write </td><td>The email address of the organizer of the event</td></tr>
+ *     <tr><td> integer </td><td> has_attendee </td><td> read only </td><td>Whether or not the todo has an attendee list </td></tr>
+ *     <tr><td> child list </td><td> calendar_attendee </td><td> read, write </td><td>The attendee list of the todo. Refer to the @ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_attendee</td></tr>
+ *     <tr><td> child list </td><td> extended </td><td> read, write </td><td>The extended property list of the todo. Refer to the @ref CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_extended_property</td></tr>
+ *     <tr><td> interger </td><td> is_allday </td><td> read only </td><td>The todo is an allday event or not </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_VIEW()
+       _CALENDAR_PROPERTY_INT( id )            // read_only
+       _CALENDAR_PROPERTY_INT( calendar_book_id )
+       _CALENDAR_PROPERTY_STR( summary )
+       _CALENDAR_PROPERTY_STR( description )
+       _CALENDAR_PROPERTY_STR( location )
+       _CALENDAR_PROPERTY_STR( categories )
+       _CALENDAR_PROPERTY_INT( todo_status )
+       _CALENDAR_PROPERTY_INT( priority )
+       _CALENDAR_PROPERTY_INT( sensitivity )
+       _CALENDAR_PROPERTY_STR( uid )
+       _CALENDAR_PROPERTY_DOUBLE( latitude )
+       _CALENDAR_PROPERTY_DOUBLE( longitude )
+       _CALENDAR_PROPERTY_LLI( created_time )
+       _CALENDAR_PROPERTY_LLI( last_modified_time ) // read_only
+       _CALENDAR_PROPERTY_LLI( completed_time )
+       _CALENDAR_PROPERTY_INT( progress )
+       _CALENDAR_PROPERTY_INT( is_deleted )    // read_only
+       _CALENDAR_PROPERTY_INT( freq )
+       _CALENDAR_PROPERTY_INT( range_type )
+       _CALENDAR_PROPERTY_CALTIME( until_time )
+       _CALENDAR_PROPERTY_INT( count )
+       _CALENDAR_PROPERTY_INT( interval )
+       _CALENDAR_PROPERTY_STR( bysecond )
+       _CALENDAR_PROPERTY_STR( byminute )
+       _CALENDAR_PROPERTY_STR( byhour )
+       _CALENDAR_PROPERTY_STR( byday )
+       _CALENDAR_PROPERTY_STR( bymonthday )
+       _CALENDAR_PROPERTY_STR( byyearday )
+       _CALENDAR_PROPERTY_STR( byweekno )
+       _CALENDAR_PROPERTY_STR( bymonth )
+       _CALENDAR_PROPERTY_STR( bysetpos )
+       _CALENDAR_PROPERTY_INT( wkst )
+       _CALENDAR_PROPERTY_INT( has_alarm )     // read_only
+       _CALENDAR_PROPERTY_STR( sync_data1 )
+       _CALENDAR_PROPERTY_STR( sync_data2 )
+       _CALENDAR_PROPERTY_STR( sync_data3 )
+       _CALENDAR_PROPERTY_STR( sync_data4 )
+       _CALENDAR_PROPERTY_CALTIME( start_time )
+       _CALENDAR_PROPERTY_STR( start_tzid )
+       _CALENDAR_PROPERTY_CALTIME( due_time )
+       _CALENDAR_PROPERTY_STR( due_tzid )
+       _CALENDAR_PROPERTY_CHILD_MULTIPLE( calendar_alarm )
+    _CALENDAR_PROPERTY_STR( organizer_name )
+    _CALENDAR_PROPERTY_STR( organizer_email )
+    _CALENDAR_PROPERTY_INT( has_attendee )     // read_only
+    _CALENDAR_PROPERTY_CHILD_MULTIPLE( calendar_attendee )
+    _CALENDAR_PROPERTY_CHILD_MULTIPLE( extended )
+    _CALENDAR_PROPERTY_INT( is_allday )         // read only
+_CALENDAR_END_VIEW( _calendar_todo )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_timezone _calendar_timezone view
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     <th> Read, Write </th>
+ *     <th> Description </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td><td> read only </td><td> Identifier of this timezone view </td></tr>
+ *     <tr><td> integer </td><td> id </td><td> read only </td><td> DB record ID of the timezone </td></tr>
+ *     <tr><td> integer </td><td> calendar_book_id </td><td> read, write </td><td> DB record ID of a related calendar book </td></tr>
+ *     <tr><td> integer </td><td> tz_offset_from_gmt </td><td> read, write </td><td> UTC offset which is in use when the onset of this time zone observance begins. Valid values are -720(-12:00) to 840(+14:00) </td></tr>
+ *     <tr><td> string </td><td> standard_name </td><td> read, write </td><td> Name of the Standard Time </td></tr>
+ *     <tr><td> integer </td><td> standard_start_month </td><td> read, write </td><td> Starting month of the Standard Time. Month is 0-based. eg, 0 for January </td></tr>
+ *     <tr><td> integer </td><td> standard_start_position_of_week </td><td> read, write </td><td> Starting day-of-week-in-month of the Standard Time. Day is 1-based </td></tr>
+ *     <tr><td> integer </td><td> standard_start_day </td><td> read, write </td><td> Starting day-of-week of the Standard Time. Valid values are 1(SUNDAY) to 7(SATURDAY) </td></tr>
+ *     <tr><td> integer </td><td> standard_start_hour </td><td> read, write </td><td> Starting hour of the Standard Time. Valid values are 0 to 23 </td></tr>
+ *     <tr><td> integer </td><td> standard_bias </td><td> read, write </td><td> The number of minutes added during the Standard Time </td></tr>
+ *     <tr><td> string </td><td> day_light_name </td><td> read, write </td><td> Name of Daylight </td></tr>
+ *     <tr><td> integer </td><td> day_light_start_month </td><td> read, write </td><td> Starting month of Daylight. Month is 0-based. eg, 0 for January </td></tr>
+ *     <tr><td> integer </td><td> day_light_start_position_of_week </td><td> read, write </td><td> Starting day-of-week-in-month of Daylight. Day is 1-based </td></tr>
+ *     <tr><td> integer </td><td> day_light_start_day </td><td> read, write </td><td> Starting day-of-week of Daylight. Valid values are 1(SUNDAY) to 7(SATURDAY) </td></tr>
+ *     <tr><td> integer </td><td> day_light_start_hour </td><td> read, write </td><td> Starting hour of Daylight. Valid values are 0 to 23 </td></tr>
+ *     <tr><td> integer </td><td> day_light_bias </td><td> read, write </td><td> The number of minutes added during Daylight Time </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_VIEW()
+       _CALENDAR_PROPERTY_INT( id )                    // read_only
+       _CALENDAR_PROPERTY_INT( calendar_book_id )
+       _CALENDAR_PROPERTY_INT( tz_offset_from_gmt ) // offset(minute)
+       _CALENDAR_PROPERTY_STR( standard_name )
+       _CALENDAR_PROPERTY_INT( standard_start_month )
+       _CALENDAR_PROPERTY_INT( standard_start_position_of_week ) // nth wday
+       _CALENDAR_PROPERTY_INT( standard_start_day ) // wday
+       _CALENDAR_PROPERTY_INT( standard_start_hour )
+       _CALENDAR_PROPERTY_INT( standard_bias )
+       _CALENDAR_PROPERTY_STR( day_light_name )
+       _CALENDAR_PROPERTY_INT( day_light_start_month )
+       _CALENDAR_PROPERTY_INT( day_light_start_position_of_week )
+       _CALENDAR_PROPERTY_INT( day_light_start_day )
+       _CALENDAR_PROPERTY_INT( day_light_start_hour )
+       _CALENDAR_PROPERTY_INT( day_light_bias ) // diff between standard and daylight(minute)
+_CALENDAR_END_VIEW( _calendar_timezone )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_attendee _calendar_attendee view
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     <th> Read, Write </th>
+ *     <th> Description </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td><td> read only </td><td> Identifier of this calendar attendee view </td></tr>
+ *     <tr><td> integer </td><td> event_id </td><td> read only </td><td> Event/TODO that the attendee belongs to </td></tr>
+ *     <tr><td> string </td><td> number </td><td> read, write </td><td> The number of the attendee </td></tr>
+ *     <tr><td> integer </td><td> cutype </td><td> read, write </td><td> The type of attendee (one of CALENDAR_ATTENDEE_CUTYPE_INDIVIDUAL, CALENDAR_ATTENDEE_CUTYPE_GROUP, CALENDAR_ATTENDEE_CUTYPE_RESOURCE, CALENDAR_ATTENDEE_CUTYPE_ROOM, CALENDAR_ATTENDEE_CUTYPE_UNKNOWN) </tr>
+ *     <tr><td> integer </td><td> person_id </td><td> read, write </td><td> Person ID that the attendee belongs to </td></tr>
+ *     <tr><td> string </td><td> uid </td><td> read, write </td><td> Unique identifier </td></tr>
+ *     <tr><td> string </td><td> email </td><td> read, write </td><td> The email address of the attendee </td></tr>
+ *     <tr><td> integer </td><td> role </td><td> read, write </td><td> Attendee role (one of CALENDAR_ATTENDEE_ROLE_REQ_PARTICIPANT, CALENDAR_ATTENDEE_ROLE_OPT_PARTICIPANT, CALENDAR_ATTENDEE_ROLE_NON_PARTICIPANT, CALENDAR_ATTENDEE_ROLE_CHAIR) </td></tr>
+ *     <tr><td> integer </td><td> status </td><td> read, write </td><td> Attendee status (one of CALENDAR_ATTENDEE_STATUS_PENDING, CALENDAR_ATTENDEE_STATUS_ACCEPTED, CALENDAR_ATTENDEE_STATUS_DECLINED, CALENDAR_ATTENDEE_STATUS_TENTATIVE, CALENDAR_ATTENDEE_STATUS_DELEGATED, CALENDAR_ATTENDEE_STATUS_COMPLETED, CALENDAR_ATTENDEE_STATUS_IN_PROCESS) </td></tr>
+ *     <tr><td> integer </td><td> rsvp </td><td> read, write </td><td> RSVP invitation reply (one of true, false) </td></tr>
+ *     <tr><td> string </td><td> delegatee_uri </td><td> read, write </td><td> Delegatee (DELEGATED-TO) </td></tr>
+ *     <tr><td> string </td><td> delegator_uri </td><td> read, write </td><td> Delegator (DELEGATED-FROM) </td></tr>
+ *     <tr><td> string </td><td> name </td><td> read, write </td><td> Attendee name </td></tr>
+ *     <tr><td> string </td><td> member </td><td> read, write </td><td> Group that the attendee belongs to </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_VIEW()
+    _CALENDAR_PROPERTY_INT( parent_id ) // read_only
+       _CALENDAR_PROPERTY_STR( number )
+       _CALENDAR_PROPERTY_INT( cutype ) // calendar user type: INDIVIDUAL, GROUP, RESOURCE, ROOM, UNKNOWN
+       _CALENDAR_PROPERTY_INT( person_id )
+       _CALENDAR_PROPERTY_STR( uid )
+       _CALENDAR_PROPERTY_STR( group )
+       _CALENDAR_PROPERTY_STR( email )
+       _CALENDAR_PROPERTY_INT( role )
+       _CALENDAR_PROPERTY_INT( status )
+       _CALENDAR_PROPERTY_INT( rsvp )
+       _CALENDAR_PROPERTY_STR( delegatee_uri )
+       _CALENDAR_PROPERTY_STR( delegator_uri )
+       _CALENDAR_PROPERTY_STR( name )
+       _CALENDAR_PROPERTY_STR( member )
+_CALENDAR_END_VIEW( _calendar_attendee )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_alarm _calendar_alarm view
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     <th> Read, Write </th>
+ *     <th> Description </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td><td> read only </td><td> Identifier of this calendar alarm view </td></tr>
+ *     <tr><td> integer </td><td> parent_id </td><td> read only </td><td> Event that the alarm belongs to </td></tr>
+ *     <tr><td> integer </td><td> type </td><td> read, write </td><td> Currently NOT used </td></tr>
+ *     <tr><td> long long int </td><td> time </td><td> read, write </td><td> The alarm time of the event(This represents the number of seconds elapsed since the Epoch, 1970-01-01 00:00:00 +0000(UTC)). This MUST be used with CALENDAR_ALARM_TIME_UNIT_SPECIFIC </td></tr>
+ *     <tr><td> integer </td><td> tick </td><td> read, write </td><td> The number of unit before start time. This MUST be used with one of CALENDAR_ALARM_TIME_UNIT_MINUTE, CALENDAR_ALARM_TIME_UNIT_HOUR, CALENDAR_ALARM_TIME_UNIT_DAY, CALENDAR_ALARM_TIME_UNIT_WEEK. </td></tr>
+ *     <tr><td> integer </td><td> tick_unit </td><td> read, write </td><td> Reminder tick time unit (one of CALENDAR_ALARM_NONE, CALENDAR_ALARM_TIME_UNIT_SPECIFIC, CALENDAR_ALARM_TIME_UNIT_MINUTE, CALENDAR_ALARM_TIME_UNIT_HOUR, CALENDAR_ALARM_TIME_UNIT_DAY, CALENDAR_ALARM_TIME_UNIT_WEEK) </td></tr>
+ *     <tr><td> string </td><td> attach </td><td> read, write </td><td> Alarm tone path </td></tr>
+ *     <tr><td> string </td><td> summary </td><td> read, write </td><td> Alarm summary </td></tr>
+ *     <tr><td> string </td><td> description </td><td> read, write </td><td> Alarm description </td></tr>
+ *     <tr><td> integer </td><td> action </td><td> read, write </td><td> Action of alarm (one of CALENDAR_ALARM_ACTION_AUDIO, CALENDAR_ALARM_ACTION_DISPLAY, CALENDAR_ALARM_ACTION_EMAIL) </td></tr>
+ *     <tr><td> calendar time </td><td> alarm_time </td><td> read, write </td><td>The alarm time </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_VIEW()
+    _CALENDAR_PROPERTY_INT( parent_id ) // read_only
+       _CALENDAR_PROPERTY_INT( tick )
+       _CALENDAR_PROPERTY_INT( tick_unit )
+       _CALENDAR_PROPERTY_STR( description )
+       _CALENDAR_PROPERTY_STR( summary ) // emailprop: summary
+       _CALENDAR_PROPERTY_INT( action ) // AUDIO, DISPLAY, EMAIL
+       _CALENDAR_PROPERTY_STR( attach )
+    _CALENDAR_PROPERTY_CALTIME( alarm_time )
+_CALENDAR_END_VIEW( _calendar_alarm )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_updated_info _calendar_updated_info view (read only)
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     <th> Description </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td><td> Identifier of this updated_info view </td></tr>
+ *     <tr><td> integer </td><td> id </td><td> Modified event(or todo) record ID </td></tr>
+ *     <tr><td> integer </td><td> calendar_book_id </td><td> Calendar book ID of the modified event(or todo) record </td></tr>
+ *     <tr><td> integer </td><td> modified_status </td><td> Enumeration value of the modified status (@ref calendar_record_modified_status_e) </td></tr>
+ *     <tr><td> integer </td><td> version </td><td> Version after change </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_READ_ONLY_VIEW()
+       _CALENDAR_PROPERTY_INT( id ) // read_only
+       _CALENDAR_PROPERTY_INT( calendar_book_id )
+       _CALENDAR_PROPERTY_INT( modified_status )
+       _CALENDAR_PROPERTY_INT( version )
+_CALENDAR_END_READ_ONLY_VIEW( _calendar_updated_info )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_event_calendar_book _calendar_event_calendar_book view (read only)
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td></tr>
+ *     <tr><td> integer </td><td> event_id </td></tr>
+ *     <tr><td> integer </td><td> calendar_book_id </td></tr>
+ *     <tr><td> string </td><td> summary </td></tr>
+ *     <tr><td> string </td><td> description </td></tr>
+ *     <tr><td> string </td><td> location </td></tr>
+ *     <tr><td> string </td><td> categories </td></tr>
+ *     <tr><td> string </td><td> exdate </td></tr>
+ *     <tr><td> integer </td><td> event_status </td></tr>
+ *     <tr><td> integer </td><td> priority </td></tr>
+ *     <tr><td> integer </td><td> timezone </td></tr>
+ *     <tr><td> integer </td><td> person_id </td></tr>
+ *     <tr><td> integer </td><td> busy_status </td></tr>
+ *     <tr><td> integer </td><td> sensitivity </td></tr>
+ *     <tr><td> string </td><td> uid </td></tr>
+ *     <tr><td> string </td><td> organizer_name </td></tr>
+ *     <tr><td> string </td><td> organizer_email </td></tr>
+ *     <tr><td> integer </td><td> meeting_status </td></tr>
+ *     <tr><td> integer </td><td> original_event_id </td></tr>
+ *     <tr><td> double </td><td> latitude </td></tr>
+ *     <tr><td> double </td><td> longitude </td></tr>
+ *     <tr><td> integer </td><td> email_id </td></tr>
+ *     <tr><td> long long int </td><td> created_time </td></tr>
+ *     <tr><td> long long int </td><td> last_modified_time </td></tr>
+ *     <tr><td> integer </td><td> freq </td></tr>
+ *     <tr><td> integer </td><td> range_type </td></tr>
+ *     <tr><td> calendar time </td><td> until_time </td></tr>
+ *     <tr><td> integer </td><td> count </td></tr>
+ *     <tr><td> integer </td><td> interval </td></tr>
+ *     <tr><td> string </td><td> bysecond </td></tr>
+ *     <tr><td> string </td><td> byminute </td></tr>
+ *     <tr><td> string </td><td> byhour </td></tr>
+ *     <tr><td> string </td><td> byday </td></tr>
+ *     <tr><td> string </td><td> bymonthday </td></tr>
+ *     <tr><td> string </td><td> byyearday </td></tr>
+ *     <tr><td> string </td><td> byweekno </td></tr>
+ *     <tr><td> string </td><td> bymonth </td></tr>
+ *     <tr><td> string </td><td> bysetpos </td></tr>
+ *     <tr><td> integer </td><td> wkst </td></tr>
+ *     <tr><td> string </td><td> recurrence_id </td></tr>
+ *     <tr><td> string </td><td> rdate </td></tr>
+ *     <tr><td> integer </td><td> has_attendee </td></tr>
+ *     <tr><td> integer </td><td> has_alarm </td></tr>
+ *     <tr><td> integer </td><td> calendar_system_type </td></tr>
+ *     <tr><td> string </td><td> sync_data1 </td></tr>
+ *     <tr><td> string </td><td> sync_data2 </td></tr>
+ *     <tr><td> string </td><td> sync_data3 </td></tr>
+ *     <tr><td> string </td><td> sync_data4 </td></tr>
+ *     <tr><td> calendar time </td><td> start_time </td></tr>
+ *     <tr><td> string </td><td> start_tzid </td></tr>
+ *     <tr><td> calendar time </td><td> end_time </td></tr>
+ *     <tr><td> string </td><td> end_tzid </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_visibility </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_account_id </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_READ_ONLY_VIEW()
+    _CALENDAR_PROPERTY_INT( event_id )
+    _CALENDAR_PROPERTY_INT( calendar_book_id )
+    _CALENDAR_PROPERTY_STR( summary )
+    _CALENDAR_PROPERTY_STR( description )
+    _CALENDAR_PROPERTY_STR( location )
+    _CALENDAR_PROPERTY_STR( categories )
+    _CALENDAR_PROPERTY_STR( exdate )
+    _CALENDAR_PROPERTY_INT( event_status )
+    _CALENDAR_PROPERTY_INT( priority )
+    _CALENDAR_PROPERTY_INT( timezone )
+    _CALENDAR_PROPERTY_INT( person_id )
+    _CALENDAR_PROPERTY_INT( busy_status )
+    _CALENDAR_PROPERTY_INT( sensitivity )
+    _CALENDAR_PROPERTY_STR( uid )
+    _CALENDAR_PROPERTY_STR( organizer_name )
+    _CALENDAR_PROPERTY_STR( organizer_email )
+    _CALENDAR_PROPERTY_INT( meeting_status )
+    _CALENDAR_PROPERTY_INT( original_event_id )
+    _CALENDAR_PROPERTY_DOUBLE( latitude )
+    _CALENDAR_PROPERTY_DOUBLE( longitude )
+    _CALENDAR_PROPERTY_INT( email_id )
+    _CALENDAR_PROPERTY_LLI( created_time )
+    _CALENDAR_PROPERTY_LLI( last_modified_time )
+    _CALENDAR_PROPERTY_INT( freq )
+    _CALENDAR_PROPERTY_INT( range_type )
+    _CALENDAR_PROPERTY_CALTIME( until_time )
+    _CALENDAR_PROPERTY_INT( count )
+    _CALENDAR_PROPERTY_INT( interval )
+    _CALENDAR_PROPERTY_STR( bysecond )
+    _CALENDAR_PROPERTY_STR( byminute )
+    _CALENDAR_PROPERTY_STR( byhour )
+    _CALENDAR_PROPERTY_STR( byday )
+    _CALENDAR_PROPERTY_STR( bymonthday )
+    _CALENDAR_PROPERTY_STR( byyearday )
+    _CALENDAR_PROPERTY_STR( byweekno )
+    _CALENDAR_PROPERTY_STR( bymonth )
+    _CALENDAR_PROPERTY_STR( bysetpos )
+    _CALENDAR_PROPERTY_INT( wkst )
+    _CALENDAR_PROPERTY_STR( recurrence_id )
+    _CALENDAR_PROPERTY_STR( rdate )
+    _CALENDAR_PROPERTY_INT( has_attendee )
+    _CALENDAR_PROPERTY_INT( has_alarm )
+    _CALENDAR_PROPERTY_INT( calendar_system_type )
+    _CALENDAR_PROPERTY_STR( sync_data1 )
+    _CALENDAR_PROPERTY_STR( sync_data2 )
+    _CALENDAR_PROPERTY_STR( sync_data3 )
+    _CALENDAR_PROPERTY_STR( sync_data4 )
+    _CALENDAR_PROPERTY_CALTIME( start_time )
+    _CALENDAR_PROPERTY_STR( start_tzid )
+    _CALENDAR_PROPERTY_CALTIME( end_time )
+    _CALENDAR_PROPERTY_STR( end_tzid )
+    _CALENDAR_PROPERTY_INT( is_allday )         // read only
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_visibility )
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_account_id )
+_CALENDAR_END_READ_ONLY_VIEW( _calendar_event_calendar_book )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_todo_calendar_book _calendar_todo_calendar_book view (read only)
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td></tr>
+ *     <tr><td> integer </td><td> todo_id </td></tr>
+ *     <tr><td> integer </td><td> calendar_book_id </td></tr>
+ *     <tr><td> string </td><td> summary </td></tr>
+ *     <tr><td> string </td><td> description </td></tr>
+ *     <tr><td> string </td><td> location </td></tr>
+ *     <tr><td> string </td><td> categories </td></tr>
+ *     <tr><td> integer </td><td> todo_status </td></tr>
+ *     <tr><td> integer </td><td> priority </td></tr>
+ *     <tr><td> integer </td><td> sensitivity </td></tr>
+ *     <tr><td> string </td><td> uid </td></tr>
+ *     <tr><td> double </td><td> latitude </td></tr>
+ *     <tr><td> double </td><td> longitude </td></tr>
+ *     <tr><td> long long int </td><td> created_time </td></tr>
+ *     <tr><td> long long int </td><td> last_modified_time </td></tr>
+ *     <tr><td> long long int </td><td> completed_time </td></tr>
+ *     <tr><td> integer </td><td> progress </td></tr>
+ *     <tr><td> integer </td><td> freq </td></tr>
+ *     <tr><td> integer </td><td> range_type </td></tr>
+ *     <tr><td> calendar time </td><td> until_time </td></tr>
+ *     <tr><td> integer </td><td> count </td></tr>
+ *     <tr><td> integer </td><td> interval </td></tr>
+ *     <tr><td> string </td><td> bysecond </td></tr>
+ *     <tr><td> string </td><td> byminute </td></tr>
+ *     <tr><td> string </td><td> byhour </td></tr>
+ *     <tr><td> string </td><td> byday </td></tr>
+ *     <tr><td> string </td><td> bymonthday </td></tr>
+ *     <tr><td> string </td><td> byyearday </td></tr>
+ *     <tr><td> string </td><td> byweekno </td></tr>
+ *     <tr><td> string </td><td> bymonth </td></tr>
+ *     <tr><td> string </td><td> bysetpos </td></tr>
+ *     <tr><td> integer </td><td> wkst </td></tr>
+ *     <tr><td> integer </td><td> has_alarm </td></tr>
+ *     <tr><td> string </td><td> sync_data1 </td></tr>
+ *     <tr><td> string </td><td> sync_data2 </td></tr>
+ *     <tr><td> string </td><td> sync_data3 </td></tr>
+ *     <tr><td> string </td><td> sync_data4 </td></tr>
+ *     <tr><td> calendar time </td><td> start_time </td></tr>
+ *     <tr><td> string </td><td> start_tzid </td></tr>
+ *     <tr><td> calendar time </td><td> due_time </td></tr>
+ *     <tr><td> string </td><td> due_tzid </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_visibility </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_account_id </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_READ_ONLY_VIEW()
+    _CALENDAR_PROPERTY_INT( todo_id )
+    _CALENDAR_PROPERTY_INT( calendar_book_id )
+    _CALENDAR_PROPERTY_STR( summary )
+    _CALENDAR_PROPERTY_STR( description )
+    _CALENDAR_PROPERTY_STR( location )
+    _CALENDAR_PROPERTY_STR( categories )
+    _CALENDAR_PROPERTY_INT( todo_status )
+    _CALENDAR_PROPERTY_INT( priority )
+    _CALENDAR_PROPERTY_INT( sensitivity )
+    _CALENDAR_PROPERTY_STR( uid )
+    _CALENDAR_PROPERTY_DOUBLE( latitude )
+    _CALENDAR_PROPERTY_DOUBLE( longitude )
+    _CALENDAR_PROPERTY_LLI( created_time )
+    _CALENDAR_PROPERTY_LLI( last_modified_time )
+    _CALENDAR_PROPERTY_LLI( completed_time )
+    _CALENDAR_PROPERTY_INT( progress )
+    _CALENDAR_PROPERTY_INT( freq )
+    _CALENDAR_PROPERTY_INT( range_type )
+    _CALENDAR_PROPERTY_CALTIME( until_time )
+    _CALENDAR_PROPERTY_INT( count )
+    _CALENDAR_PROPERTY_INT( interval )
+    _CALENDAR_PROPERTY_STR( bysecond )
+    _CALENDAR_PROPERTY_STR( byminute )
+    _CALENDAR_PROPERTY_STR( byhour )
+    _CALENDAR_PROPERTY_STR( byday )
+    _CALENDAR_PROPERTY_STR( bymonthday )
+    _CALENDAR_PROPERTY_STR( byyearday )
+    _CALENDAR_PROPERTY_STR( byweekno )
+    _CALENDAR_PROPERTY_STR( bymonth )
+    _CALENDAR_PROPERTY_STR( bysetpos )
+    _CALENDAR_PROPERTY_INT( wkst )
+    _CALENDAR_PROPERTY_INT( has_alarm )
+    _CALENDAR_PROPERTY_STR( sync_data1 )
+    _CALENDAR_PROPERTY_STR( sync_data2 )
+    _CALENDAR_PROPERTY_STR( sync_data3 )
+    _CALENDAR_PROPERTY_STR( sync_data4 )
+    _CALENDAR_PROPERTY_CALTIME( start_time )
+    _CALENDAR_PROPERTY_STR( start_tzid )
+    _CALENDAR_PROPERTY_CALTIME( due_time )
+    _CALENDAR_PROPERTY_STR( due_tzid )
+    _CALENDAR_PROPERTY_STR( organizer_name )
+    _CALENDAR_PROPERTY_STR( organizer_email )
+    _CALENDAR_PROPERTY_INT( has_attendee )
+    _CALENDAR_PROPERTY_INT( is_allday )         // read only
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_visibility )
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_account_id )
+_CALENDAR_END_READ_ONLY_VIEW( _calendar_todo_calendar_book )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_event_calendar_book_attendee _calendar_event_calendar_book_attendee view (read only)
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td></tr>
+ *     <tr><td> integer </td><td> event_id </td></tr>
+ *     <tr><td> integer </td><td> calendar_book_id </td></tr>
+ *     <tr><td> string </td><td> summary </td></tr>
+ *     <tr><td> string </td><td> description </td></tr>
+ *     <tr><td> string </td><td> location </td></tr>
+ *     <tr><td> string </td><td> categories </td></tr>
+ *     <tr><td> string </td><td> exdate </td></tr>
+ *     <tr><td> integer </td><td> event_status </td></tr>
+ *     <tr><td> integer </td><td> priority </td></tr>
+ *     <tr><td> integer </td><td> timezone </td></tr>
+ *     <tr><td> integer </td><td> person_id </td></tr>
+ *     <tr><td> integer </td><td> busy_status </td></tr>
+ *     <tr><td> integer </td><td> sensitivity </td></tr>
+ *     <tr><td> string </td><td> uid </td></tr>
+ *     <tr><td> string </td><td> organizer_name </td></tr>
+ *     <tr><td> string </td><td> organizer_email </td></tr>
+ *     <tr><td> integer </td><td> meeting_status </td></tr>
+ *     <tr><td> integer </td><td> original_event_id </td></tr>
+ *     <tr><td> double </td><td> latitude </td></tr>
+ *     <tr><td> double </td><td> longitude </td></tr>
+ *     <tr><td> integer </td><td> email_id </td></tr>
+ *     <tr><td> long long int </td><td> created_time </td></tr>
+ *     <tr><td> long long int </td><td> last_modified_time </td></tr>
+ *     <tr><td> integer </td><td> freq </td></tr>
+ *     <tr><td> integer </td><td> range_type </td></tr>
+ *     <tr><td> calendar time </td><td> until_time </td></tr>
+ *     <tr><td> integer </td><td> count </td></tr>
+ *     <tr><td> integer </td><td> interval </td></tr>
+ *     <tr><td> string </td><td> bysecond </td></tr>
+ *     <tr><td> string </td><td> byminute </td></tr>
+ *     <tr><td> string </td><td> byhour </td></tr>
+ *     <tr><td> string </td><td> byday </td></tr>
+ *     <tr><td> string </td><td> bymonthday </td></tr>
+ *     <tr><td> string </td><td> byyearday </td></tr>
+ *     <tr><td> string </td><td> byweekno </td></tr>
+ *     <tr><td> string </td><td> bymonth </td></tr>
+ *     <tr><td> string </td><td> bysetpos </td></tr>
+ *     <tr><td> integer </td><td> wkst </td></tr>
+ *     <tr><td> string </td><td> recurrence_id </td></tr>
+ *     <tr><td> string </td><td> rdate </td></tr>
+ *     <tr><td> integer </td><td> has_attendee </td></tr>
+ *     <tr><td> integer </td><td> has_alarm </td></tr>
+ *     <tr><td> integer </td><td> calendar_system_type </td></tr>
+ *     <tr><td> string </td><td> sync_data1 </td></tr>
+ *     <tr><td> string </td><td> sync_data2 </td></tr>
+ *     <tr><td> string </td><td> sync_data3 </td></tr>
+ *     <tr><td> string </td><td> sync_data4 </td></tr>
+ *     <tr><td> calendar time </td><td> start_time </td></tr>
+ *     <tr><td> string </td><td> start_tzid </td></tr>
+ *     <tr><td> calendar time </td><td> end_time </td></tr>
+ *     <tr><td> string </td><td> end_tzid </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_visibility </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_account_id </td></tr>
+ *     <tr><td> filter string </td><td> attendee_email </td></tr>
+ *     <tr><td> filter string </td><td> attendee_name </td></tr>
+ *     <tr><td> filter string </td><td> attendee_member </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_READ_ONLY_VIEW()
+    _CALENDAR_PROPERTY_INT( event_id )
+    _CALENDAR_PROPERTY_INT( calendar_book_id )
+    _CALENDAR_PROPERTY_STR( summary )
+    _CALENDAR_PROPERTY_STR( description )
+    _CALENDAR_PROPERTY_STR( location )
+    _CALENDAR_PROPERTY_STR( categories )
+    _CALENDAR_PROPERTY_STR( exdate )
+    _CALENDAR_PROPERTY_INT( event_status )
+    _CALENDAR_PROPERTY_INT( priority )
+    _CALENDAR_PROPERTY_INT( timezone )
+    _CALENDAR_PROPERTY_INT( person_id )
+    _CALENDAR_PROPERTY_INT( busy_status )
+    _CALENDAR_PROPERTY_INT( sensitivity )
+    _CALENDAR_PROPERTY_STR( uid )
+    _CALENDAR_PROPERTY_STR( organizer_name )
+    _CALENDAR_PROPERTY_STR( organizer_email )
+    _CALENDAR_PROPERTY_INT( meeting_status )
+    _CALENDAR_PROPERTY_INT( original_event_id )
+    _CALENDAR_PROPERTY_DOUBLE( latitude )
+    _CALENDAR_PROPERTY_DOUBLE( longitude )
+    _CALENDAR_PROPERTY_INT( email_id )
+    _CALENDAR_PROPERTY_LLI( created_time )
+    _CALENDAR_PROPERTY_LLI( last_modified_time )
+    _CALENDAR_PROPERTY_INT( freq )
+    _CALENDAR_PROPERTY_INT( range_type )
+    _CALENDAR_PROPERTY_CALTIME( until_time )
+    _CALENDAR_PROPERTY_INT( count )
+    _CALENDAR_PROPERTY_INT( interval )
+    _CALENDAR_PROPERTY_STR( bysecond )
+    _CALENDAR_PROPERTY_STR( byminute )
+    _CALENDAR_PROPERTY_STR( byhour )
+    _CALENDAR_PROPERTY_STR( byday )
+    _CALENDAR_PROPERTY_STR( bymonthday )
+    _CALENDAR_PROPERTY_STR( byyearday )
+    _CALENDAR_PROPERTY_STR( byweekno )
+    _CALENDAR_PROPERTY_STR( bymonth )
+    _CALENDAR_PROPERTY_STR( bysetpos )
+    _CALENDAR_PROPERTY_INT( wkst )
+    _CALENDAR_PROPERTY_STR( recurrence_id )
+    _CALENDAR_PROPERTY_STR( rdate )
+    _CALENDAR_PROPERTY_INT( has_attendee )
+    _CALENDAR_PROPERTY_INT( has_alarm )
+    _CALENDAR_PROPERTY_INT( calendar_system_type )
+    _CALENDAR_PROPERTY_STR( sync_data1 )
+    _CALENDAR_PROPERTY_STR( sync_data2 )
+    _CALENDAR_PROPERTY_STR( sync_data3 )
+    _CALENDAR_PROPERTY_STR( sync_data4 )
+    _CALENDAR_PROPERTY_CALTIME( start_time )
+    _CALENDAR_PROPERTY_STR( start_tzid )
+    _CALENDAR_PROPERTY_CALTIME( end_time )
+    _CALENDAR_PROPERTY_STR( end_tzid )
+    _CALENDAR_PROPERTY_INT( is_allday )         // read only
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_visibility )
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_account_id )
+    _CALENDAR_PROPERTY_FILTER_STR( attendee_email )
+    _CALENDAR_PROPERTY_FILTER_STR( attendee_name )
+    _CALENDAR_PROPERTY_FILTER_STR( attendee_member )
+_CALENDAR_END_READ_ONLY_VIEW( _calendar_event_calendar_book_attendee )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_instance_utime_calendar_book _calendar_instance_utime_calendar_book view
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td></tr>
+ *     <tr><td> integer </td><td> event_id </td></tr>
+ *     <tr><td> calendar time </td><td> start_time </td></tr>
+ *     <tr><td> calendar time </td><td> end_time </td></tr>
+ *     <tr><td> string </td><td> summary </td></tr>
+ *     <tr><td> string </td><td> location </td></tr>
+ *     <tr><td> integer </td><td> calendar_book_id </td></tr>
+ *     <tr><td> string </td><td> description </td></tr>
+ *     <tr><td> integer </td><td> busy_status </td></tr>
+ *     <tr><td> integer </td><td> event_status </td></tr>
+ *     <tr><td> integer </td><td> priority </td></tr>
+ *     <tr><td> integer </td><td> sensitivity </td></tr>
+ *     <tr><td> integer </td><td> has_rrule </td></tr>
+ *     <tr><td> double </td><td> latitude </td></tr>
+ *     <tr><td> double </td><td> longitude </td></tr>
+ *     <tr><td> integer </td><td> has_alarm </td></tr>
+ *     <tr><td> integer </td><td> original_event_id </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_visibility </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_account_id </td></tr>
+ *     <tr><td> long long int </td><td> last_modified_time </td></tr>
+ *     <tr><td> string </td><td> sync_data1 </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_READ_ONLY_VIEW()
+    _CALENDAR_PROPERTY_INT( event_id )
+    _CALENDAR_PROPERTY_CALTIME( start_time )
+    _CALENDAR_PROPERTY_CALTIME( end_time )
+    _CALENDAR_PROPERTY_STR( summary )
+    _CALENDAR_PROPERTY_STR( location )
+    _CALENDAR_PROPERTY_INT( calendar_book_id )
+    _CALENDAR_PROPERTY_STR( description )
+    _CALENDAR_PROPERTY_INT( busy_status )
+    _CALENDAR_PROPERTY_INT( event_status )
+    _CALENDAR_PROPERTY_INT( priority )
+    _CALENDAR_PROPERTY_INT( sensitivity )
+    _CALENDAR_PROPERTY_INT( has_rrule )
+    _CALENDAR_PROPERTY_DOUBLE( latitude )
+    _CALENDAR_PROPERTY_DOUBLE( longitude )
+    _CALENDAR_PROPERTY_INT( has_alarm )
+    _CALENDAR_PROPERTY_INT( original_event_id )
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_visibility )
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_account_id )
+    _CALENDAR_PROPERTY_LLI( last_modified_time )
+    _CALENDAR_PROPERTY_STR( sync_data1 )
+_CALENDAR_END_READ_ONLY_VIEW( _calendar_instance_utime_calendar_book )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_instance_localtime_calendar_book _calendar_instance_localtime_calendar_book view
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td></tr>
+ *     <tr><td> integer </td><td> event_id </td></tr>
+ *     <tr><td> calendar time </td><td> start_time </td></tr>
+ *     <tr><td> calendar time </td><td> end_time </td></tr>
+ *     <tr><td> string </td><td> summary </td></tr>
+ *     <tr><td> string </td><td> location </td></tr>
+ *     <tr><td> integer </td><td> calendar_book_id </td></tr>
+ *     <tr><td> string </td><td> description </td></tr>
+ *     <tr><td> integer </td><td> busy_status </td></tr>
+ *     <tr><td> integer </td><td> event_status </td></tr>
+ *     <tr><td> integer </td><td> priority </td></tr>
+ *     <tr><td> integer </td><td> sensitivity </td></tr>
+ *     <tr><td> integer </td><td> has_rrule </td></tr>
+ *     <tr><td> double </td><td> latitude </td></tr>
+ *     <tr><td> double </td><td> longitude </td></tr>
+ *     <tr><td> integer </td><td> has_alarm </td></tr>
+ *     <tr><td> integer </td><td> original_event_id </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_visibility </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_account_id </td></tr>
+ *     <tr><td> long long int </td><td> last_modified_time </td></tr>
+ *     <tr><td> string </td><td> sync_data1 </td></tr>
+ *     <tr><td> int </td><td> is_allday </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_READ_ONLY_VIEW()
+    _CALENDAR_PROPERTY_INT( event_id )
+    _CALENDAR_PROPERTY_CALTIME( start_time )
+    _CALENDAR_PROPERTY_CALTIME( end_time )
+    _CALENDAR_PROPERTY_STR( summary )
+    _CALENDAR_PROPERTY_STR( location )
+    _CALENDAR_PROPERTY_INT( calendar_book_id )
+    _CALENDAR_PROPERTY_STR( description )
+    _CALENDAR_PROPERTY_INT( busy_status )
+    _CALENDAR_PROPERTY_INT( event_status )
+    _CALENDAR_PROPERTY_INT( priority )
+    _CALENDAR_PROPERTY_INT( sensitivity )
+    _CALENDAR_PROPERTY_INT( has_rrule )
+    _CALENDAR_PROPERTY_DOUBLE( latitude )
+    _CALENDAR_PROPERTY_DOUBLE( longitude )
+    _CALENDAR_PROPERTY_INT( has_alarm )
+    _CALENDAR_PROPERTY_INT( original_event_id )
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_visibility )
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_account_id )
+    _CALENDAR_PROPERTY_LLI( last_modified_time )
+    _CALENDAR_PROPERTY_STR( sync_data1 )
+    _CALENDAR_PROPERTY_INT( is_allday )
+_CALENDAR_END_READ_ONLY_VIEW( _calendar_instance_localtime_calendar_book )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_instance_utime_calendar_book_extended _calendar_instance_utime_calendar_book_extended view
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td></tr>
+ *     <tr><td> integer </td><td> event_id </td></tr>
+ *     <tr><td> calendar time </td><td> start_time </td></tr>
+ *     <tr><td> calendar time </td><td> end_time </td></tr>
+ *     <tr><td> string </td><td> summary </td></tr>
+ *     <tr><td> string </td><td> location </td></tr>
+ *     <tr><td> integer </td><td> calendar_book_id </td></tr>
+ *     <tr><td> string </td><td> description </td></tr>
+ *     <tr><td> integer </td><td> busy_status </td></tr>
+ *     <tr><td> integer </td><td> event_status </td></tr>
+ *     <tr><td> integer </td><td> priority </td></tr>
+ *     <tr><td> integer </td><td> sensitivity </td></tr>
+ *     <tr><td> integer </td><td> has_rrule </td></tr>
+ *     <tr><td> double </td><td> latitude </td></tr>
+ *     <tr><td> double </td><td> longitude </td></tr>
+ *     <tr><td> integer </td><td> has_alarm </td></tr>
+ *     <tr><td> integer </td><td> original_event_id </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_visibility </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_account_id </td></tr>
+ *     <tr><td> string </td><td> organizer_name </td></tr>
+ *     <tr><td> string </td><td> categories </td></tr>
+ *     <tr><td> integer </td><td> has_attendee </td></tr>
+ *     <tr><td> string </td><td> sync_data1 </td></tr>
+ *     <tr><td> string </td><td> sync_data2 </td></tr>
+ *     <tr><td> string </td><td> sync_data3 </td></tr>
+ *     <tr><td> string </td><td> sync_data4 </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_READ_ONLY_VIEW()
+    _CALENDAR_PROPERTY_INT( event_id )
+    _CALENDAR_PROPERTY_CALTIME( start_time )
+    _CALENDAR_PROPERTY_CALTIME( end_time )
+    _CALENDAR_PROPERTY_STR( summary )
+    _CALENDAR_PROPERTY_STR( location )
+    _CALENDAR_PROPERTY_INT( calendar_book_id )
+    _CALENDAR_PROPERTY_STR( description )
+    _CALENDAR_PROPERTY_INT( busy_status )
+    _CALENDAR_PROPERTY_INT( event_status )
+    _CALENDAR_PROPERTY_INT( priority )
+    _CALENDAR_PROPERTY_INT( sensitivity )
+    _CALENDAR_PROPERTY_INT( has_rrule )
+    _CALENDAR_PROPERTY_DOUBLE( latitude )
+    _CALENDAR_PROPERTY_DOUBLE( longitude )
+    _CALENDAR_PROPERTY_INT( has_alarm )
+    _CALENDAR_PROPERTY_INT( original_event_id )
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_visibility )
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_account_id )
+    _CALENDAR_PROPERTY_LLI( last_modified_time )
+    _CALENDAR_PROPERTY_STR( sync_data1 )
+    _CALENDAR_PROPERTY_STR( organizer_name )
+    _CALENDAR_PROPERTY_STR( categories )
+    _CALENDAR_PROPERTY_INT( has_attendee )
+    _CALENDAR_PROPERTY_STR( sync_data2 )
+    _CALENDAR_PROPERTY_STR( sync_data3 )
+    _CALENDAR_PROPERTY_STR( sync_data4 )
+_CALENDAR_END_READ_ONLY_VIEW( _calendar_instance_utime_calendar_book_extended )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_instance_localtime_calendar_book_extended _calendar_instance_localtime_calendar_book_extended view
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td></tr>
+ *     <tr><td> integer </td><td> event_id </td></tr>
+ *     <tr><td> calendar time </td><td> start_time </td></tr>
+ *     <tr><td> calendar time </td><td> end_time </td></tr>
+ *     <tr><td> string </td><td> summary </td></tr>
+ *     <tr><td> string </td><td> location </td></tr>
+ *     <tr><td> integer </td><td> calendar_book_id </td></tr>
+ *     <tr><td> string </td><td> description </td></tr>
+ *     <tr><td> integer </td><td> busy_status </td></tr>
+ *     <tr><td> integer </td><td> event_status </td></tr>
+ *     <tr><td> integer </td><td> priority </td></tr>
+ *     <tr><td> integer </td><td> sensitivity </td></tr>
+ *     <tr><td> integer </td><td> has_rrule </td></tr>
+ *     <tr><td> double </td><td> latitude </td></tr>
+ *     <tr><td> double </td><td> longitude </td></tr>
+ *     <tr><td> integer </td><td> has_alarm </td></tr>
+ *     <tr><td> integer </td><td> original_event_id </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_visibility </td></tr>
+ *     <tr><td> filter integer </td><td> calendar_book_account_id </td></tr>
+ *     <tr><td> string </td><td> organizer_name </td></tr>
+ *     <tr><td> string </td><td> categories </td></tr>
+ *     <tr><td> integer </td><td> has_attendee </td></tr>
+ *     <tr><td> string </td><td> sync_data1 </td></tr>
+ *     <tr><td> string </td><td> sync_data2 </td></tr>
+ *     <tr><td> string </td><td> sync_data3 </td></tr>
+ *     <tr><td> string </td><td> sync_data4 </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_READ_ONLY_VIEW()
+    _CALENDAR_PROPERTY_INT( event_id )
+    _CALENDAR_PROPERTY_CALTIME( start_time )
+    _CALENDAR_PROPERTY_CALTIME( end_time )
+    _CALENDAR_PROPERTY_STR( summary )
+    _CALENDAR_PROPERTY_STR( location )
+    _CALENDAR_PROPERTY_INT( calendar_book_id )
+    _CALENDAR_PROPERTY_STR( description )
+    _CALENDAR_PROPERTY_INT( busy_status )
+    _CALENDAR_PROPERTY_INT( event_status )
+    _CALENDAR_PROPERTY_INT( priority )
+    _CALENDAR_PROPERTY_INT( sensitivity )
+    _CALENDAR_PROPERTY_INT( has_rrule )
+    _CALENDAR_PROPERTY_DOUBLE( latitude )
+    _CALENDAR_PROPERTY_DOUBLE( longitude )
+    _CALENDAR_PROPERTY_INT( has_alarm )
+    _CALENDAR_PROPERTY_INT( original_event_id )
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_visibility )
+    _CALENDAR_PROPERTY_FILTER_INT( calendar_book_account_id )
+    _CALENDAR_PROPERTY_LLI( last_modified_time )
+    _CALENDAR_PROPERTY_STR( sync_data1 )
+    _CALENDAR_PROPERTY_STR( organizer_name )
+    _CALENDAR_PROPERTY_STR( categories )
+    _CALENDAR_PROPERTY_INT( has_attendee )
+    _CALENDAR_PROPERTY_INT( is_allday )
+    _CALENDAR_PROPERTY_STR( sync_data2 )
+    _CALENDAR_PROPERTY_STR( sync_data3 )
+    _CALENDAR_PROPERTY_STR( sync_data4 )
+_CALENDAR_END_READ_ONLY_VIEW( _calendar_instance_localtime_calendar_book_extended )
+
+/**
+ * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE
+ * @addtogroup CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE View/Property
+ * @section CAPI_SOCIAL_CALENDAR_SVC_VIEW_MODULE_calendar_extended_property _calendar_extended_property view (read only)
+ * <table>
+ *     <tr>
+ *     <th> Type </th>
+ *     <th> Property ID </th>
+ *     <th> Read, Write </th>
+ *     <th> Description </th>
+ *     </tr>
+ *     <tr><td> string </td><td> _uri </td><td> read only </td><td></td> Identifier of this extended_property view </tr>
+ *     <tr><td> integer </td><td> id </td><td> read only </td><td> DB record ID of the extended_property </td></tr>
+ *     <tr><td> integer </td><td> record_id </td><td> read,write </td><td> Related record ID </td></tr>
+ *     <tr><td> integer </td><td> record_type </td><td> read, write </td><td> Enumeration value of the record type (@ref calendar_record_type_e) </td></tr>
+ *     <tr><td> string </td><td> key </td><td> read, write </td><td> The key of the property </td></tr>
+ *     <tr><td> string </td><td> value </td><td> read, write </td><td> The value of the property </td></tr>
+ * </table>
+ */
+_CALENDAR_BEGIN_VIEW()
+    _CALENDAR_PROPERTY_INT( id ) // read_only
+    _CALENDAR_PROPERTY_INT( record_id )
+    _CALENDAR_PROPERTY_INT( record_type )
+    _CALENDAR_PROPERTY_STR( key )
+    _CALENDAR_PROPERTY_STR( value )
+_CALENDAR_END_VIEW( _calendar_extended_property )
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_SOCIAL_CALENDAR_VIEW_H__ */
diff --git a/include/cals-db-info.h b/include/cals-db-info.h
deleted file mode 100755 (executable)
index cea4166..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __CALENDAR_SVC_DB_INFO_H__
-#define __CALENDAR_SVC_DB_INFO_H__
-
-#define CALS_DB_PATH "/opt/dbspace/.calendar-svc.db"
-#define CALS_DB_JOURNAL_PATH "/opt/dbspace/.calendar-svc.db-journal"
-
-// For Security
-#define CALS_SECURITY_FILE_GROUP 6003
-#define CALS_SECURITY_DEFAULT_PERMISSION 0660
-#define CALS_SECURITY_DIR_DEFAULT_PERMISSION 0770
-
-#define CALS_TABLE_SCHEDULE "schedule_table"
-#define CALS_TABLE_ALARM "alarm_table"
-#define CALS_TABLE_CALENDAR "calendar_table"
-#define CALS_TABLE_PARTICIPANT "cal_participant_table"
-#define CALS_TABLE_TIMEZONE "timezone_table"
-#define CALS_TABLE_VERSION "version_table"
-#define CALS_TABLE_DELETED "deleted_table"
-#define CALS_TABLE_RRULE "rrule_table"
-#define CALS_TABLE_NORMAL_INSTANCE "normal_instance_table"
-#define CALS_TABLE_ALLDAY_INSTANCE "allday_instance_table"
-
-#endif /* __CALENDAR_SVC_DB_INFO_H__ */
-
diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..adf5f53
--- /dev/null
@@ -0,0 +1,88 @@
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/native)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common)
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+
+SET(INC_DIR ${CMAKE_SOURCE_DIR}/include)
+
+SET(CALSVCNATIVE calendar-service-native)
+
+SET(SRCS
+       ${CMAKE_SOURCE_DIR}/common/cal_record.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_calendar.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_event.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_todo.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_attendee.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_alarm.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_search.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_timezone.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_updated_info.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_instance_normal.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_instance_allday.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_instance_normal_extended.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_instance_allday_extended.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_extended.c
+       ${CMAKE_SOURCE_DIR}/common/cal_view.c
+       ${CMAKE_SOURCE_DIR}/common/cal_filter.c
+       ${CMAKE_SOURCE_DIR}/common/cal_query.c
+       ${CMAKE_SOURCE_DIR}/common/cal_inotify.c
+       ${CMAKE_SOURCE_DIR}/common/cal_list.c
+       ${CMAKE_SOURCE_DIR}/common/cal_time.cpp
+       ${CMAKE_SOURCE_DIR}/common/cal_vcalendar.c
+       ${CMAKE_SOURCE_DIR}/common/cal_vcalendar_make.c
+       ${CMAKE_SOURCE_DIR}/common/cal_vcalendar_parse.c
+       ${CMAKE_SOURCE_DIR}/common/cal_mutex.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db.c
+       ${CMAKE_SOURCE_DIR}/native/cal_calendar.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_util.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_alarm.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_attendee.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_instance.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_rrule.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_query.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_calendar.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_event.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_event.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_attendee.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_alarm.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_search.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_timezone.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_instance_normal.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_instance_normal_extended.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_instance_allday.c
+        ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_instance_allday_extended.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_todo.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_extended.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_extended.c
+       ${CMAKE_SOURCE_DIR}/native/cal_reminder.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_instance_helper.c
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(servicenative_pkgs REQUIRED db-util alarm-service capi-base-common)
+
+FOREACH(flag ${servicenative_pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(servicenative_pkgs_LDFLAGS "${pkgs_LDFLAGS} ${servicenative_pkgs_LDFLAGS}")
+
+ADD_DEFINITIONS("-DCAL_NATIVE")
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+
+#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+#ADD_LIBRARY(${CALSVCNATIVE} SHARED ${SRCS})
+#SET_TARGET_PROPERTIES(${CALSVCNATIVE} PROPERTIES SOVERSION ${VERSION_MAJOR})
+#SET_TARGET_PROPERTIES(${CALSVCNATIVE} PROPERTIES VERSION ${VERSION})
+#TARGET_LINK_LIBRARIES(${CALSVCNATIVE} ${servicenative_pkgs_LDFLAGS})
+
+#INSTALL(TARGETS ${CALSVCNATIVE} DESTINATION lib)
+
+#pc
+#CONFIGURE_FILE(${CALSVCNATIVE}.pc.in ${CALSVCNATIVE}.pc @ONLY)
+#INSTALL(FILES ${CALSVCNATIVE}.pc DESTINATION lib/pkgconfig)
+#INSTALL(FILES calendar-service2.pc DESTINATION lib/pkgconfig)
diff --git a/native/cal_access_control.c b/native/cal_access_control.c
new file mode 100644 (file)
index 0000000..78b1181
--- /dev/null
@@ -0,0 +1,361 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <pthread.h>
+#include <signal.h>
+#include <security-server.h>
+#include <sys/smack.h>
+#include <string.h>
+#include <pims-ipc-svc.h>
+
+#include "calendar_db.h"
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_time.h"
+#include "cal_record.h"
+#include "cal_mutex.h"
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_access_control.h"
+#include "cal_service.h"
+
+typedef struct {
+       unsigned int thread_id;
+       char *smack_label;
+       cal_permission_e permission;
+       int *write_list;
+}calendar_permission_info_s;
+
+static GList *__thread_list = NULL;
+
+static int have_smack = -1;
+
+static calendar_permission_info_s* __cal_access_control_find_permission_info(unsigned int thread_id);
+static void __cal_access_control_set_permission_info(unsigned int thread_id, const char *cookie);
+static void __cal_access_control_disconnected_cb(pims_ipc_h ipc, void *user_data);
+
+static calendar_permission_info_s* __cal_access_control_find_permission_info(unsigned int thread_id)
+{
+       GList *cursor;
+
+       for(cursor=__thread_list;cursor;cursor=cursor->next) {
+               calendar_permission_info_s *info = NULL;
+               info = cursor->data;
+               if (info->thread_id == thread_id)
+                       return info;
+       }
+       return NULL;
+}
+
+// check SMACK enable or disable
+static int __cal_have_smack(void)
+{
+       if (-1 == have_smack) {
+               if (NULL == smack_smackfs_path())
+                       have_smack = 0;
+               else
+                       have_smack = 1;
+       }
+       return have_smack;
+}
+
+static void __cal_access_control_set_permission_info(unsigned int thread_id, const char *cookie)
+{
+       calendar_permission_info_s *info = NULL;
+       const char *smack_label;
+       bool smack_enabled = false;
+
+       if (__cal_have_smack() == 1)
+               smack_enabled = true;
+       else
+               INFO("SAMCK disabled");
+
+       info = __cal_access_control_find_permission_info(thread_id);
+       if(info == NULL) {
+               ERR("dont' have access info of this thread(%d)", thread_id);
+               return ;
+       }
+       smack_label = info->smack_label;
+
+       if ((smack_label && 0 == strcmp(smack_label, "calendar-service")) || !smack_enabled) {
+               info->permission |= CAL_PERMISSION_READ;
+               info->permission |= CAL_PERMISSION_WRITE;
+       }
+       else if (cookie) {
+               if (SECURITY_SERVER_API_SUCCESS == security_server_check_privilege_by_cookie(cookie, "calendar-service::svc", "r"))
+                       info->permission |= CAL_PERMISSION_READ;
+               if (SECURITY_SERVER_API_SUCCESS == security_server_check_privilege_by_cookie(cookie, "calendar-service::svc", "w"))
+                       info->permission |= CAL_PERMISSION_WRITE;
+       }
+       SEC_INFO("Thread(0x%x), info(%p), smack :%s, permission:%d", thread_id, info, smack_label, info->permission);
+
+       CAL_FREE(info->write_list);
+
+       char query[CAL_DB_SQL_MAX_LEN] = {0,};
+       int count = 0;
+       int ret = 0;
+       sqlite3_stmt *stmt;
+       int write_index = 0;
+       snprintf(query, sizeof(query), "SELECT count(id) FROM %s WHERE deleted = 0 ", CAL_TABLE_CALENDAR);
+       ret = _cal_db_util_query_get_first_int_result(query, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("cal_db_util_query_prepare() Fail(%d)", ret);
+               return;
+       }
+
+       if (info->permission & CAL_PERMISSION_WRITE) {
+               info->write_list = calloc(count+1, sizeof(int));
+               retm_if(NULL == info->write_list, "calloc() Fail");
+               info->write_list[0] = -1;
+       }
+
+       snprintf(query, sizeof(query), "SELECT id, mode, owner_label FROM %s WHERE deleted = 0 ", CAL_TABLE_CALENDAR);
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt) {
+               ERR("DB Failed");
+               return;
+       }
+
+       while (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               int id = 0;
+               int mode = 0;
+               char *temp = NULL;
+
+               id = sqlite3_column_int(stmt, 0);
+               mode = sqlite3_column_int(stmt, 1);
+               temp = (char *)sqlite3_column_text(stmt, 2);
+
+               if ( temp && ( (smack_label && 0 == strcmp(temp, smack_label)) ||
+                                       ( smack_label && 0 == strcmp(smack_label, "calendar-service") ) ) )  {// owner and calendar-service
+                       if (info->permission & CAL_PERMISSION_WRITE)
+                               info->write_list[write_index++] = id;
+               }
+               else {
+                       switch(mode) {
+                       case CALENDAR_BOOK_MODE_NONE:
+                               if (info->permission & CAL_PERMISSION_WRITE)
+                                       info->write_list[write_index++] = id;
+                               break;
+                       case CALENDAR_BOOK_MODE_RECORD_READONLY:
+                       default:
+                               break;
+                       }
+               }
+       } // while
+
+       if (info->permission & CAL_PERMISSION_WRITE)
+               info->write_list[write_index] = -1;
+
+       sqlite3_finalize(stmt);
+}
+
+void _cal_access_control_set_client_info(const char* smack_label, const char* cookie)
+{
+       unsigned int thread_id = (unsigned int)pthread_self();
+       calendar_permission_info_s *info = NULL;
+
+       _cal_mutex_lock(CAL_MUTEX_ACCESS_CONTROL);
+       info = __cal_access_control_find_permission_info(thread_id);
+       if (NULL == info) {
+               info = calloc(1, sizeof(calendar_permission_info_s));
+               if(NULL == info) {
+                       ERR("callo() Fail");
+                       _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+                       return;
+               }
+               __thread_list  = g_list_append(__thread_list, info);
+       }
+       info->thread_id = thread_id;
+       CAL_FREE(info->smack_label);
+       info->smack_label = SAFE_STRDUP(smack_label);
+       __cal_access_control_set_permission_info(thread_id, cookie);
+
+       // for close DB or free access_control when client is disconnected
+       pims_ipc_svc_set_client_disconnected_cb(__cal_access_control_disconnected_cb,NULL);
+
+       _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+}
+
+void _cal_access_control_unset_client_info(void)
+{
+       calendar_permission_info_s *find = NULL;
+
+       _cal_mutex_lock(CAL_MUTEX_ACCESS_CONTROL);
+       find = __cal_access_control_find_permission_info(pthread_self());
+       if (find) {
+               CAL_FREE(find->smack_label);
+               CAL_FREE(find->write_list);
+               __thread_list = g_list_remove(__thread_list, find);
+               free(find);
+       }
+       _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+}
+
+bool _cal_access_control_have_permission(cal_permission_e permission)
+{
+       calendar_permission_info_s *find = NULL;
+
+       _cal_mutex_lock(CAL_MUTEX_ACCESS_CONTROL);
+       find = __cal_access_control_find_permission_info(pthread_self());
+       if (!find) {
+               _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+               return false;
+       }
+
+       if (CAL_PERMISSION_NONE == permission) {
+               _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+               return false;
+       }
+
+       if ((find->permission & permission) == permission) {
+               _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+               return true;
+       }
+
+       _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+       ERR("Does not have permission %d, this module has permission %d",
+                       permission, find->permission);
+
+       return false;
+}
+
+char* _cal_access_control_get_label(void)
+{
+       unsigned int thread_id = (unsigned int)pthread_self();
+       calendar_permission_info_s *info = NULL;
+       char *tmp = NULL;
+
+       _cal_mutex_lock(CAL_MUTEX_ACCESS_CONTROL);
+       info = __cal_access_control_find_permission_info(thread_id);
+
+       if (info == NULL) {
+               _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+               return NULL;
+       }
+       tmp = SAFE_STRDUP(info->smack_label);
+       _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+
+       return tmp;
+}
+
+
+void _cal_access_control_reset(void)
+{
+       _cal_mutex_lock(CAL_MUTEX_ACCESS_CONTROL);
+       GList *cursor;
+       for(cursor=__thread_list;cursor;cursor=cursor->next) {
+               calendar_permission_info_s *info = NULL;
+               info = cursor->data;
+               if (info)
+                       __cal_access_control_set_permission_info(info->thread_id, NULL);
+       }
+       _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+}
+
+bool _cal_access_control_have_write_permission(int calendarbook_id)
+{
+       int i = 0;
+       calendar_permission_info_s *find = NULL;
+
+       _cal_mutex_lock(CAL_MUTEX_ACCESS_CONTROL);
+       find = __cal_access_control_find_permission_info(pthread_self());
+       if (!find) {
+               _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+               ERR("can not found access info");
+               return false;
+       }
+
+       if (NULL == find->write_list) {
+               _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+               ERR("there is no write access info");
+               return false;
+       }
+
+       while(1) {
+               if (find->write_list[i] == -1)
+                       break;
+               if (calendarbook_id == find->write_list[i]) {
+                       _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+                       return true;
+               }
+               i++;
+       }
+
+       _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+       return false;
+}
+
+static void __cal_access_control_disconnected_cb(pims_ipc_h ipc, void *user_data)
+{
+       ENTER();
+       calendar_permission_info_s *find = NULL;
+
+       _cal_mutex_lock(CAL_MUTEX_ACCESS_CONTROL);
+       find = __cal_access_control_find_permission_info(pthread_self());
+       if (find) {
+               CAL_FREE(find->smack_label);
+               CAL_FREE(find->write_list);
+               __thread_list = g_list_remove(__thread_list, find);
+               free(find);
+       }
+       _cal_mutex_unlock(CAL_MUTEX_ACCESS_CONTROL);
+       // if client did not call disconnect function such as disconnect
+       // DB will be closed in _cal_db_internal_disconnect()
+       _cal_calendar_internal_disconnect();
+}
+
+int _cal_is_owner(int calendarbook_id)
+{
+       int ret;
+       sqlite3_stmt *stmt = NULL;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char *owner_label = NULL;
+       char *saved_smack = NULL;
+
+       snprintf(query, sizeof(query),
+                       "SELECT owner_label FROM "CAL_TABLE_CALENDAR" "
+                       "WHERE id = %d", calendarbook_id);
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt) {
+               ERR("DB error : _cal_db_util_query_prepare() Failed()");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       ret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_ROW != ret) {
+               ERR("_cal_db_util_stmt_step() Failed(%d)", ret);
+               sqlite3_finalize(stmt);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       ret = CALENDAR_ERROR_PERMISSION_DENIED;
+
+       owner_label = (char*)sqlite3_column_text(stmt, 0);
+       saved_smack = _cal_access_control_get_label();
+
+       if (owner_label && saved_smack && strcmp(owner_label, saved_smack) == 0)
+               ret = CALENDAR_ERROR_NONE;
+
+       sqlite3_finalize(stmt);
+
+       free(saved_smack);
+       return ret;
+}
+
diff --git a/native/cal_access_control.h b/native/cal_access_control.h
new file mode 100644 (file)
index 0000000..b988314
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_ACCESS_CONTROL_H__
+#define __CALENDAR_SVC_ACCESS_CONTROL_H__
+
+#include "cal_typedef.h"
+
+void _cal_access_control_set_client_info(const char* smack_label, const char* cookie);
+void _cal_access_control_unset_client_info(void);
+bool _cal_access_control_have_permission(cal_permission_e permission);
+
+char* _cal_access_control_get_label(void);
+
+void _cal_access_control_reset(void);  // reset read_list, write_list..
+bool _cal_access_control_have_write_permission(int calendarbook_id);
+
+int _cal_is_owner(int calendarbook_id);
+
+#endif // __CALENDAR_SVC_ACCESS_CONTROL_H__
+
diff --git a/native/cal_calendar.c b/native/cal_calendar.c
new file mode 100644 (file)
index 0000000..b8539ef
--- /dev/null
@@ -0,0 +1,246 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <unistd.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <db-util.h>
+
+#include "cal_service.h"
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_db.h"
+#include "cal_view.h"
+
+#ifdef CAL_NATIVE
+#include "cal_inotify.h"
+#endif
+
+static TLS int db_ref_cnt = 0;
+
+API int calendar_connect(void)
+{
+       CAL_FN_CALL;
+       int ret = 0;
+
+       DBG("pthread_self=%x, db_ref_cnt=%p", pthread_self(),&db_ref_cnt );
+
+       g_type_init();  // added for alarmmgr
+
+       if(db_ref_cnt <= 0)
+       {
+               ret = _cal_db_open();
+               retvm_if(ret, ret, "cal_db_open() Failed(%d)", ret);
+
+               db_ref_cnt = 0;
+#ifdef CAL_NATIVE
+               _cal_inotify_initialize();
+#endif
+       }
+       db_ref_cnt++;
+
+       _cal_view_initialize();
+
+       DBG("db_ref_cnt(%d)", db_ref_cnt);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_disconnect(void)
+{
+       CAL_FN_CALL;
+
+       DBG("db_ref_cnt(%d)", db_ref_cnt);
+       DBG("pthread_self=%x, db_ref_cnt=%p", pthread_self(),&db_ref_cnt );
+
+       retvm_if(0 == db_ref_cnt, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Calendar service was not connected");
+
+       if (db_ref_cnt==1)
+       {
+               _cal_db_close();
+
+               db_ref_cnt = 0;
+
+#ifdef CAL_NATIVE
+               _cal_inotify_finalize();
+#endif
+
+               _cal_view_finalize();
+               return CALENDAR_ERROR_NONE;
+       }
+       db_ref_cnt--;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+void _cal_calendar_internal_disconnect(void)
+{
+       ENTER();
+       if (db_ref_cnt > 0)
+       {
+               _cal_db_close();
+
+               db_ref_cnt = 0;
+       }
+}
+
+#ifdef CAL_NATIVE
+API int calendar_db_add_changed_cb(const char* view_uri, calendar_db_changed_cb callback, void* user_data )
+{
+       CAL_FN_CALL;
+       int ret;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+
+       retv_if(NULL == view_uri || NULL == callback , CALENDAR_ERROR_INVALID_PARAMETER);
+
+       type = _cal_view_get_type(view_uri);
+
+       switch(type)
+       {
+       case CAL_RECORD_TYPE_CALENDAR:
+               ret = _cal_inotify_subscribe(CAL_NOTI_TYPE_CALENDAR, CAL_NOTI_CALENDAR_CHANGED, callback, user_data);
+               break;
+       case CAL_RECORD_TYPE_EVENT:
+               ret = _cal_inotify_subscribe(CAL_NOTI_TYPE_EVENT, CAL_NOTI_EVENT_CHANGED, callback, user_data);
+               break;
+       case CAL_RECORD_TYPE_TODO:
+               ret = _cal_inotify_subscribe(CAL_NOTI_TYPE_TODO, CAL_NOTI_TODO_CHANGED, callback, user_data);
+               break;
+       default:
+               ERR("Invalid view_uri(%s)", view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "_cal_inotify_subscribe() Failed(%d)", ret);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_db_remove_changed_cb( const char* view_uri, calendar_db_changed_cb callback, void* user_data )
+{
+       CAL_FN_CALL;
+       int ret;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+
+       retv_if(NULL == view_uri || NULL == callback , CALENDAR_ERROR_INVALID_PARAMETER);
+
+       type = _cal_view_get_type(view_uri);
+
+       switch(type)
+       {
+       case CAL_RECORD_TYPE_CALENDAR:
+               ret = _cal_inotify_unsubscribe_with_data(CAL_NOTI_CALENDAR_CHANGED,
+                               callback, user_data);
+               break;
+       case CAL_RECORD_TYPE_EVENT:
+               ret = _cal_inotify_unsubscribe_with_data(CAL_NOTI_EVENT_CHANGED,
+                               callback, user_data);
+               break;
+       case CAL_RECORD_TYPE_TODO:
+               ret = _cal_inotify_unsubscribe_with_data(CAL_NOTI_TODO_CHANGED,
+                               callback, user_data);
+               break;
+       default:
+               ERR("Invalid view_uri(%s)", view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "_cal_inotify_unsubscribe_with_data() Failed(%d)", ret);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_connect_on_thread(void)
+{
+       CAL_FN_CALL;
+       int ret = 0;
+
+       DBG("pthread_self=%x, db_ref_cnt=%p", pthread_self(),&db_ref_cnt );
+
+       g_type_init();  // added for alarmmgr
+
+       if(db_ref_cnt <= 0)
+       {
+               ret = _cal_db_open();
+               retvm_if(ret, ret, "cal_db_open() Failed(%d)", ret);
+
+               db_ref_cnt = 0;
+               _cal_inotify_initialize();
+
+       }
+       db_ref_cnt++;
+
+       _cal_view_initialize();
+
+       DBG("db_ref_cnt(%d)", db_ref_cnt);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_disconnect_on_thread(void)
+{
+       CAL_FN_CALL;
+
+       DBG("db_ref_cnt(%d)", db_ref_cnt);
+       DBG("pthread_self=%x, db_ref_cnt=%p", pthread_self(),&db_ref_cnt );
+
+       retvm_if(0 == db_ref_cnt, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Calendar service was not connected");
+
+       if (db_ref_cnt==1) {
+               _cal_db_close();
+
+               db_ref_cnt = 0;
+
+               _cal_inotify_finalize();
+
+               _cal_view_finalize();
+               return CALENDAR_ERROR_NONE;
+       }
+       db_ref_cnt--;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_connect_with_flags(unsigned int flags)
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       ret = calendar_connect();
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               if (flags & CALENDAR_CONNECT_FLAG_RETRY)
+               {
+                       int retry_time = 500;
+                       int i = 0;
+                       for(i=0;i<6;i++)
+                       {
+                               usleep(retry_time*1000);
+                               ret = calendar_connect();
+                               DBG("retry cnt=%d, ret=%x",(i+1), ret);
+                               if (ret == CALENDAR_ERROR_NONE)
+                                       break;
+                               retry_time *= 2;
+                       }
+
+               }
+       }
+
+       return ret;
+}
+#endif
diff --git a/native/cal_db.c b/native/cal_db.c
new file mode 100755 (executable)
index 0000000..58a5ae5
--- /dev/null
@@ -0,0 +1,1999 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <unistd.h>
+#include <glib.h>
+#include <db-util.h>
+
+#include "calendar_db.h"
+#include "calendar_vcalendar.h"
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+#include "cal_db_util.h"
+#include "cal_list.h"
+#include "cal_db.h"
+#include "cal_access_control.h"
+
+#define BULK_DEFAULT_COUNT 100
+
+/*
+ * Declear DB plugin
+ */
+extern cal_db_plugin_cb_s _cal_db_calendar_plugin_cb;
+extern cal_db_plugin_cb_s _cal_db_event_plugin_cb;
+extern cal_db_plugin_cb_s _cal_db_instance_normal_plugin_cb;
+extern cal_db_plugin_cb_s _cal_db_instance_normal_extended_plugin_cb;
+extern cal_db_plugin_cb_s _cal_db_instance_allday_plugin_cb;
+extern cal_db_plugin_cb_s _cal_db_instance_allday_extended_plugin_cb;
+extern cal_db_plugin_cb_s _cal_db_todo_plugin_cb;
+extern cal_db_plugin_cb_s _cal_db_alarm_plugin_cb;
+extern cal_db_plugin_cb_s _cal_db_attendee_plugin_cb;
+extern cal_db_plugin_cb_s _cal_db_search_plugin_cb;
+extern cal_db_plugin_cb_s _cal_db_timezone_plugin_cb;
+extern cal_db_plugin_cb_s _cal_db_extended_plugin_cb;
+
+static cal_db_plugin_cb_s* __cal_db_get_plugin(cal_record_type_e type);
+
+#ifdef CAL_NATIVE
+typedef struct {
+       calendar_list_h list;
+       calendar_db_insert_result_cb callback;
+       void *user_data;
+} __insert_records_data_s;
+
+typedef struct {
+       calendar_list_h list;
+       calendar_db_result_cb callback;
+       void *user_data;
+} __update_records_data_s;
+
+typedef struct {
+       const char* view_uri;
+       int *ids;
+       int count;
+       calendar_db_result_cb callback;
+       void *user_data;
+} __delete_records_data_s;
+
+typedef struct {
+       char* vcalendar_stream;
+       calendar_db_insert_result_cb callback;
+       void *user_data;
+} __insert_vcalendars_data_s;
+
+typedef struct {
+       char* vcalendar_stream;
+       int *ids;
+       int count;
+       calendar_db_result_cb callback;
+       void *user_data;
+} __replace_vcalendars_data_s;
+
+typedef struct {
+       calendar_list_h list;
+       int *ids;
+       int count;
+       calendar_db_result_cb callback;
+       void *user_data;
+} __replace_records_data_s;
+static gboolean  __cal_db_insert_records_idle(void* user_data);
+static gboolean  __cal_db_update_records_idle(void* user_data);
+static gboolean  __cal_db_delete_records_idle(void* user_data);
+static gboolean  __cal_db_insert_vcalendars_idle(void* user_data);
+static gboolean  __cal_db_replace_vcalendars_idle(void* user_data);
+static gboolean  __cal_db_replace_records_idle(void* user_data);
+
+static gboolean  __cal_db_insert_records_idle(void* user_data)
+{
+       __insert_records_data_s* callback_data = user_data;
+       int ret = CALENDAR_ERROR_NONE;
+       int *ids = NULL;
+       int count = 0;
+
+       if (callback_data == NULL)
+       {
+               ERR("data is NULL");
+               return false;
+       }
+
+       ret = calendar_db_insert_records(callback_data->list, &ids, &count);
+
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               callback_data->callback(ret, ids, count, callback_data->user_data);
+       }
+       else
+       {
+               callback_data->callback(ret, NULL, 0, callback_data->user_data);
+       }
+
+       calendar_list_destroy(callback_data->list, true);
+       CAL_FREE(callback_data);
+       CAL_FREE(ids);
+       return false;
+}
+
+static gboolean  __cal_db_update_records_idle(void* user_data)
+{
+       __update_records_data_s* callback_data = user_data;
+       int ret = CALENDAR_ERROR_NONE;
+
+       if (callback_data == NULL)
+       {
+               ERR("data is NULL");
+               return false;
+       }
+       ret = calendar_db_update_records(callback_data->list);
+
+       callback_data->callback(ret, callback_data->user_data);
+
+       calendar_list_destroy(callback_data->list, true);
+       CAL_FREE(callback_data);
+       return false;
+}
+
+static gboolean  __cal_db_delete_records_idle(void* user_data)
+{
+       __delete_records_data_s* callback_data = user_data;
+       int ret = CALENDAR_ERROR_NONE;
+
+       if (callback_data == NULL)
+       {
+               ERR("data is NULL");
+               return false;
+       }
+       ret = calendar_db_delete_records(callback_data->view_uri,callback_data->ids,callback_data->count);
+
+       callback_data->callback(ret, callback_data->user_data);
+
+       CAL_FREE(callback_data->ids);
+       CAL_FREE(callback_data);
+       return false;
+}
+static gboolean  __cal_db_insert_vcalendars_idle(void* user_data)
+{
+       __insert_vcalendars_data_s* callback_data = user_data;
+       int ret = CALENDAR_ERROR_NONE;
+       int *ids = NULL;
+       int count = 0;
+
+       if (callback_data == NULL)
+       {
+               ERR("data is NULL");
+               return false;
+       }
+
+       ret = calendar_db_insert_vcalendars(callback_data->vcalendar_stream, &ids, &count);
+
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               callback_data->callback(ret, ids, count, callback_data->user_data);
+       }
+       else
+       {
+               callback_data->callback(ret, NULL, 0, callback_data->user_data);
+       }
+
+       CAL_FREE(callback_data->vcalendar_stream);
+       CAL_FREE(callback_data);
+       CAL_FREE(ids);
+       return false;
+}
+
+static gboolean  __cal_db_replace_vcalendars_idle(void* user_data)
+{
+       __replace_vcalendars_data_s* callback_data = user_data;
+       int ret = CALENDAR_ERROR_NONE;
+
+       if (callback_data == NULL)
+       {
+               ERR("data is NULL");
+               return false;
+       }
+       ret = calendar_db_replace_vcalendars(callback_data->vcalendar_stream,
+                       callback_data->ids,callback_data->count);
+
+       callback_data->callback(ret, callback_data->user_data);
+
+       CAL_FREE(callback_data->vcalendar_stream);
+       CAL_FREE(callback_data->ids);
+       CAL_FREE(callback_data);
+       return false;
+}
+
+static gboolean  __cal_db_replace_records_idle(void* user_data)
+{
+       __replace_records_data_s* callback_data = user_data;
+       int ret = CALENDAR_ERROR_NONE;
+
+       if (callback_data == NULL)
+       {
+               ERR("data is NULL");
+               return false;
+       }
+       ret = calendar_db_replace_records(callback_data->list,callback_data->ids,callback_data->count);
+
+       callback_data->callback(ret, callback_data->user_data);
+
+       calendar_list_destroy(callback_data->list, true);
+       CAL_FREE(callback_data->ids);
+       CAL_FREE(callback_data);
+       return false;
+}
+
+#endif
+
+static cal_db_plugin_cb_s* __cal_db_get_plugin(cal_record_type_e type)
+{
+       switch (type)
+       {
+       case CAL_RECORD_TYPE_CALENDAR:
+               return (&_cal_db_calendar_plugin_cb);
+       case CAL_RECORD_TYPE_EVENT:
+               return (&_cal_db_event_plugin_cb);
+       case CAL_RECORD_TYPE_TODO:
+               return (&_cal_db_todo_plugin_cb);
+       case CAL_RECORD_TYPE_ALARM:
+               return (&_cal_db_alarm_plugin_cb);
+       case CAL_RECORD_TYPE_ATTENDEE:
+               return (&_cal_db_attendee_plugin_cb);
+       case CAL_RECORD_TYPE_TIMEZONE:
+               return (&_cal_db_timezone_plugin_cb);
+       case CAL_RECORD_TYPE_INSTANCE_NORMAL:
+               return (&_cal_db_instance_normal_plugin_cb);
+       case CAL_RECORD_TYPE_INSTANCE_ALLDAY:
+               return (&_cal_db_instance_allday_plugin_cb);
+       case CAL_RECORD_TYPE_INSTANCE_NORMAL_EXTENDED:
+               return (&_cal_db_instance_normal_extended_plugin_cb);
+       case CAL_RECORD_TYPE_INSTANCE_ALLDAY_EXTENDED:
+               return (&_cal_db_instance_allday_extended_plugin_cb);
+       case CAL_RECORD_TYPE_SEARCH:
+               return (&_cal_db_search_plugin_cb);
+       case CAL_RECORD_TYPE_EXTENDED:
+               return (&_cal_db_extended_plugin_cb);
+       default:
+               ERR("Invalid plugin(%d)", type);
+               return NULL;
+       }
+       return NULL;
+}
+
+void _cal_db_initialize_view_table(void)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_db_util_error_e dbret;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+
+       ret = _cal_db_util_begin_trans();
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_begin_trans() failed");
+               return ;
+       }
+
+       /*
+        * CAL_VIEW_TABLE_EVENT
+        * schedule_table(type=1) + rrule_table
+        * A : schedule_table
+        * B : rrule_table
+        * C : calendar_table
+        */
+       snprintf(query, sizeof(query),
+                       "CREATE VIEW IF NOT EXISTS %s AS "
+                       "SELECT A.*, "
+                       "B.range_type, B.until_type, B.until_utime, B.until_datetime, B.count, "
+                       "B.interval, B.bysecond, B.byminute, B.byhour, B.byday, B.bymonthday, "
+                       "B.byyearday, B.byweekno, B.bymonth, B.bysetpos, B.wkst, C.deleted "
+                       "FROM %s as A "
+                       "LEFT OUTER JOIN %s B ON A.id = B.event_id "
+                       "JOIN %s C ON A.calendar_id = C.id "
+                       "WHERE A.type = %d AND A.is_deleted=0 "
+                       "AND C.deleted = 0 ",
+                       CAL_VIEW_TABLE_EVENT,
+                       CAL_TABLE_SCHEDULE,
+                       CAL_TABLE_RRULE,
+                       CAL_TABLE_CALENDAR,
+                       CAL_SCH_TYPE_EVENT);
+       dbret = _cal_db_util_query_exec(query);
+       //SEC_DBG("%s",query);
+       if (dbret != CAL_DB_OK)
+       {
+               ERR("create view fail");
+       }
+
+       /*
+        * CAL_VIEW_TABLE_TODO
+        * schedule_table(type=2) + rrule_table
+        * A : schedule_table
+        * B : rrule_table
+        * C : calendar_table
+        */
+       snprintf(query, sizeof(query),
+                       "CREATE VIEW IF NOT EXISTS %s AS "
+                       "SELECT A.*, "
+                       "B.range_type, B.until_type, B.until_utime, B.until_datetime, B.count, "
+                       "B.interval, B.bysecond, B.byminute, B.byhour, B.byday, B.bymonthday, "
+                       "B.byyearday, B.byweekno, B.bymonth, B.bysetpos, B.wkst, C.deleted "
+                       "FROM %s as A "
+                       "LEFT OUTER JOIN %s B ON A.id = B.event_id "
+                       "JOIN %s C ON A.calendar_id = C.id "
+                       "WHERE A.type = %d AND A.is_deleted=0 "
+                       "AND C.deleted = 0 ",
+                       CAL_VIEW_TABLE_TODO,
+                       CAL_TABLE_SCHEDULE,
+                       CAL_TABLE_RRULE,
+                       CAL_TABLE_CALENDAR,
+                       CAL_SCH_TYPE_TODO);
+       dbret = _cal_db_util_query_exec(query);
+       //SEC_DBG("%s",query);
+       if (dbret != CAL_DB_OK)
+       {
+               ERR("create view fail");
+       }
+
+       /*
+        * CAL_VIEW_TABLE_NORMAL_INSTANCE  : CALENDAR_VIEW_INSTANCE_NORMAL_CALENDAR
+        * normal_instance_table + schedule_table(type=1) + calendar_table
+        * A = normal_instace_table
+        * B = schedule_table
+        * C = calendar_table
+        */
+       snprintf(query, sizeof(query),
+                       "CREATE VIEW IF NOT EXISTS %s AS SELECT A.event_id, "
+                       "B.dtstart_type, A.dtstart_utime, B.dtstart_datetime, "
+                       "B.dtend_type, A.dtend_utime, B.dtend_datetime, "
+                       "B.summary, B.description, "
+                       "B.location, B.busy_status, B.task_status, B.priority, B.sensitivity, "
+                       "B.rrule_id, B.latitude, B.longitude, B.has_alarm, B.original_event_id, "
+                       "B.calendar_id, B.last_mod, "
+                       "B.sync_data1, "
+                       "C.visibility, C.account_id "
+                       "FROM %s as A, %s as B, %s as C "
+                       "ON A.event_id = B.id AND B.calendar_id = C.id "
+                       "where C.deleted = 0 AND B.is_deleted = 0 ",
+                       CAL_VIEW_TABLE_NORMAL_INSTANCE,
+                       CAL_TABLE_NORMAL_INSTANCE,
+                       CAL_TABLE_SCHEDULE,
+                       CAL_TABLE_CALENDAR);
+       dbret = _cal_db_util_query_exec(query);
+       //SEC_DBG("%s",query);
+       if (dbret != CAL_DB_OK)
+       {
+               ERR("create view fail");
+       }
+
+       // CAL_VIEW_TABLE_ALLDAY_INSTANCE  : CALENDAR_VIEW_INSTANCE_ALLDAY_CALENDAR
+       snprintf(query, sizeof(query),
+                       "CREATE VIEW IF NOT EXISTS %s AS SELECT A.event_id, "
+                       "B.dtstart_type, B.dtstart_utime, A.dtstart_datetime, "
+                       "B.dtend_type, B.dtend_utime, A.dtend_datetime, "
+                       "B.summary, B.description, "
+                       "B.location, B.busy_status, B.task_status, B.priority, B.sensitivity, "
+                       "B.rrule_id, B.latitude, B.longitude, B.has_alarm, B.original_event_id, "
+                       "B.calendar_id, B.last_mod, "
+                       "B.sync_data1, B.is_allday, "
+                       "C.visibility, C.account_id "
+                       "FROM %s as A, %s as B, %s as C "
+                       "ON A.event_id = B.id AND B.calendar_id = C.id "
+                       "where C.deleted = 0 AND B.is_deleted = 0 ",
+                       CAL_VIEW_TABLE_ALLDAY_INSTANCE,
+                       CAL_TABLE_ALLDAY_INSTANCE,
+                       CAL_TABLE_SCHEDULE,
+                       CAL_TABLE_CALENDAR);
+       dbret = _cal_db_util_query_exec(query);
+       //SEC_DBG("%s",query);
+       if (dbret != CAL_DB_OK)
+       {
+               ERR("create view fail");
+       }
+
+       /*
+        * CAL_VIEW_TABLE_NORMAL_INSTANCE_EXTENDED  : CALENDAR_VIEW_INSTANCE_NORMAL_CALENDAR_EXTENDED
+        * normal_instance_table + schedule_table(type=1) + calendar_table
+        * A = normal_instace_table
+        * B = schedule_table
+        * C = calendar_table
+        */
+       snprintf(query, sizeof(query),
+                       "CREATE VIEW IF NOT EXISTS %s AS SELECT A.event_id, "
+                       "B.dtstart_type, A.dtstart_utime, B.dtstart_datetime, "
+                       "B.dtend_type, A.dtend_utime, B.dtend_datetime, "
+                       "B.summary, B.description, "
+                       "B.location, B.busy_status, B.task_status, B.priority, B.sensitivity, "
+                       "B.rrule_id, B.latitude, B.longitude, B.has_alarm, B.original_event_id, "
+                       "B.calendar_id, B.last_mod, "
+                       "B.sync_data1, B.organizer_name, B.categories, B.has_attendee, B.sync_data2, B.sync_data3, B.sync_data4, "
+                       "C.visibility, C.account_id "
+                       "FROM %s as A, %s as B, %s as C "
+                       "ON A.event_id = B.id AND B.calendar_id = C.id "
+                       "where C.deleted = 0 AND B.is_deleted = 0 ",
+                       CAL_VIEW_TABLE_NORMAL_INSTANCE_EXTENDED,
+                       CAL_TABLE_NORMAL_INSTANCE,
+                       CAL_TABLE_SCHEDULE,
+                       CAL_TABLE_CALENDAR);
+       dbret = _cal_db_util_query_exec(query);
+       //SEC_DBG("%s",query);
+       if (dbret != CAL_DB_OK)
+       {
+               ERR("create view fail");
+       }
+
+       // CAL_VIEW_TABLE_ALLDAY_INSTANCE_EXTENDED  : CALENDAR_VIEW_INSTANCE_ALLDAY_CALENDAR_EXTENDED
+       snprintf(query, sizeof(query),
+                       "CREATE VIEW IF NOT EXISTS %s AS SELECT A.event_id, "
+                       "B.dtstart_type, B.dtstart_utime, A.dtstart_datetime, "
+                       "B.dtend_type, B.dtend_utime, A.dtend_datetime, "
+                       "B.summary, B.description, "
+                       "B.location, B.busy_status, B.task_status, B.priority, B.sensitivity, "
+                       "B.rrule_id, B.latitude, B.longitude, B.has_alarm, B.original_event_id, "
+                       "B.calendar_id, B.last_mod, "
+                       "B.sync_data1, B.organizer_name, B.categories, B.has_attendee, B.sync_data2, B.sync_data3, B.sync_data4, B.is_allday, "
+                       "C.visibility, C.account_id "
+                       "FROM %s as A, %s as B, %s as C "
+                       "ON A.event_id = B.id AND B.calendar_id = C.id "
+                       "where C.deleted = 0 AND B.is_deleted = 0 ",
+                       CAL_VIEW_TABLE_ALLDAY_INSTANCE_EXTENDED,
+                       CAL_TABLE_ALLDAY_INSTANCE,
+                       CAL_TABLE_SCHEDULE,
+                       CAL_TABLE_CALENDAR);
+       dbret = _cal_db_util_query_exec(query);
+       //SEC_DBG("%s",query);
+       if (dbret != CAL_DB_OK)
+       {
+               ERR("create view fail");
+       }
+
+       // event_calendar view  :  CALENDAR_VIEW_EVENT_CALENDAR
+       // A : schedule_table
+       // B : rrule_table
+       // C : calendar_table
+       snprintf(query, sizeof(query),
+                       "CREATE VIEW IF NOT EXISTS %s AS "
+                       "SELECT A.*, "
+                       "B.range_type, B.until_type, B.until_utime, B.until_datetime, B.count, "
+                       "B.interval, B.bysecond, B.byminute, B.byhour, B.byday, B.bymonthday, "
+                       "B.byyearday, B.byweekno, B.bymonth, B.bysetpos, B.wkst, "
+                       "C.*"
+                       "FROM %s A "
+                       "JOIN %s C ON A.calendar_id = C.id "
+                       "LEFT OUTER JOIN %s B ON A.id = B.event_id "
+                       "WHERE A.type = 1 AND c.deleted = 0 AND A.is_deleted = 0 ",
+                       CAL_VIEW_TABLE_EVENT_CALENDAR,
+                       CAL_TABLE_SCHEDULE, CAL_TABLE_CALENDAR,
+                       CAL_TABLE_RRULE );
+       dbret = _cal_db_util_query_exec(query);
+       //SEC_DBG("%s",query);
+       if (dbret != CAL_DB_OK)
+       {
+               ERR("create view fail");
+       }
+
+       // todo_calendar view  : CALENDAR_VIEW_TODO_CALENDAR
+       // A : schedule_table
+       // B : rrule_table
+       // C : calendar_table
+       snprintf(query, sizeof(query),
+                       "CREATE VIEW IF NOT EXISTS %s AS "
+                       "SELECT A.*, "
+                       "B.range_type, B.until_type, B.until_utime, B.until_datetime, B.count, "
+                       "B.interval, B.bysecond, B.byminute, B.byhour, B.byday, B.bymonthday, "
+                       "B.byyearday, B.byweekno, B.bymonth, B.bysetpos, B.wkst, "
+                       "C.*"
+                       "FROM %s A "
+                       "JOIN %s C ON A.calendar_id = C.id "
+                       "LEFT OUTER JOIN %s B ON A.id = B.event_id "
+                       "WHERE A.type = 2 AND c.deleted = 0 AND A.is_deleted = 0 ",
+                       CAL_VIEW_TABLE_TODO_CALENDAR,
+                       CAL_TABLE_SCHEDULE, CAL_TABLE_CALENDAR,
+                       CAL_TABLE_RRULE);
+       dbret = _cal_db_util_query_exec(query);
+       //SEC_DBG("%s",query);
+       if (dbret != CAL_DB_OK)
+       {
+               ERR("create view fail");
+       }
+
+       // event_calendar_attendee view  :  CALENDAR_VIEW_EVENT_CALENDAR_ATTENDEE
+       // A : schedule_table
+       // B : attendee_table
+       // C : calendar_table;
+       // D : rrule_table;
+       snprintf(query, sizeof(query),
+                       "CREATE VIEW IF NOT EXISTS %s AS "
+                       "SELECT A.*, "
+                       "D.range_type, D.until_type, D.until_utime, D.until_datetime, D.count, "
+                       "D.interval, D.bysecond, D.byminute, D.byhour, D.byday, D.bymonthday, "
+                       "D.byyearday, D.byweekno, D.bymonth, D.bysetpos, D.wkst, "
+                       "B.*, C.*"
+                       "FROM %s A "
+                       "LEFT OUTER  JOIN %s B ON A.id = B.event_id "
+                       "JOIN %s C ON A.calendar_id = C.id "
+                       "LEFT OUTER JOIN %s D ON A.id = D.event_id "
+                       "WHERE A.type = 1 AND c.deleted = 0 AND A.is_deleted = 0 ",
+                       CAL_VIEW_TABLE_EVENT_CALENDAR_ATTENDEE,
+                       CAL_TABLE_SCHEDULE, CAL_TABLE_ATTENDEE, CAL_TABLE_CALENDAR,
+                       CAL_TABLE_RRULE );
+       dbret = _cal_db_util_query_exec(query);
+       //SEC_DBG("%s",query);
+       if (dbret != CAL_DB_OK)
+       {
+               ERR("create view fail");
+       }
+       _cal_db_util_end_trans(true);
+       return ;
+}
+
+int _cal_db_open(void)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       ret = _cal_db_util_open();
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("db open fail");
+       }
+       return ret;
+}
+
+int _cal_db_close(void)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       ret = _cal_db_util_close();
+       return ret;
+}
+
+API int calendar_db_get_changes_by_version(const char* view_uri, int calendar_book_id, int calendar_db_version, calendar_list_h* record_list, int *current_calendar_db_version )
+{
+       const char *query_cur_version = "SELECT ver FROM "CAL_TABLE_VERSION;
+       int transaction_ver = 0;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+       int ret = 0;
+       int is_deleted = 0;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_READ),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : read ");
+       retvm_if(NULL == current_calendar_db_version || NULL == view_uri || NULL == record_list,
+                       CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = _cal_db_util_query_get_first_int_result(query_cur_version, NULL, &transaction_ver);
+       retvm_if (CALENDAR_ERROR_NONE != ret, ret, "_cal_db_util_query_get_first_int_result() failed(%d)", ret);
+
+       char buf[64] = {0};
+       if (calendar_book_id > 0) {
+               snprintf(buf, sizeof(buf), "AND calendar_id = %d ", calendar_book_id);
+
+       } else {
+               memset(buf, 0x0, sizeof(buf));
+       }
+
+       int schedule_type = 0;
+       int record_type = 0;
+       if (strcmp(view_uri,_calendar_event._uri) == 0) {
+               schedule_type = CAL_SCH_TYPE_EVENT;
+               record_type = CAL_RECORD_TYPE_EVENT;
+
+       } else if (strcmp(view_uri,_calendar_todo._uri) == 0) {
+               schedule_type = CAL_SCH_TYPE_TODO;
+               record_type = CAL_RECORD_TYPE_TODO;
+
+       } else {
+               ERR("Invalid parameter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       snprintf(query, sizeof(query),
+                       "SELECT id, changed_ver, created_ver, is_deleted, calendar_id FROM %s "
+                       "WHERE changed_ver > %d AND changed_ver <= %d AND type = %d AND original_event_id < 0 %s "
+                       "UNION "
+                       "SELECT schedule_id, deleted_ver, created_ver, 1, calendar_id FROM %s "
+                       "WHERE deleted_ver > %d AND schedule_type = %d AND original_event_id < 0 %s ",
+                       CAL_TABLE_SCHEDULE,
+                       calendar_db_version, transaction_ver, schedule_type, buf,
+                       CAL_TABLE_DELETED,
+                       calendar_db_version, record_type, buf);
+       SEC_DBG("query[%s]", query);
+
+       ret = calendar_list_create(record_list);
+       retvm_if (ret != CALENDAR_ERROR_NONE, ret, "calendar_list_create() Failed");
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_list_destroy(*record_list, true);
+               *record_list = NULL;
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               int id = 0, calendar_id = 0,type = 0;
+               int ver = 0;
+               int created_ver = 0;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_updated_info._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       ERR("calendar_record_create() failed");
+                       calendar_list_destroy(*record_list, true);
+                       *record_list = NULL;
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+
+               id = sqlite3_column_int(stmt, 0);
+               ver = sqlite3_column_int(stmt, 1);
+               created_ver = sqlite3_column_int(stmt, 2);
+               is_deleted = sqlite3_column_int(stmt, 3);
+               if (is_deleted == 1)
+               {
+                       type = CALENDAR_RECORD_MODIFIED_STATUS_DELETED;
+               }
+               else if (created_ver != ver)
+               {
+                       type = CALENDAR_RECORD_MODIFIED_STATUS_UPDATED;
+               }
+               else
+               {
+                       type = CALENDAR_RECORD_MODIFIED_STATUS_INSERTED;
+               }
+
+               calendar_id = sqlite3_column_int(stmt, 4);
+
+               if (type == CALENDAR_RECORD_MODIFIED_STATUS_DELETED && created_ver > calendar_db_version)
+               {
+                       calendar_record_destroy(record, true);
+                       DBG("type is deleted, created_ver(%d) > calendar_db_ver(%d), so skip", created_ver, calendar_db_version);
+                       continue;
+               }
+
+               _cal_record_set_int(record,_calendar_updated_info.id,id);
+               _cal_record_set_int(record,_calendar_updated_info.calendar_book_id,calendar_id);
+               _cal_record_set_int(record,_calendar_updated_info.modified_status,type);
+               _cal_record_set_int(record,_calendar_updated_info.version,ver);
+
+               ret = calendar_list_add(*record_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*record_list, true);
+                       *record_list = NULL;
+                       calendar_record_destroy(record, true);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+       }
+
+       *current_calendar_db_version = transaction_ver;
+       sqlite3_finalize(stmt);
+
+       calendar_list_first(*record_list);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_db_get_current_version(int* current_version)
+{
+       const char *query = "SELECT ver FROM "CAL_TABLE_VERSION;
+       int transaction_ver = 0;
+       int ret;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_READ),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : read ");
+       retvm_if(NULL == current_version, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = _cal_db_util_query_get_first_int_result(query, NULL, &transaction_ver);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() fail(%d)", ret);
+               return ret;
+       }
+       if (current_version) *current_version = transaction_ver;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_db_insert_record( calendar_record_h record, int* id )
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(((cal_record_s *)record)->type);
+       retvm_if(NULL == plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == plugin_cb->insert_record, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = _cal_db_util_begin_trans();
+       retvm_if(CALENDAR_ERROR_NONE != ret,CALENDAR_ERROR_DB_FAILED, "Db failed");
+
+       ret = plugin_cb->insert_record(record, id);
+
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               ret = _cal_db_util_end_trans(true);
+       }
+       else
+       {
+               _cal_db_util_end_trans(false);
+       }
+
+       return ret;
+}
+
+int _cal_db_get_record( const char* view_uri, int id, calendar_record_h* out_record )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+
+       retvm_if(NULL == view_uri, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       type = _cal_view_get_type(view_uri);
+
+       cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(type);
+       retvm_if(NULL == plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == plugin_cb->get_record, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = plugin_cb->get_record(id, out_record);
+
+       return ret;
+}
+
+API int calendar_db_get_record( const char* view_uri, int id, calendar_record_h* out_record )
+{
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_READ),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : read ");
+
+       return _cal_db_get_record(view_uri, id, out_record);
+}
+
+API int calendar_db_update_record( calendar_record_h record )
+{
+       cal_record_s *temp=NULL ;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       temp = (cal_record_s*)(record);
+
+       cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(temp->type);
+       retvm_if(NULL == plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == plugin_cb->update_record, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = _cal_db_util_begin_trans();
+       retvm_if( CALENDAR_ERROR_NONE != ret,CALENDAR_ERROR_DB_FAILED, "Db failed" );
+
+       ret = plugin_cb->update_record(record);
+
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               ret = _cal_db_util_end_trans(true);
+       }
+       else
+       {
+               _cal_db_util_end_trans(false);
+       }
+
+       return ret;
+}
+
+API int calendar_db_delete_record( const char* view_uri, int id )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == view_uri, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       type = _cal_view_get_type(view_uri);
+
+       cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(type);
+       retvm_if(NULL == plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == plugin_cb->delete_record, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = _cal_db_util_begin_trans();
+       retvm_if( CALENDAR_ERROR_NONE != ret,CALENDAR_ERROR_DB_FAILED, "Db failed" );
+
+       ret = plugin_cb->delete_record(id);
+
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               ret = _cal_db_util_end_trans(true);
+       }
+       else
+       {
+               _cal_db_util_end_trans(false);
+       }
+
+       return ret;
+}
+
+API int calendar_db_get_all_records( const char* view_uri, int offset, int limit, calendar_list_h* out_list )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+       calendar_list_h list = NULL;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_READ),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : read ");
+       retvm_if(NULL == view_uri, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       type = _cal_view_get_type(view_uri);
+
+       cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(type);
+       retvm_if(NULL == plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == plugin_cb->get_all_records, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = plugin_cb->get_all_records(offset,limit, &list);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("get_all_records() failed");
+               return ret;
+       }
+       calendar_list_first(list);
+       if (out_list) *out_list = list;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_db_get_records_with_query( calendar_query_h query, int offset, int limit, calendar_list_h* out_list )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+       cal_query_s *que = NULL;
+       calendar_list_h list = NULL;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_READ),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : read ");
+       retvm_if(NULL == query, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       que = (cal_query_s *)query;
+
+       type = _cal_view_get_type(que->view_uri);
+
+       cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(type);
+       retvm_if(NULL == plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == plugin_cb->get_records_with_query, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = plugin_cb->get_records_with_query(query,offset,limit, &list);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("get_records_with_query() failed");
+               return ret;
+       }
+       calendar_list_first(list);
+       if (out_list) *out_list = list;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_db_clean_after_sync( int calendar_book_id,  int calendar_db_version )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MIN_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int len = 0;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(calendar_book_id < 0, CALENDAR_ERROR_INVALID_PARAMETER, "calendar_id(%d) is Invalid", calendar_book_id);
+
+       ret = _cal_db_util_begin_trans();
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_begin_trans() failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       // !! please check rrule_table, alarm_table, attendee_table ..
+
+       ret =  _cal_is_owner(calendar_book_id);
+       if (CALENDAR_ERROR_NONE != ret) {
+               if (CALENDAR_ERROR_PERMISSION_DENIED == ret)
+                       ERR("Does not have permission of calendar_book (%d)", calendar_book_id);
+               else
+                       ERR("_cal_is_owner Fail(%d)", ret);
+               _cal_db_util_end_trans(false);
+               return ret;
+       }
+
+       /* delete event table */
+       len = snprintf(query, sizeof(query), "DELETE FROM %s "
+                       "WHERE is_deleted = 1 AND calendar_id = %d",
+                       CAL_TABLE_SCHEDULE,
+                       calendar_book_id);
+       if (calendar_db_version > 0)
+       {
+               len = snprintf(query+len, sizeof(query)-len, " AND changed_ver <= %d", calendar_db_version);
+       }
+
+       dbret = _cal_db_util_query_exec(query);
+       CAL_DBG("%s",query);
+       if (dbret != CAL_DB_OK)
+       {
+               ERR("DB failed");
+               _cal_db_util_end_trans(false);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       retvm_if(ret < 0, ret, "cals_query_exec() failed (%d)", ret);
+
+       /* delete delete table */
+       snprintf(query, sizeof(query), "DELETE FROM %s "
+                       "WHERE calendar_id = %d",
+                       CAL_TABLE_DELETED,
+                       calendar_book_id);
+
+       dbret = _cal_db_util_query_exec(query);
+       CAL_DBG("%s",query);
+       if (dbret != CAL_DB_OK)
+       {
+               ERR("DB failed");
+               _cal_db_util_end_trans(false);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       _cal_db_util_end_trans(true);
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_db_get_count( const char* view_uri, int *out_count )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_READ),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : read ");
+       retvm_if(NULL == view_uri, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       type = _cal_view_get_type(view_uri);
+
+       cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(type);
+       retvm_if(NULL == plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == plugin_cb->get_count, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = plugin_cb->get_count(out_count);
+       return ret;
+}
+
+API int calendar_db_get_count_with_query( calendar_query_h query, int *out_count )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+       cal_query_s *que = NULL;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_READ),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : read ");
+       retvm_if(NULL == query, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       que = (cal_query_s *)query;
+
+       type = _cal_view_get_type(que->view_uri);
+
+       cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(type);
+       retvm_if(NULL == plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == plugin_cb->get_count_with_query, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = plugin_cb->get_count_with_query(query, out_count);
+       return ret;
+}
+
+API int calendar_db_insert_records(calendar_list_h list, int** ids, int* count)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       int i;
+       int *_ids = NULL;
+       int _count = 0;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == list, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = _cal_db_util_begin_trans();
+       if ( ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("Db failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       _count = 0;
+       calendar_list_get_count(list, &_count);
+       DBG("list count(%d)", _count);
+
+       _ids = calloc(_count, sizeof(int));
+
+       // divide count for accessing of another modules.
+       int div = (int)(_count / BULK_DEFAULT_COUNT) + 1;
+       int bulk = _count / div + 1;
+
+       calendar_list_first(list);
+       for (i = 0; i < _count; i++)
+       {
+               calendar_record_h record = NULL;
+               ret = calendar_list_get_current_record_p(list, &record);
+               if (record == NULL|| ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("No record in the list");
+                       _cal_db_util_end_trans(false);
+                       CAL_FREE(_ids);
+                       return ret;
+               }
+
+               cal_record_s *temp = (cal_record_s *)record;
+               cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(temp->type);
+               if (NULL == plugin_cb || NULL == plugin_cb->insert_record)
+               {
+                       DBG("Not plugin");
+                       _cal_db_util_end_trans(false);
+                       CAL_FREE(_ids);
+                       return CALENDAR_ERROR_NOT_PERMITTED;
+               }
+               ret = plugin_cb->insert_record(record, &_ids[i]);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       DBG("Failed to insert record");
+                       _cal_db_util_end_trans(false);
+                       CAL_FREE(_ids);
+                       return ret;
+               }
+               DBG("insert with id(%d)", _ids[i]);
+               calendar_list_next(list);
+
+               if (i > bulk)
+               {
+                       bulk += (_count / div + 1);
+                       _cal_db_util_end_trans(true);
+                       sleep(1);
+                       ret = _cal_db_util_begin_trans();
+                       if ( ret != CALENDAR_ERROR_NONE)
+                       {
+                               calendar_list_destroy(list, true);
+                               CAL_FREE(_ids);
+                               ERR("Db failed");
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+       }
+
+       if (ids)
+       {
+               *ids = _ids;
+       }
+       else
+       {
+               CAL_FREE(_ids);
+       }
+       if (count) *count = _count;
+       _cal_db_util_end_trans(true);
+
+       return ret;
+}
+
+API int calendar_db_insert_records_async(calendar_list_h list, calendar_db_insert_result_cb callback, void *user_data)
+{
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+#ifdef CAL_NATIVE
+       if (callback != NULL)
+       {
+               int ret = CALENDAR_ERROR_NONE;
+               calendar_list_h out_list = NULL;
+
+               ret = _cal_list_clone(list, &out_list);
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+
+               __insert_records_data_s *callback_data = NULL;
+               callback_data = calloc(1,sizeof(__insert_records_data_s));
+
+               if (callback_data == NULL)
+               {
+                       ERR("calloc fail");
+                       calendar_list_destroy(out_list, true);
+                       return CALENDAR_ERROR_OUT_OF_MEMORY;
+               }
+               callback_data->list = out_list;
+               callback_data->callback = callback;
+               callback_data->user_data = user_data;
+               g_idle_add( &__cal_db_insert_records_idle, callback_data);
+               return CALENDAR_ERROR_NONE;
+       }
+#endif
+       int ret = CALENDAR_ERROR_NONE;
+       int i;
+       int *ids = NULL;
+       int count = 0;
+
+       ret = _cal_db_util_begin_trans();
+       if ( ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("Db failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       calendar_list_get_count(list, &count);
+       DBG("list count(%d)", count);
+
+       ids = calloc(count, sizeof(int));
+
+       calendar_list_first(list);
+       for (i = 0; i < count; i++)
+       {
+               calendar_record_h record = NULL;
+               ret = calendar_list_get_current_record_p(list, &record);
+               if (record == NULL || ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("No record in the list");
+                       CAL_FREE(ids);
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+
+               cal_record_s *temp = (cal_record_s *)record;
+               cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(temp->type);
+               if (NULL == plugin_cb || NULL == plugin_cb->insert_record)
+               {
+                       DBG("Not plugin");
+                       CAL_FREE(ids);
+                       _cal_db_util_end_trans(false);
+                       return CALENDAR_ERROR_NOT_PERMITTED;
+               }
+               ret = plugin_cb->insert_record(record, &ids[i]);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       DBG("Failed to insert record");
+                       CAL_FREE(ids);
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+               DBG("insert with id(%d)", ids[i]);
+               calendar_list_next(list);
+       }
+       CAL_FREE(ids);
+       _cal_db_util_end_trans(true);
+
+       return ret;
+}
+
+API int calendar_db_update_records( calendar_list_h list)
+{
+       int i;
+       int count = 0;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = _cal_db_util_begin_trans();
+       if ( ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("Db failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       calendar_list_get_count(list, &count);
+       DBG("update list count(%d", count);
+
+       // divide count for accessing of another modules.
+       int div = (int)(count / BULK_DEFAULT_COUNT) + 1;
+       int bulk = count / div + 1;
+
+       calendar_list_first(list);
+       for (i = 0; i < count; i++)
+       {
+               calendar_record_h record = NULL;
+               ret = calendar_list_get_current_record_p(list, &record);
+               if (record == NULL || ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("No record in the list");
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+
+               cal_record_s *temp = (cal_record_s *)record;
+               cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(temp->type);
+               if (NULL == plugin_cb || NULL == plugin_cb->update_record)
+               {
+                       ERR("Not plugin");
+                       _cal_db_util_end_trans(false);
+                       ret = CALENDAR_ERROR_NOT_PERMITTED;
+                       return ret;
+               }
+               ret = plugin_cb->update_record(record);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("Failed to update record");
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+               DBG("update record");
+               calendar_list_next(list);
+
+               if (i > bulk)
+               {
+                       bulk += (count / div + 1);
+                       _cal_db_util_end_trans(true);
+                       sleep(1);
+                       ret = _cal_db_util_begin_trans();
+                       if ( ret != CALENDAR_ERROR_NONE)
+                       {
+                               calendar_list_destroy(list, true);
+                               ERR("Db failed");
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+       }
+       _cal_db_util_end_trans(true);
+
+       return ret;
+}
+
+API int calendar_db_update_records_async( calendar_list_h list, calendar_db_result_cb callback, void *user_data)
+{
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+
+#ifdef CAL_NATIVE
+       if (callback != NULL)
+       {
+               int ret = CALENDAR_ERROR_NONE;
+               calendar_list_h out_list = NULL;
+               ret = _cal_list_clone(list, &out_list);
+               retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+
+               __update_records_data_s *callback_data = NULL;
+               callback_data = calloc(1,sizeof(__update_records_data_s));
+
+               if (callback_data == NULL)
+               {
+                       ERR("calloc fail");
+                       calendar_list_destroy(out_list, true);
+                       return CALENDAR_ERROR_OUT_OF_MEMORY;
+               }
+               callback_data->list = out_list;
+               callback_data->callback = callback;
+               callback_data->user_data = user_data;
+               g_idle_add( &__cal_db_update_records_idle, callback_data);
+               return CALENDAR_ERROR_NONE;
+       }
+#endif
+       int i;
+       int count = 0;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retvm_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = _cal_db_util_begin_trans();
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("Db failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       calendar_list_get_count(list, &count);
+       DBG("update list count(%d", count);
+
+       calendar_list_first(list);
+       for (i = 0; i < count; i++)
+       {
+               calendar_record_h record = NULL;
+               ret = calendar_list_get_current_record_p(list, &record);
+               if (record == NULL || ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("No record in the list");
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+
+               cal_record_s *temp = (cal_record_s *)record;
+               cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(temp->type);
+               if (NULL == plugin_cb || NULL == plugin_cb->insert_record)
+               {
+                       ERR("Not plugin");
+                       _cal_db_util_end_trans(false);
+                       ret = CALENDAR_ERROR_NOT_PERMITTED;
+                       return ret;
+               }
+               ret = plugin_cb->update_record(record);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("Failed to update record");
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+               DBG("update record");
+               calendar_list_next(list);
+       }
+       _cal_db_util_end_trans(true);
+
+       return ret;
+}
+
+API int calendar_db_delete_records(const char* view_uri, int record_id_array[], int count)
+{
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == view_uri, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == record_id_array, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(count <= 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       int ret = CALENDAR_ERROR_NONE;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+
+       type = _cal_view_get_type(view_uri);
+
+       cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(type);
+       retvm_if(NULL == plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == plugin_cb->delete_records, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = _cal_db_util_begin_trans();
+       retvm_if( CALENDAR_ERROR_NONE != ret,CALENDAR_ERROR_DB_FAILED, "Db failed" );
+
+       ret = plugin_cb->delete_records(record_id_array,count);
+
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               ret = _cal_db_util_end_trans(true);
+       }
+       else
+       {
+               _cal_db_util_end_trans(false);
+       }
+       return ret;
+}
+
+API int calendar_db_delete_records_async(const char* view_uri, int ids[], int count, calendar_db_result_cb callback, void *user_data)
+{
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == view_uri, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == ids, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(count <= 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+#ifdef CAL_NATIVE
+       if (callback != NULL)
+       {
+               __delete_records_data_s *callback_data = NULL;
+               callback_data = calloc(1,sizeof(__delete_records_data_s));
+
+               if (callback_data == NULL)
+               {
+                       ERR("calloc fail");
+                       return CALENDAR_ERROR_OUT_OF_MEMORY;
+               }
+               callback_data->view_uri = view_uri;
+               callback_data->ids = calloc(1, sizeof(int)*count);
+               if (callback_data->ids == NULL)
+               {
+                       CAL_FREE(callback_data);
+                       ERR("calloc fail");
+                       return CALENDAR_ERROR_OUT_OF_MEMORY;
+               }
+               memcpy(callback_data->ids, ids, sizeof(int)*count);
+               callback_data->count = count;
+               callback_data->callback = callback;
+               callback_data->user_data = user_data;
+               g_idle_add( &__cal_db_delete_records_idle, callback_data);
+               return CALENDAR_ERROR_NONE;
+       }
+#endif
+       int ret = CALENDAR_ERROR_NONE;
+       cal_record_type_e type = CAL_RECORD_TYPE_INVALID;
+
+       type = _cal_view_get_type(view_uri);
+
+       cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(type);
+       retvm_if(NULL == plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == plugin_cb->delete_records, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = _cal_db_util_begin_trans();
+       retvm_if( CALENDAR_ERROR_NONE != ret,CALENDAR_ERROR_DB_FAILED, "Db failed" );
+
+       ret = plugin_cb->delete_records(ids,count);
+
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               ret = _cal_db_util_end_trans(true);
+       }
+       else
+       {
+               _cal_db_util_end_trans(false);
+       }
+       return ret;
+}
+
+API int calendar_db_insert_vcalendars(const char* vcalendar_stream, int **record_id_array, int *count)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_list_h list = NULL;
+       int list_count = 0;
+       int i = 0;
+       int *ids = NULL;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == vcalendar_stream, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == record_id_array, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == count, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = calendar_vcalendar_parse_to_calendar(vcalendar_stream, &list);
+       retvm_if(ret != CALENDAR_ERROR_NONE, ret, "parse fail");
+
+       ret = calendar_list_get_count(list, &list_count);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               calendar_list_destroy(list, true);
+               ERR("get count fail");
+               return ret;
+       }
+
+       calendar_list_first(list);
+       ids = calloc(1, sizeof(int)*list_count);
+       if (ids == NULL)
+       {
+               calendar_list_destroy(list, true);
+               ERR("calloc fail");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       ret = _cal_db_util_begin_trans();
+
+       if ( ret != CALENDAR_ERROR_NONE)
+       {
+               calendar_list_destroy(list, true);
+               CAL_FREE(ids);
+               ERR("Db failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       for(i=0;i<list_count;i++)
+       {
+               calendar_record_h record = NULL;
+
+               ret = calendar_list_get_current_record_p(list, &record);
+               if( ret != CALENDAR_ERROR_NONE)
+               {
+                       calendar_list_destroy(list, true);
+                       CAL_FREE(ids);
+                       ERR("list get fail");
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+
+               // insert
+               ret = calendar_db_insert_record(record, &ids[i]);
+               if( ret != CALENDAR_ERROR_NONE)
+               {
+                       calendar_list_destroy(list, true);
+                       CAL_FREE(ids);
+                       ERR("list get fail");
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+
+               calendar_list_next(list);
+       }
+
+       _cal_db_util_end_trans(true);
+
+       *record_id_array = ids;
+       *count = list_count;
+
+       calendar_list_destroy(list, true);
+       return ret;
+}
+
+API int calendar_db_insert_vcalendars_async(const char* vcalendar_stream, calendar_db_insert_result_cb callback, void *user_data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == vcalendar_stream, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == callback, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+#ifdef CAL_NATIVE
+
+       __insert_vcalendars_data_s *callback_data = NULL;
+       callback_data = calloc(1,sizeof(__insert_vcalendars_data_s));
+
+       if (callback_data == NULL)
+       {
+               ERR("calloc fail");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       callback_data->vcalendar_stream = SAFE_STRDUP(vcalendar_stream);
+       callback_data->callback = callback;
+       callback_data->user_data = user_data;
+       g_idle_add( &__cal_db_insert_vcalendars_idle, callback_data);
+
+#endif
+       return ret;
+}
+
+API int calendar_db_replace_vcalendars(const char* vcalendar_stream, int *record_id_array, int count)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_list_h list = NULL;
+       int list_count = 0;
+       int i = 0;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == vcalendar_stream, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == record_id_array, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(count <= 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = calendar_vcalendar_parse_to_calendar(vcalendar_stream, &list);
+       retvm_if(ret != CALENDAR_ERROR_NONE, ret, "parse fail");
+
+       ret = calendar_list_get_count(list, &list_count);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               calendar_list_destroy(list, true);
+               ERR("get count fail");
+               return ret;
+       }
+
+       // check count
+       if (count != list_count)
+       {
+               calendar_list_destroy(list, true);
+               ERR("get count fail vcalendar_count=%d, input count=%d", list_count, count);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       calendar_list_first(list);
+
+       ret = _cal_db_util_begin_trans();
+       if ( ret != CALENDAR_ERROR_NONE)
+       {
+               calendar_list_destroy(list, true);
+               ERR("Db failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       // divide count for accessing of another modules.
+       int div = (int)(count / BULK_DEFAULT_COUNT) + 1;
+       int bulk = count / div + 1;
+
+       for(i = 0; i < list_count; i++)
+       {
+               calendar_record_h record = NULL;
+               char *view_uri = NULL;
+
+               ret = calendar_list_get_current_record_p(list, &record);
+               if( ret != CALENDAR_ERROR_NONE)
+               {
+                       calendar_list_destroy(list, true);
+                       ERR("list get fail");
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+
+               // set_id
+               ret = calendar_record_get_uri_p(record, &view_uri);
+               if( ret != CALENDAR_ERROR_NONE)
+               {
+                       calendar_list_destroy(list, true);
+                       ERR("record get uri fail");
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+
+               if(strcmp(view_uri, _calendar_event._uri) == 0)
+               {
+                       ret = _cal_record_set_int(record, _calendar_event.id, record_id_array[i]);
+               }
+               else if(strcmp(view_uri, _calendar_todo._uri) == 0)
+               {
+                       ret = _cal_record_set_int(record, _calendar_todo.id, record_id_array[i]);
+               }
+               else
+               {
+                       DBG("this uri[%s] is not replacable.", view_uri);
+                       calendar_list_next(list);
+                       continue;
+               }
+
+               if( ret != CALENDAR_ERROR_NONE)
+               {
+                       calendar_list_destroy(list, true);
+                       ERR("record set fail");
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+
+               // update
+               ret = calendar_db_update_record(record);
+               if( ret != CALENDAR_ERROR_NONE)
+               {
+                       calendar_list_destroy(list, true);
+                       ERR("list get fail");
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+               calendar_list_next(list);
+
+               if (i > bulk)
+               {
+                       bulk += (count / div + 1);
+                       _cal_db_util_end_trans(true);
+                       sleep(1);
+                       ret = _cal_db_util_begin_trans();
+                       if ( ret != CALENDAR_ERROR_NONE)
+                       {
+                               calendar_list_destroy(list, true);
+                               ERR("Db failed");
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+       }
+
+       _cal_db_util_end_trans(true);
+
+       calendar_list_destroy(list, true);
+
+       return ret;
+}
+
+API int calendar_db_replace_vcalendars_async(const char* vcalendar_stream, int *record_id_array, int count, calendar_db_result_cb callback, void *user_data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == vcalendar_stream, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == callback, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == record_id_array, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(count <= 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+#ifdef CAL_NATIVE
+
+       __replace_vcalendars_data_s *callback_data = NULL;
+       callback_data = calloc(1,sizeof(__replace_vcalendars_data_s));
+
+       if (callback_data == NULL)
+       {
+               ERR("calloc fail");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       callback_data->ids = calloc(1, sizeof(int)*count);
+       if (callback_data->ids == NULL)
+       {
+               CAL_FREE(callback_data);
+               ERR("calloc fail");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       memcpy(callback_data->ids, record_id_array, sizeof(int)*count);
+       callback_data->vcalendar_stream = SAFE_STRDUP(vcalendar_stream);
+       callback_data->callback = callback;
+       callback_data->user_data = user_data;
+       callback_data->count = count;
+       g_idle_add( &__cal_db_replace_vcalendars_idle, callback_data);
+
+#endif
+       return ret;
+}
+
+API int calendar_db_replace_record(calendar_record_h record, int record_id)
+{
+       cal_record_s *temp=NULL ;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(record_id < 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       temp = (cal_record_s*)(record);
+
+       cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(temp->type);
+       retvm_if(NULL == plugin_cb, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == plugin_cb->replace_record, CALENDAR_ERROR_NOT_PERMITTED, "Not permitted");
+
+       ret = _cal_db_util_begin_trans();
+       retvm_if( CALENDAR_ERROR_NONE != ret,CALENDAR_ERROR_DB_FAILED, "Db failed" );
+
+       ret = plugin_cb->replace_record(record, record_id);
+
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               ret = _cal_db_util_end_trans(true);
+       }
+       else
+       {
+               _cal_db_util_end_trans(false);
+       }
+
+       return ret;
+}
+
+API int calendar_db_replace_records(calendar_list_h list, int *ids, int count)
+{
+       int i;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == ids, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(count <= 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = _cal_db_util_begin_trans();
+       if ( ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("Db failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       calendar_list_first(list);
+       for (i = 0; i < count; i++)
+       {
+               calendar_record_h record = NULL;
+               ret = calendar_list_get_current_record_p(list, &record);
+               if (record == NULL || ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("No record in the list");
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+
+               cal_record_s *temp = (cal_record_s *)record;
+               cal_db_plugin_cb_s* plugin_cb = __cal_db_get_plugin(temp->type);
+               if (NULL == plugin_cb || NULL == plugin_cb->insert_record)
+               {
+                       DBG("Not plugin");
+                       _cal_db_util_end_trans(false);
+                       ret = CALENDAR_ERROR_NOT_PERMITTED;
+                       return ret;
+               }
+               ret = plugin_cb->replace_record(record, ids[i]);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       DBG("Failed to replace record");
+                       _cal_db_util_end_trans(false);
+                       return ret;
+               }
+               DBG("insert with id(%d)", ids[i]);
+               calendar_list_next(list);
+       }
+       _cal_db_util_end_trans(true);
+       return ret;
+}
+
+API int calendar_db_replace_records_async(calendar_list_h record_list, int *record_id_array, int count, calendar_db_result_cb callback, void *user_data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_WRITE),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : write ");
+       retvm_if(NULL == record_list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == callback, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(NULL == record_id_array, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       retvm_if(count <= 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+#ifdef CAL_NATIVE
+
+       calendar_list_h out_list = NULL;
+
+       ret = _cal_list_clone(record_list, &out_list);
+       retv_if(ret!=CALENDAR_ERROR_NONE,ret);
+
+       __replace_records_data_s *callback_data = NULL;
+       callback_data = calloc(1,sizeof(__replace_records_data_s));
+       if (callback_data == NULL)
+       {
+               ERR("calloc fail");
+               calendar_list_destroy(out_list, true);
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       callback_data->ids = calloc(1, sizeof(int)*count);
+       if (callback_data->ids == NULL)
+       {
+               CAL_FREE(callback_data);
+               ERR("calloc fail");
+               calendar_list_destroy(out_list, true);
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       memcpy(callback_data->ids, record_id_array, sizeof(int)*count);
+       callback_data->list = out_list;
+       callback_data->callback = callback;
+       callback_data->user_data = user_data;
+       callback_data->count = count;
+       g_idle_add( &__cal_db_replace_records_idle, callback_data);
+
+#endif
+       return ret;
+}
+
+API int calendar_db_get_last_change_version(int* last_version)
+{
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_READ),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : read ");
+       retvm_if(NULL == last_version, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+       *last_version = _cal_db_util_get_transaction_ver();
+       return CALENDAR_ERROR_NONE;
+}
+
+API int calendar_db_get_changes_exception_by_version(const char* view_uri, int original_event_id, int calendar_db_version, calendar_list_h* record_list)
+{
+       const char *query_cur_version = "SELECT ver FROM "CAL_TABLE_VERSION;
+       int transaction_ver = 0;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+       int ret = 0;
+       int is_deleted = 0;
+
+       retvm_if(!_cal_access_control_have_permission(CAL_PERMISSION_READ),
+                       CALENDAR_ERROR_PERMISSION_DENIED, "Permission denied : read ");
+       retvm_if(NULL == view_uri || NULL == record_list || original_event_id <= 0,
+                       CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = _cal_db_util_query_get_first_int_result(query_cur_version, NULL, &transaction_ver);
+       retvm_if (CALENDAR_ERROR_NONE != ret, ret, "_cal_db_util_query_get_first_int_result() failed");
+
+       int schedule_type = 0;
+       int record_type = 0;
+       if (strcmp(view_uri,_calendar_event._uri) == 0) {
+               schedule_type = CAL_SCH_TYPE_EVENT;
+               record_type = CAL_RECORD_TYPE_EVENT;
+
+       } else {
+               ERR("Invalid parameter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       snprintf(query, sizeof(query),
+                       "SELECT id, changed_ver, created_ver, is_deleted, calendar_id FROM %s "
+                       "WHERE changed_ver > %d AND changed_ver <= %d AND type = %d AND original_event_id = %d "
+                       "UNION "
+                       "SELECT schedule_id, deleted_ver, created_ver, 1, calendar_id FROM %s "
+                       "WHERE deleted_ver > %d AND schedule_type = %d AND original_event_id = %d ",
+                       CAL_TABLE_SCHEDULE,
+                       calendar_db_version, transaction_ver, schedule_type, original_event_id,
+                       CAL_TABLE_DELETED,
+                       calendar_db_version, record_type, original_event_id);
+       SEC_DBG("query[%s]", query);
+
+       ret = calendar_list_create(record_list);
+       retvm_if (ret != CALENDAR_ERROR_NONE, ret, "calendar_list_create() Failed");
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_list_destroy(*record_list, true);
+               *record_list = NULL;
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               int id = 0, calendar_id = 0,type = 0;
+               int ver = 0;
+               int created_ver = 0;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_updated_info._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       ERR("calendar_record_create() failed");
+                       calendar_list_destroy(*record_list, true);
+                       *record_list = NULL;
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+
+               id = sqlite3_column_int(stmt, 0);
+               ver = sqlite3_column_int(stmt, 1);
+               created_ver = sqlite3_column_int(stmt, 2);
+               is_deleted = sqlite3_column_int(stmt, 3);
+               if (is_deleted == 1)
+               {
+                       type = CALENDAR_RECORD_MODIFIED_STATUS_DELETED;
+               }
+               else if (created_ver != ver)
+               {
+                       type = CALENDAR_RECORD_MODIFIED_STATUS_UPDATED;
+               }
+               else
+               {
+                       type = CALENDAR_RECORD_MODIFIED_STATUS_INSERTED;
+               }
+
+               calendar_id = sqlite3_column_int(stmt, 4);
+#if 0
+               if (type == CALENDAR_RECORD_MODIFIED_STATUS_DELETED && created_ver > calendar_db_version)
+               {
+                       calendar_record_destroy(record, true);
+                       continue;
+               }
+#endif
+
+               _cal_record_set_int(record,_calendar_updated_info.id,id);
+               _cal_record_set_int(record,_calendar_updated_info.calendar_book_id,calendar_id);
+               _cal_record_set_int(record,_calendar_updated_info.modified_status,type);
+               _cal_record_set_int(record,_calendar_updated_info.version,ver);
+
+               ret = calendar_list_add(*record_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*record_list, true);
+                       *record_list = NULL;
+                       calendar_record_destroy(record, true);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+       }
+
+       //*current_calendar_db_version = transaction_ver;
+       sqlite3_finalize(stmt);
+
+       calendar_list_first(*record_list);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_append_string(char **dst, char *src)
+{
+       retv_if(NULL == dst, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(NULL == src, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       int len_src = strlen(src);
+       if (len_src == 0) {
+               DBG("src len is 0");
+               return CALENDAR_ERROR_NONE;
+       }
+
+       if (NULL == *dst) {
+               *dst = strdup(src);
+               if (*dst == NULL)
+               {
+                       ERR("strdup fail");
+                       return CALENDAR_ERROR_OUT_OF_MEMORY;
+               }
+               return CALENDAR_ERROR_NONE;
+       }
+
+       int len_dst = strlen(*dst);
+       *dst = (char *)realloc(*dst, len_dst + len_src + 2);
+       if (*dst == NULL) {
+               ERR("strdup fail");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+       snprintf(*dst +len_dst, len_src +2, " %s", src);
+       return CALENDAR_ERROR_NONE;
+}
+
diff --git a/native/cal_db.h b/native/cal_db.h
new file mode 100644 (file)
index 0000000..cebfae7
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __CALENDAR_SVC_DB_H__
+#define __CALENDAR_SVC_DB_H__
+
+#include "calendar_view.h"
+#include "calendar_list.h"
+
+#define CAL_DB_PATH "/opt/usr/dbspace/.calendar-svc.db"
+#define CAL_DB_JOURNAL_PATH "/opt/usr/dbspace/.calendar-svc.db-journal"
+
+// For Security
+#define CAL_SECURITY_FILE_GROUP 5000
+#define CAL_SECURITY_DEFAULT_PERMISSION 0660
+#define CAL_SECURITY_DIR_DEFAULT_PERMISSION 0770
+
+#define CAL_DB_SQL_MAX_LEN 2048
+#define CAL_DB_SQL_MIN_LEN 1024
+#define _BUFFER_ORDER 128
+
+// DB table
+#define CAL_TABLE_SCHEDULE "schedule_table"
+#define CAL_TABLE_ALARM "alarm_table"
+#define CAL_TABLE_CALENDAR "calendar_table"
+#define CAL_TABLE_ATTENDEE "attendee_table"
+#define CAL_TABLE_TIMEZONE "timezone_table"
+#define CAL_TABLE_VERSION "version_table"
+#define CAL_TABLE_DELETED "deleted_table"
+#define CAL_TABLE_RRULE "rrule_table"
+#define CAL_TABLE_NORMAL_INSTANCE "normal_instance_table"
+#define CAL_TABLE_ALLDAY_INSTANCE "allday_instance_table"
+#define CAL_TABLE_EXTENDED "extended_table"
+
+// for event or todo..
+#define CAL_VIEW_TABLE_EVENT "event_view"
+#define CAL_VIEW_TABLE_TODO "todo_view"
+// search ?
+#define CAL_VIEW_TABLE_EVENT_CALENDAR "event_calendar_view"
+#define CAL_VIEW_TABLE_TODO_CALENDAR "todo_calendar_view"
+#define CAL_VIEW_TABLE_EVENT_CALENDAR_ATTENDEE "event_calendar_attendee_view"
+#define CAL_VIEW_TABLE_NORMAL_INSTANCE "normal_instance_view"
+#define CAL_VIEW_TABLE_ALLDAY_INSTANCE "allday_instance_view"
+#define CAL_VIEW_TABLE_NORMAL_INSTANCE_EXTENDED "normal_instance_view_extended"
+#define CAL_VIEW_TABLE_ALLDAY_INSTANCE_EXTENDED "allday_instance_view_extended"
+
+typedef int (*cal_db_insert_record_cb)( calendar_record_h record, int* id );
+typedef int (*cal_db_get_record_cb)( int id, calendar_record_h* out_record );
+typedef int (*cal_db_update_record_cb)( calendar_record_h record );
+typedef int (*cal_db_delete_record_cb)( int id );
+typedef int (*cal_db_get_all_records_cb)( int offset, int limit, calendar_list_h* out_list );
+typedef int (*cal_db_get_records_with_query_cb)( calendar_query_h query, int offset, int limit, calendar_list_h* out_list );
+typedef int (*cal_db_insert_records_cb)(const calendar_list_h in_list, int** ids);
+typedef int (*cal_db_update_records_cb)(const calendar_list_h in_list);
+typedef int (*cal_db_delete_records_cb)(int ids[], int count);
+typedef int (*cal_db_get_count_cb)( int *out_count );
+typedef int (*cal_db_get_count_with_query_cb)( calendar_query_h query, int *out_count );
+typedef int (*cal_db_replace_record)(calendar_record_h record, int record_id);
+typedef int (*cal_db_replace_records)(calendar_list_h record_list, int *record_id_array, int count);
+
+typedef struct {
+       bool is_query_only;
+       cal_db_insert_record_cb insert_record;
+       cal_db_get_record_cb get_record;
+       cal_db_update_record_cb update_record;
+       cal_db_delete_record_cb delete_record;
+       cal_db_get_all_records_cb get_all_records;
+       cal_db_get_records_with_query_cb get_records_with_query;
+       cal_db_insert_records_cb insert_records;
+       cal_db_update_records_cb update_records;
+       cal_db_delete_records_cb delete_records;
+       cal_db_get_count_cb get_count;
+       cal_db_get_count_with_query_cb get_count_with_query;
+       cal_db_replace_record replace_record;
+       cal_db_replace_records replace_records;
+} cal_db_plugin_cb_s;
+
+int _cal_db_open(void);
+int _cal_db_close(void);
+
+int _cal_db_get_record( const char* view_uri, int record_id, calendar_record_h* record );
+int _cal_db_append_string(char **dst, char *src);
+void _cal_db_initialize_view_table(void);
+
+#endif // __CALENDAR_SVC_DB_H__
diff --git a/native/cal_db_alarm.c b/native/cal_db_alarm.c
new file mode 100644 (file)
index 0000000..8f43d77
--- /dev/null
@@ -0,0 +1,292 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#ifdef CAL_NATIVE
+#include <alarm.h>
+#endif
+
+#include "calendar_db.h"
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_time.h"
+#include "cal_record.h"
+#include "cal_list.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_db_query.h"
+#include "cal_db_instance.h"
+#include "cal_db_alarm.h"
+
+static int __cal_db_alarm_insert_record(calendar_record_h record, int parent_id)
+{
+       cal_alarm_s *alarm = NULL;
+
+       alarm = (cal_alarm_s *)(record);
+       retvm_if(NULL == alarm, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid argument: cal_alarm_s is NULL");
+
+       if (alarm->remind_tick_unit == CALENDAR_ALARM_NONE) {
+               DBG("No alarm unit tick");
+               return CALENDAR_ERROR_NONE;
+       }
+
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       snprintf(query, sizeof(query),
+                       "INSERT INTO %s ("
+                       "event_id, "
+                       "remind_tick, remind_tick_unit, "
+                       "alarm_description, "
+                       "alarm_type,  "
+                       "alarm_summary, alarm_action, alarm_attach, "
+                       "alarm_utime, alarm_datetime "
+                       ") VALUES ( "
+                       "%d, "
+                       "%d, %d, "
+                       "?, "
+                       "%d, "
+                       "?, %d, ?, "
+                       "%lld, ?)",
+                       CAL_TABLE_ALARM,
+                       parent_id,
+                       alarm->remind_tick, alarm->remind_tick_unit,
+                       alarm->alarm.type,
+                       alarm->alarm_action,
+                       alarm->alarm.time.utime);
+
+       SEC_DBG("%s",query);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt) {
+               DBG("_cal_db_util_query_prepare() Failed");
+               DBG("query[%s]", query);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       int index = 1;
+
+       if (alarm->alarm_description) {
+               _cal_db_util_stmt_bind_text(stmt, index, alarm->alarm_description);
+               DBG("description[ %s ]", alarm->alarm_description);
+       }
+       index++;
+
+       if (alarm->alarm_summary) {
+               _cal_db_util_stmt_bind_text(stmt, index, alarm->alarm_summary);
+               DBG("summary [ %s ]", alarm->alarm_summary);
+       }
+       index++;
+
+       if (alarm->alarm_attach)
+               _cal_db_util_stmt_bind_text(stmt, index, alarm->alarm_attach);
+       index++;
+
+       if (CALENDAR_TIME_LOCALTIME == alarm->alarm.type) {
+               char alarm_datetime[32] = {0};
+               snprintf(alarm_datetime, sizeof(alarm_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               alarm->alarm.time.date.year,
+                               alarm->alarm.time.date.month,
+                               alarm->alarm.time.date.mday,
+                               alarm->alarm.time.date.hour,
+                               alarm->alarm.time.date.minute,
+                               alarm->alarm.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, index, alarm_datetime);
+               DBG("datetime [ %s ]", alarm_datetime);
+       }
+       index++;
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       sqlite3_finalize(stmt);
+
+       if (CAL_DB_DONE != dbret) {
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+               switch (dbret) {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_alarm_insert_records(cal_list_s *list_s, int event_id)
+{
+       int ret;
+       int count = 0;
+       calendar_record_h record = NULL;
+       calendar_list_h list = (calendar_list_h)list_s;
+       retv_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       calendar_list_get_count(list, &count);
+       if (0 == count)
+               return CALENDAR_ERROR_NONE;
+
+       calendar_list_first(list);
+       while (CALENDAR_ERROR_NONE == calendar_list_get_current_record_p(list, &record)) {
+               ret = __cal_db_alarm_insert_record(record, event_id);
+               retvm_if(CALENDAR_ERROR_NONE != ret, ret, "_cal_db_extended_insert_record() Failed(%d)", ret);
+               calendar_list_next(list);
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_alarm_get_records(int parent, cal_list_s *list)
+{
+       int ret;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter: list is NULL");
+
+       snprintf(query, sizeof(query),
+                       "SELECT rowid, "
+                       "remind_tick,"
+                       "remind_tick_unit, "
+                       "alarm_description, "
+                       "alarm_type, "
+                       "alarm_summary, "
+                       "alarm_action, "
+                       "alarm_attach, "
+                       "alarm_utime, "
+                       "alarm_datetime "
+                       "FROM %s WHERE event_id = %d ",
+                       CAL_TABLE_ALARM, parent);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() failed");
+
+       int index = 0;
+       const unsigned char *temp;
+       calendar_record_h record = NULL;
+       cal_alarm_s *alarm = NULL;
+
+       while (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               ret = calendar_record_create(_calendar_alarm._uri, &record);
+               if (CALENDAR_ERROR_NONE != ret) {
+                       sqlite3_finalize(stmt);
+                       _cal_list_clear(list);
+                       return ret;
+               }
+
+               index = 0;
+               alarm = (cal_alarm_s *)(record);
+
+               alarm->parent_id = parent;
+               alarm->id = sqlite3_column_int(stmt, index++);
+               alarm->remind_tick = sqlite3_column_int(stmt, index++);
+               alarm->remind_tick_unit = sqlite3_column_int(stmt, index++);
+
+               temp = sqlite3_column_text(stmt, index++);
+               alarm->alarm_description = SAFE_STRDUP(temp);
+
+               alarm->alarm.type = sqlite3_column_int(stmt, index++);
+
+               temp = sqlite3_column_text(stmt, index++);
+               alarm->alarm_summary= SAFE_STRDUP(temp);
+
+               alarm->alarm_action = sqlite3_column_int(stmt, index++);
+
+               temp = sqlite3_column_text(stmt, index++);
+               alarm->alarm_attach= SAFE_STRDUP(temp);
+
+               if (alarm->alarm.type == CALENDAR_TIME_UTIME) {
+                       alarm->alarm.time.utime = sqlite3_column_int64(stmt,index++);
+                       sqlite3_column_text(stmt, index++);             // datetime
+               }
+               else {
+                       sqlite3_column_int64(stmt, index++);    //utime
+                       temp = sqlite3_column_text(stmt, index++);
+                       if (temp) {
+                               int y = 0, m = 0, d = 0;
+                               int h = 0, n = 0, s = 0;
+                               switch (strlen((const char *)temp))
+                               {
+                               case 8:
+                                       sscanf((const char *)temp, "%04d%02d%02d", &y, &m, &d);
+                                       alarm->alarm.time.date.year = y;
+                                       alarm->alarm.time.date.month = m;
+                                       alarm->alarm.time.date.mday = d;
+                                       break;
+
+                               case 15:
+                                       sscanf((const char *)temp, "%04d%02d%02dT%02d%02d%02d", &y, &m, &d, &h, &n, &s);
+                                       alarm->alarm.time.date.year = y;
+                                       alarm->alarm.time.date.month = m;
+                                       alarm->alarm.time.date.mday = d;
+                                       alarm->alarm.time.date.hour = h;
+                                       alarm->alarm.time.date.minute = n;
+                                       alarm->alarm.time.date.second = s;
+                                       break;
+                               }
+                       }
+               }
+               calendar_list_add((calendar_list_h)list, record);
+       }
+       sqlite3_finalize(stmt);
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_alarm_delete_with_id(int parent_id)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       snprintf(query, sizeof(query), "DELETE FROM %s WHERE event_id=%d ",
+                       CAL_TABLE_ALARM, parent_id);
+
+       dbret = _cal_db_util_query_exec(query);
+       if (CAL_DB_OK != dbret) {
+               ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+               switch (dbret) {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_alarm_has_alarm(cal_list_s *list_s)
+{
+       calendar_record_h alarm = NULL;
+       int has_alarm = 0;
+       calendar_list_h list = (calendar_list_h)list_s;
+
+       calendar_list_first(list);
+       while (CALENDAR_ERROR_NONE == calendar_list_get_current_record_p(list, &alarm)) {
+               int unit;
+               calendar_record_get_int(alarm, _calendar_alarm.tick_unit, &unit);
+               if (CALENDAR_ALARM_NONE != unit) {
+                       has_alarm = 1;
+                       break;
+               }
+               calendar_list_next(list);
+       }
+       return has_alarm;
+}
diff --git a/native/cal_db_alarm.h b/native/cal_db_alarm.h
new file mode 100644 (file)
index 0000000..9815a34
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_DB_ALARM_H__
+#define __CALENDAR_SVC_DB_ALARM_H__
+
+int _cal_db_alarm_get_records(int event_id, cal_list_s *list);
+int _cal_db_alarm_delete_with_id(int event_id);
+int _cal_db_alarm_insert_records(cal_list_s *list_s, int event_id);
+
+/*
+ * @param[in] list   The alarm list
+ *
+ * @return 0 on none alarm, 1 on alarm.
+ */
+int _cal_db_alarm_has_alarm(cal_list_s *list_s);
+
+#endif  //__CALENDAR_SVC_DB_ALARM_H__
diff --git a/native/cal_db_attendee.c b/native/cal_db_attendee.c
new file mode 100644 (file)
index 0000000..10fe79d
--- /dev/null
@@ -0,0 +1,259 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+#include "cal_list.h"
+
+#include "cal_db_util.h"
+#include "cal_db_query.h"
+#include "cal_db_attendee.h"
+
+static int __cal_db_attendee_insert_record(calendar_record_h record, int parent_id)
+{
+       int index;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       char query[CAL_DB_SQL_MAX_LEN];
+       sqlite3_stmt *stmt;
+       cal_attendee_s *attendee = NULL;
+
+       attendee = (cal_attendee_s *)(record);
+       retvm_if(NULL == attendee, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid argument: cal_alarm_s is NULL");
+
+       snprintf(query, sizeof(query),
+                       "INSERT INTO %s ("
+                       "event_id, "
+                       "attendee_name, attendee_email, attendee_number, "
+                       "attendee_status, attendee_cutype, attendee_ct_index, "
+                       "attendee_role, attendee_rsvp, attendee_group, "
+                       "attendee_delegator_uri, attendee_delegatee_uri, "
+                       "attendee_member, attendee_uid "
+                       ") VALUES ( "
+                       "%d, "
+                       "?, ?, ?, "
+                       "%d, %d, %d, "
+                       "%d, %d, ?, "
+                       "?, ?, "
+                       "?, ? )",
+                       CAL_TABLE_ATTENDEE,
+                       parent_id,
+                       attendee->attendee_status,
+                       attendee->attendee_cutype,
+                       attendee->attendee_ct_index,
+                       attendee->attendee_role,
+                       attendee->attendee_rsvp);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               DBG("_cal_db_util_query_prepare() Failed");
+               DBG("query[%s]", query);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       index = 1;
+       if (attendee->attendee_name)
+               _cal_db_util_stmt_bind_text(stmt, index, attendee->attendee_name);
+       index++;
+
+       if (attendee->attendee_email)
+               _cal_db_util_stmt_bind_text(stmt, index, attendee->attendee_email);
+       index++;
+
+       if (attendee->attendee_number)
+               _cal_db_util_stmt_bind_text(stmt, index, attendee->attendee_number);
+       index++;
+
+       if (attendee->attendee_group)
+               _cal_db_util_stmt_bind_text(stmt, index, attendee->attendee_group);
+       index++;
+
+       if (attendee->attendee_delegator_uri)
+               _cal_db_util_stmt_bind_text(stmt, index, attendee->attendee_delegator_uri);
+       index++;
+
+       if (attendee->attendee_delegatee_uri)
+               _cal_db_util_stmt_bind_text(stmt, index, attendee->attendee_delegatee_uri);
+       index++;
+
+       if (attendee->attendee_member)
+               _cal_db_util_stmt_bind_text(stmt, index, attendee->attendee_member);
+       index++;
+
+       if (attendee->attendee_uid)
+               _cal_db_util_stmt_bind_text(stmt, index, attendee->attendee_uid);
+       index++;
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       sqlite3_finalize(stmt);
+
+       if (CAL_DB_DONE != dbret)
+       {
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       attendee->parent_id = parent_id;
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_attendee_insert_records(cal_list_s *list_s, int parent_id)
+{
+       int ret;
+       int count = 0;
+       calendar_record_h record = NULL;
+       calendar_list_h list = (calendar_list_h)list_s;
+
+       retv_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       calendar_list_get_count(list, &count);
+       if (0 == count)
+               return CALENDAR_ERROR_NONE;
+
+       calendar_list_first(list);
+       while (CALENDAR_ERROR_NONE == calendar_list_get_current_record_p(list, &record)) {
+               ret = __cal_db_attendee_insert_record(record, parent_id);
+               retvm_if(CALENDAR_ERROR_NONE != ret, ret, "_cal_db_extended_insert_record() Failed(%d)", ret);
+               calendar_list_next(list);
+       }
+       return CALENDAR_ERROR_NONE;
+
+}
+
+int _cal_db_attendee_get_records(int parent_id, cal_list_s *list)
+{
+       int ret;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter: list is NULL");
+
+       snprintf(query, sizeof(query),
+                       "SELECT rowid, "
+                       "attendee_name, "
+                       "attendee_email, "
+                       "attendee_number, "
+                       "attendee_status, "
+                       "attendee_ct_index, "
+                       "attendee_role, "
+                       "attendee_rsvp, "
+                       "attendee_group, "
+                       "attendee_delegator_uri, "
+                       "attendee_uid, "
+                       "attendee_cutype, "
+                       "attendee_delegatee_uri, "
+                       "attendee_member "
+                       "FROM %s WHERE event_id = %d ",
+                       CAL_TABLE_ATTENDEE, parent_id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() failed");
+
+       int index;
+       const unsigned char *temp;
+       calendar_record_h record = NULL;
+       cal_attendee_s *attendee = NULL;
+
+       while (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               ret = calendar_record_create(_calendar_attendee._uri, &record);
+               if (CALENDAR_ERROR_NONE != ret) {
+                       sqlite3_finalize(stmt);
+                       _cal_list_clear(list);
+                       return ret;
+               }
+
+               index = 0;
+               attendee = (cal_attendee_s *)(record);
+
+               attendee->parent_id = parent_id;
+               attendee->id = sqlite3_column_int(stmt, index++);
+
+               temp = sqlite3_column_text(stmt, index++);
+               attendee->attendee_name = SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, index++);
+               attendee->attendee_email = SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, index++);
+               attendee->attendee_number = SAFE_STRDUP(temp);
+
+               attendee->attendee_status = sqlite3_column_int(stmt, index++);
+               attendee->attendee_ct_index = sqlite3_column_int(stmt, index++);
+               attendee->attendee_role = sqlite3_column_int(stmt, index++);
+               attendee->attendee_rsvp = sqlite3_column_int(stmt, index++);
+
+               temp = sqlite3_column_text(stmt, index++);
+               attendee->attendee_group = SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, index++);
+               attendee->attendee_delegator_uri = SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, index++);
+               attendee->attendee_uid = SAFE_STRDUP(temp);
+
+               attendee->attendee_cutype = sqlite3_column_int(stmt, index++);
+
+               temp = sqlite3_column_text(stmt, index++);
+               attendee->attendee_delegatee_uri = SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, index++);
+               attendee->attendee_member = SAFE_STRDUP(temp);
+
+               calendar_list_add((calendar_list_h)list, record);
+       }
+
+       sqlite3_finalize(stmt);
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_attendee_delete_with_id(int parent_id)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       snprintf(query, sizeof(query), "DELETE FROM %s WHERE event_id=%d ",
+                       CAL_TABLE_ATTENDEE, parent_id);
+
+       dbret = _cal_db_util_query_exec(query);
+       if (dbret != CAL_DB_OK)
+       {
+               ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
diff --git a/native/cal_db_attendee.h b/native/cal_db_attendee.h
new file mode 100644 (file)
index 0000000..e32e60e
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_DB_ATTENDEE_H__
+#define __CALENDAR_SVC_DB_ATTENDEE_H__
+
+#include "cal_db.h"
+
+int _cal_db_attendee_get_records(int event_id, cal_list_s *list);
+int _cal_db_attendee_delete_with_id(int event_id);
+int _cal_db_attendee_insert_records(cal_list_s *list_s, int event_id);
+
+#endif  //__CALENDAR_SVC_DB_ATTENDEE_H__
diff --git a/native/cal_db_calendar.c b/native/cal_db_calendar.c
new file mode 100644 (file)
index 0000000..96ff505
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdlib.h>
+
+#include "calendar_db.h"
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+
+#include "cal_db.h"
+#include "cal_db_util.h"
+#include "cal_db_query.h"
+#include "cal_db_calendar.h"
+
+#ifdef CAL_IPC_SERVER
+int calendar_db_delete_account(int account_id)
+{
+       CAL_FN_CALL;
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+       GList *calendar_list = NULL;
+
+       snprintf(query, sizeof(query), "SELECT id FROM %s where account_id = %d and deleted = 0",
+                       CAL_TABLE_CALENDAR, account_id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               int id = 0;
+               id = sqlite3_column_int(stmt, 0);
+               calendar_list = g_list_append(calendar_list, GINT_TO_POINTER(id));
+       }
+
+       sqlite3_finalize(stmt);
+       if(calendar_list)
+               CAL_DBG("calendar cnt=%d",g_list_length(calendar_list) );
+
+       ret = _cal_db_util_begin_trans();
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               g_list_free(calendar_list);
+               ERR("db failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       GList* cursor = calendar_list;
+       while(cursor)
+       {
+               int id = GPOINTER_TO_INT(cursor->data);
+
+               ret = calendar_db_delete_record(_calendar_book._uri, id);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("calendar_id(%d) delete fail~ ",id);
+               }
+               cursor = g_list_next(cursor);
+       }
+
+       g_list_free(calendar_list);
+       _cal_db_util_end_trans(true);
+       return CALENDAR_ERROR_NONE;
+}
+#endif
diff --git a/native/cal_db_calendar.h b/native/cal_db_calendar.h
new file mode 100644 (file)
index 0000000..d316393
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __CALENDAR_SVC_DB_CALENDAR_H__
+#define __CALENDAR_SVC_DB_CALENDAR_H__
+
+#ifdef CAL_IPC_SERVER
+int calendar_db_delete_account(int account_id);
+#endif
+
+#endif // __CALENDAR_SVC_DB_CALENDAR_H__
diff --git a/native/cal_db_event.c b/native/cal_db_event.c
new file mode 100644 (file)
index 0000000..b16a106
--- /dev/null
@@ -0,0 +1,439 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+
+#include "cal_time.h"
+#include "cal_access_control.h"
+
+#include "cal_db.h"
+#include "cal_db_util.h"
+#include "cal_db_query.h"
+#include "cal_db_rrule.h"
+#include "cal_db_query.h"
+#include "cal_db_alarm.h"
+#include "cal_db_instance.h"
+#include "cal_db_attendee.h"
+#include "cal_db_extended.h"
+#include "cal_db_event.h"
+
+int _cal_db_event_update_original_event_version(int original_event_id, int version)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       DBG("original_event(%d) changed_ver updated", original_event_id);
+       if (original_event_id > 0) {
+               snprintf(query, sizeof(query), "UPDATE %s SET "
+                               "changed_ver = %d, has_exception = 1 WHERE id = %d ",
+                               CAL_TABLE_SCHEDULE, version, original_event_id);
+
+               dbret = _cal_db_util_query_exec(query);
+               if (CAL_DB_DONE != dbret) {
+                       ERR("_cal_db_util_query_exec() Failed");
+                       switch (dbret) {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_event_check_value_validation(cal_event_s *event)
+{
+       long long int slli = 0;
+       long long int elli = 0;
+
+       retv_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (event->start.type != event->end.type) {
+               ERR("start type(%d) is not same as end type(%d)", event->start.type, event->end.type);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       switch (event->start.type) {
+       case CALENDAR_TIME_UTIME:
+               if (event->start.time.utime > event->end.time.utime) {
+                       ERR("normal start(%lld) > end(%lld)",
+                                       event->start.time.utime, event->end.time.utime);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+
+       case CALENDAR_TIME_LOCALTIME:
+               // check invalid value
+               if (event->start.time.date.month < 1 || event->start.time.date.month > 12) {
+                       ERR("check start month(input:%d)", event->start.time.date.month);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               else if (event->start.time.date.mday < 1 || event->start.time.date.mday > 31) {
+                       ERR("check start mday(input:%d)", event->start.time.date.mday);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               else if (event->end.time.date.month < 1 || event->end.time.date.month > 12) {
+                       ERR("check end month(input:%d)", event->end.time.date.month);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               else if (event->end.time.date.mday < 1 || event->end.time.date.mday > 31) {
+                       ERR("check end mday(input:%d)", event->end.time.date.mday);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               } else { // handle hour, minute, second
+                       if (event->start.time.date.hour < 0 || event->start.time.date.hour > 24) event->start.time.date.hour = 0;
+                       if (event->start.time.date.minute < 0 || event->start.time.date.minute > 60) event->start.time.date.minute = 0;
+                       if (event->start.time.date.second < 0 || event->start.time.date.second > 60) event->start.time.date.second = 0;
+                       if (event->end.time.date.hour < 0 || event->end.time.date.hour > 24) event->end.time.date.hour = 0;
+                       if (event->end.time.date.minute < 0 || event->end.time.date.minute > 60) event->end.time.date.minute = 0;
+                       if (event->end.time.date.second < 0 || event->end.time.date.second > 60) event->end.time.date.second = 0;
+               }
+
+               // check start > end; convert long long int.
+               slli = _cal_time_convert_itol(NULL,
+                               event->start.time.date.year, event->start.time.date.month, event->start.time.date.mday,
+                               event->start.time.date.hour, event->start.time.date.minute, event->start.time.date.second);
+               elli = _cal_time_convert_itol(NULL,
+                               event->end.time.date.year, event->end.time.date.month, event->end.time.date.mday,
+                               event->end.time.date.hour, event->end.time.date.minute, event->end.time.date.second);
+
+               if (slli - elli > 1) { // 1 is to ignore milliseconds
+                       ERR("allday start(%lld) > end(%lld)", slli, elli);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               break;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+
+int _cal_db_event_insert_record(calendar_record_h record, int original_event_id, int *id)
+{
+       int ret = -1;
+       int event_id = -1;
+       int index;
+       int input_ver;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char dtstart_datetime[32] = {0};
+       char dtend_datetime[32] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_event_s* event =  (cal_event_s*)(record);
+       cal_rrule_s *rrule = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int tmp = 0;
+       int calendar_book_id = 0;
+       calendar_record_h record_calendar = NULL;
+       int has_alarm = 0;
+       int timezone_id = 0;
+
+       retv_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       ret = _cal_db_event_check_value_validation(event);
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "_cal_db_event_check_value_validation() failed");
+
+       // access control
+       if (_cal_access_control_have_write_permission(event->calendar_id) == false) {
+               ERR("_cal_access_control_have_write_permission() failed");
+               return CALENDAR_ERROR_PERMISSION_DENIED;
+       }
+
+       ret = calendar_record_get_int(record, _calendar_event.calendar_book_id, &calendar_book_id);
+       DBG("calendar_book_id(%d)", calendar_book_id);
+
+       ret = _cal_db_get_record(_calendar_book._uri, calendar_book_id, &record_calendar);
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_INVALID_PARAMETER, "calendar_book_id is invalid");
+
+       calendar_record_destroy(record_calendar, true);
+
+       has_alarm = _cal_db_alarm_has_alarm(event->alarm_list);
+       _cal_time_get_timezone_from_table(event->start_tzid, NULL, &timezone_id);
+       input_ver = _cal_db_util_get_next_ver();
+       int is_allday = 0;
+       if (CALENDAR_TIME_LOCALTIME == event->start.type
+                       && (0 == event->start.time.date.hour)
+                       && (0 == event->start.time.date.minute)
+                       && (0 == event->start.time.date.second)
+                       && (0 == event->end.time.date.hour)
+                       && (0 == event->end.time.date.minute)
+                       && (0 == event->end.time.date.second)) {
+               is_allday = 1;
+       }
+
+       snprintf(query, sizeof(query), "INSERT INTO %s ( "
+                       "type, "
+                       "created_ver, changed_ver, "
+                       "summary, description, location, categories, exdate, "
+                       "task_status, priority, "
+                       "timezone, "
+                       "contact_id, busy_status, sensitivity, uid, "
+                       "organizer_name, organizer_email, meeting_status, "
+                       "calendar_id, "
+                       "original_event_id, "
+                       "latitude, longitude, "
+                       "email_id, "
+                       "created_time, completed_time, progress, "
+                       "dtstart_type, dtstart_utime, dtstart_datetime, dtstart_tzid, "
+                       "dtend_type, dtend_utime, dtend_datetime, dtend_tzid, "
+                       "last_mod, rrule_id, "
+                       "recurrence_id, rdate, has_attendee, "
+                       "has_alarm, system_type, updated, "
+                       "sync_data1, sync_data2, sync_data3, sync_data4,"
+                       "has_exception, has_extended, freq, is_allday "
+                       ") VALUES ( "
+                       "%d, "
+                       "%d, %d, "
+                       "?, ?, ?, ?, ?, "
+                       "%d, %d, "
+                       "%d, "
+                       "%d, %d, %d, ?, "
+                       "?, ?, %d, "
+                       "%d, "
+                       "%d, "
+                       "%lf, %lf, "
+                       "%d, "
+                       "strftime('%%s', 'now'), %lld, %d, "
+                       "%d, %lld, ?, ?, "
+                       "%d, %lld, ?, ?, "
+                       "strftime('%%s', 'now'), %d, "
+                       "?, ?, %d, %d, %d, %ld, "
+                       "?, ?, ?, ?, "
+                       "%d, %d, %d, %d) ",
+               CAL_TABLE_SCHEDULE,
+               CAL_SCH_TYPE_EVENT, /*event->cal_type,*/
+               input_ver, input_ver,
+               event->event_status, event->priority,
+               event->timezone ? event->timezone : timezone_id,
+               event->contact_id, event->busy_status, event->sensitivity,
+               event->meeting_status,
+               event->calendar_id,
+               original_event_id,
+               event->latitude, event->longitude,
+               event->email_id,
+               (long long int)0, 0, //event->completed_time, event->progress,
+               event->start.type, event->start.type == CALENDAR_TIME_UTIME ? event->start.time.utime : 0,
+               event->end.type, event->end.type == CALENDAR_TIME_UTIME ? event->end.time.utime : 0,
+               event->freq > 0 ? 1 : 0,
+               (0 < event->attendee_list->count) ? 1 : 0,
+               has_alarm,
+               event->system_type,
+               event->updated,
+               (0 < event->exception_list->count) ? 1 : 0,
+               (0 < event->extended_list->count) ? 1 : 0,
+               event->freq,
+               is_allday);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED,
+                       "_cal_db_util_query_prepare() Failed");
+
+       index = 1;
+
+       if (event->summary)
+               _cal_db_util_stmt_bind_text(stmt, index, event->summary);
+       index++;
+
+       if (event->description)
+               _cal_db_util_stmt_bind_text(stmt, index, event->description);
+       index++;
+
+       if (event->location)
+               _cal_db_util_stmt_bind_text(stmt, index, event->location);
+       index++;
+
+       if (event->categories)
+               _cal_db_util_stmt_bind_text(stmt, index, event->categories);
+       index++;
+
+       if (event->exdate)
+               _cal_db_util_stmt_bind_text(stmt, index, event->exdate);
+       index++;
+
+       if (event->uid)
+               _cal_db_util_stmt_bind_text(stmt, index, event->uid);
+       index++;
+
+       if (event->organizer_name)
+               _cal_db_util_stmt_bind_text(stmt, index, event->organizer_name);
+       index++;
+
+       if (event->organizer_email)
+               _cal_db_util_stmt_bind_text(stmt, index, event->organizer_email);
+       index++;
+
+       if (CALENDAR_TIME_LOCALTIME == event->start.type) {
+               snprintf(dtstart_datetime, sizeof(dtstart_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               event->start.time.date.year,
+                               event->start.time.date.month,
+                               event->start.time.date.mday,
+                               event->start.time.date.hour,
+                               event->start.time.date.minute,
+                               event->start.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, index, dtstart_datetime);
+       }
+       index++;
+
+       if (event->start_tzid)
+               _cal_db_util_stmt_bind_text(stmt, index, event->start_tzid);
+       index++;
+
+       if (CALENDAR_TIME_LOCALTIME == event->end.type) {
+               snprintf(dtend_datetime, sizeof(dtend_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               event->end.time.date.year,
+                               event->end.time.date.month,
+                               event->end.time.date.mday,
+                               event->end.time.date.hour,
+                               event->end.time.date.minute,
+                               event->end.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, index, dtend_datetime);
+       }
+       index++;
+
+       if (event->end_tzid)
+               _cal_db_util_stmt_bind_text(stmt, index, event->end_tzid);
+       index++;
+
+       if (event->recurrence_id)
+               _cal_db_util_stmt_bind_text(stmt, index, event->recurrence_id);
+       index++;
+
+       if (event->rdate)
+               _cal_db_util_stmt_bind_text(stmt, index, event->rdate);
+       index++;
+
+       if (event->sync_data1)
+               _cal_db_util_stmt_bind_text(stmt, index, event->sync_data1);
+       index++;
+
+       if (event->sync_data2)
+               _cal_db_util_stmt_bind_text(stmt, index, event->sync_data2);
+       index++;
+
+       if (event->sync_data3)
+               _cal_db_util_stmt_bind_text(stmt, index, event->sync_data3);
+       index++;
+
+       if (event->sync_data4)
+               _cal_db_util_stmt_bind_text(stmt, index, event->sync_data4);
+       index++;
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret) {
+               sqlite3_finalize(stmt);
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+               switch (dbret) {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       event_id = _cal_db_util_last_insert_id();
+       sqlite3_finalize(stmt);
+
+       // update parent event changed ver in case this event is exception mod
+       // which is original_event_id > 0
+       _cal_db_event_update_original_event_version(original_event_id, input_ver);
+
+       calendar_record_get_int(record, _calendar_event.id, &tmp);
+       _cal_record_set_int(record, _calendar_event.id, event_id);
+       if (id) {
+               *id = event_id;
+       }
+
+       _cal_db_rrule_set_default(record);
+       _cal_db_rrule_get_rrule_from_event(record, &rrule);
+       if (rrule) {
+               _cal_db_rrule_insert_record(event_id, rrule);
+               CAL_FREE(rrule);
+       }
+       _cal_db_instance_publish_record(record);
+
+       if (event->alarm_list->count)   {
+               DBG("insert alarm");
+               ret = _cal_db_alarm_insert_records(event->alarm_list, event_id);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_alarm_insert_records() Failed(%d)", ret);
+       }
+       else {
+               DBG("No alarm");
+       }
+
+       if (0 < event->attendee_list->count) {
+               DBG("insert attendee");
+               ret = _cal_db_attendee_insert_records(event->attendee_list, event_id);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_attendee_insert_records() Failed(%d)", ret);
+       }
+       else {
+               DBG("No attendee");
+       }
+
+       if (original_event_id <= 0 && 0 < event->exception_list->count) {
+               DBG("insert exception");
+               ret = _cal_db_event_insert_records(event->exception_list, event_id);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_event_insert_records() Failed(%d)", ret);
+       }
+       else {
+               DBG("No exception");
+       }
+
+       if (0 < event->extended_list->count) {
+               DBG("insert extended");
+               ret = _cal_db_extended_insert_records(event->extended_list, event_id, CALENDAR_RECORD_TYPE_EVENT);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_extended_insert_records() Failed(%d)", ret);
+       }
+       else {
+               DBG("No extended");
+       }
+
+       _cal_db_util_notify(CAL_NOTI_TYPE_EVENT);
+
+       _cal_record_set_int(record, _calendar_event.id, tmp);
+
+       return CALENDAR_ERROR_NONE;
+
+}
+
+int _cal_db_event_insert_records(cal_list_s *list_s, int original_event_id)
+{
+       int ret;
+       int count = 0;
+       calendar_record_h record = NULL;
+       calendar_list_h list = (calendar_list_h)list_s;
+
+       retv_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       calendar_list_get_count(list, &count);
+       if (0 == count)
+               return CALENDAR_ERROR_NONE;
+
+       calendar_list_first(list);
+       while (CALENDAR_ERROR_NONE == calendar_list_get_current_record_p(list, &record)) {
+               ret = _cal_db_event_insert_record(record, original_event_id, NULL);
+               retvm_if(CALENDAR_ERROR_NONE != ret, ret, "_cal_db_extended_insert_record() Failed(%d)", ret);
+               calendar_list_next(list);
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+
diff --git a/native/cal_db_event.h b/native/cal_db_event.h
new file mode 100644 (file)
index 0000000..2c27d56
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_DB_EVENT_H__
+#define __CALENDAR_SVC_DB_EVENT_H__
+
+int _cal_db_event_update_original_event_version(int original_event_id, int version);
+int _cal_db_event_check_value_validation(cal_event_s *event);
+int _cal_db_event_insert_record(calendar_record_h record, int original_event_id, int *id);
+int _cal_db_event_insert_records(cal_list_s *list_s, int original_event_id);
+
+#endif // __CALENDAR_SVC_DB_EVENT_H__
diff --git a/native/cal_db_extended.c b/native/cal_db_extended.c
new file mode 100644 (file)
index 0000000..656d76b
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+#include "cal_list.h"
+
+#include "cal_db.h"
+#include "cal_db_util.h"
+#include "cal_db_query.h"
+#include "cal_db_extended.h"
+
+int _cal_db_extended_get_records(int record_id, calendar_record_type_e record_type, cal_list_s *list)
+{
+       int ret;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: GList is NULL");
+
+       snprintf(query, sizeof(query),
+                       "SELECT * FROM %s "
+                       "WHERE record_id = %d AND "
+                       "record_type = %d",
+                       CAL_TABLE_EXTENDED,
+                       record_id,
+                       record_type);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt,CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() failed");
+
+       int count = 0;
+       const unsigned char *temp;
+       calendar_record_h record = NULL;
+       cal_extended_s *extended = NULL;
+
+       while (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               ret = calendar_record_create(_calendar_extended_property._uri, &record);
+               if (CALENDAR_ERROR_NONE != ret) {
+                       sqlite3_finalize(stmt);
+                       _cal_list_clear(list);
+                       return ret;
+               }
+
+               count = 0;
+               extended = (cal_extended_s *)(record);
+
+               extended->id = sqlite3_column_int(stmt, count++);
+               extended->record_id = sqlite3_column_int(stmt, count++);
+               extended->record_type = sqlite3_column_int(stmt, count++);
+               temp = sqlite3_column_text(stmt, count++);
+               extended->key = SAFE_STRDUP(temp);
+               temp = sqlite3_column_text(stmt, count++);
+               extended->value = SAFE_STRDUP(temp);
+
+               calendar_list_add((calendar_list_h)list, record);
+       }
+       sqlite3_finalize(stmt);
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_extended_delete_with_id(int record_id, calendar_record_type_e record_type)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       snprintf(query, sizeof(query), "DELETE FROM %s WHERE record_id=%d AND record_type=%d",
+                       CAL_TABLE_EXTENDED, record_id, record_type);
+
+       dbret = _cal_db_util_query_exec(query);
+       if (dbret != CAL_DB_OK) {
+               ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_extended_insert_record(calendar_record_h record, int record_id, calendar_record_type_e record_type, int *id)
+{
+       int index;
+       sqlite3_stmt *stmt;
+       char query[CAL_DB_SQL_MAX_LEN];
+       cal_extended_s* extended =  (cal_extended_s*)(record);
+       cal_db_util_error_e dbret;
+
+       retv_if(NULL == extended, CALENDAR_ERROR_INVALID_PARAMETER);
+       retvm_if(record_id <= 0, CALENDAR_ERROR_INVALID_PARAMETER, "record_id(%d)", record_id);
+
+       snprintf(query, sizeof(query), "INSERT INTO %s(record_id, "
+                       "record_type ,key ,value) "
+                       "VALUES(%d,%d,?,?)",
+                       CAL_TABLE_EXTENDED,
+                       record_id,
+                       record_type);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       if (extended->key)
+               _cal_db_util_stmt_bind_text(stmt, 1, extended->key);
+
+       if (extended->value)
+               _cal_db_util_stmt_bind_text(stmt, 2, extended->value);
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret)
+       {
+               sqlite3_finalize(stmt);
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       index = _cal_db_util_last_insert_id();
+       sqlite3_finalize(stmt);
+
+       //_cal_record_set_int(record, _calendar_extended.id,index);
+       if (id) {
+               *id = index;
+       }
+
+       if (record_type == CALENDAR_RECORD_TYPE_EVENT || record_type == CALENDAR_RECORD_TYPE_TODO)
+       {
+               snprintf(query, sizeof(query), "UPDATE %s SET "
+                               "has_extended = 1 "
+                               "WHERE id = %d;",
+                               CAL_TABLE_SCHEDULE,
+                               record_id);
+               dbret = _cal_db_util_query_exec(query);
+               if(CAL_DB_OK != dbret)
+               {
+                       ERR("_cal_db_util_query_exec() Failed(%d)", dbret);
+                       switch (dbret)
+                       {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_extended_insert_records(cal_list_s *list_s, int record_id, calendar_record_type_e record_type)
+{
+       int ret;
+       int count = 0;
+       calendar_record_h record = NULL;
+       calendar_list_h list = (calendar_list_h)list_s;
+
+       retv_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       calendar_list_get_count(list, &count);
+       if (0 == count)
+               return CALENDAR_ERROR_NONE;
+
+       calendar_list_first(list);
+       while (CALENDAR_ERROR_NONE == calendar_list_get_current_record_p(list, &record)) {
+               ret = _cal_db_extended_insert_record(record, record_id, record_type, NULL);
+               retvm_if(CALENDAR_ERROR_NONE != ret, ret, "_cal_db_extended_insert_record() Failed(%d)", ret);
+               calendar_list_next(list);
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
diff --git a/native/cal_db_extended.h b/native/cal_db_extended.h
new file mode 100644 (file)
index 0000000..6df028a
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_DB_EXTENDED_H__
+#define __CALENDAR_SVC_DB_EXTENDED_H__
+
+int _cal_db_extended_get_records(int record_id, calendar_record_type_e record_type, cal_list_s *list);
+int _cal_db_extended_delete_with_id(int record_id, calendar_record_type_e record_type);
+int _cal_db_extended_insert_record(calendar_record_h record, int record_id, calendar_record_type_e record_type, int *id);
+int _cal_db_extended_insert_records(cal_list_s *list_s, int record_id, calendar_record_type_e record_type);
+
+#endif  //__CALENDAR_SVC_DB_EXTENDED_H__
diff --git a/native/cal_db_instance.c b/native/cal_db_instance.c
new file mode 100644 (file)
index 0000000..475f11b
--- /dev/null
@@ -0,0 +1,2281 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <unicode/ucal.h>
+#include <unicode/ustring.h>
+#include <unicode/ustdio.h>
+#include <unicode/udat.h>
+#include <sys/types.h>
+
+#include "calendar_db.h"
+#include "calendar_types.h"
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_time.h"
+#include "cal_record.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_db_instance_helper.h"
+
+#define ms2sec(ms) (long long int)(ms / 1000.0)
+#define sec2ms(s) (s * 1000.0)
+#define lli2p(x) ((gpointer)((time_t)x))
+
+#define COLOR_RED "\033[0;31m"
+#define COLOR_GREEN "\033[0;32m"
+#define COLOR_END "\033[0;m"
+
+/* input order
+       UCAL_MONTH + UCAL_DAY_OF_MONTH
+       UCAL_MONTH + UCAL_WEEK_OF_MONTH + UCAL_DAY_OF_WEEK
+       UCAL_MONTH + UCAL_DAY_OF_WEEK_IN_MONTH + UCAL_DAY_OF_WEEK
+       UCAL_DAY_OF_YEAR
+       UCAL_DAY_OF_WEEK + UCAL_WEEK_OF_YEAR
+ */
+
+struct day {
+       int uday;
+       const char *str;
+};
+
+#define CAL_LUNAR_CALENDAR_BASE_YEAR 2637
+#define CAL_ENDLESS_LIMIT_YEAR 2036
+#define CAL_ENDLESS_LIMIT_MONTH 12
+#define CAL_ENDLESS_LIMIT_MDAY 31
+#define CAL_ENDLESS_LIMIT_UTIME 2114380800 // 2037/01/01 00:00:00 GMT
+#define CAL_ENDLESS_LIMIT_FULL_DAY (365 * 50)
+
+#define CAL_FORMAT_TIME_ALLDAY "%04d%02d%02d"
+#define CAL_FORMAT_TIME_LOCALTIME "%04d%02d%02dT%02d%02d%02d"
+#define CAL_FORMAT_TIME_UTIME "%04d%02d%02dT%02d%02d%02d"
+#define CAL_FORMAT_INSTANCE_LOCALTIME "%04d-%02d-%02dT%02d:%02d:%02d"
+
+static void __print_normal(int calendar_system_type, UCalendar *ucal, const char *tzid, int wkst)
+{
+       UErrorCode ec = U_ZERO_ERROR;
+       if (NULL == ucal) return;
+
+       UCalendar *s_ucal = NULL;
+
+       switch (calendar_system_type)
+       {
+       case CALENDAR_SYSTEM_EAST_ASIAN_LUNISOLAR:
+               s_ucal = _cal_time_get_ucal(tzid, wkst);
+               retm_if(NULL == s_ucal, "_cal_time_get_ucal() Fail");
+               ucal_setMillis(s_ucal, ucal_getMillis(ucal, &ec), &ec);
+               break;
+
+       default: // CALENDAR_SYSTEM_NONE: CALENDAR_SYSTEM_GREGORIAN:
+               s_ucal = ucal;
+               break;
+       }
+       DBG(COLOR_GREEN"[INSERTED] normal instance %04d-%02d-%02d %02d:%02d:%02d"COLOR_END,
+                       ucal_get(s_ucal, UCAL_YEAR, &ec),
+                       ucal_get(s_ucal, UCAL_MONTH, &ec) + 1,
+                       ucal_get(s_ucal, UCAL_DATE, &ec),
+                       ucal_get(s_ucal, UCAL_HOUR_OF_DAY, &ec),
+                       ucal_get(s_ucal, UCAL_MINUTE, &ec),
+                       ucal_get(s_ucal, UCAL_SECOND, &ec));
+
+       if (CALENDAR_SYSTEM_EAST_ASIAN_LUNISOLAR == calendar_system_type) {
+               ucal_close(s_ucal);
+       }
+}
+
+static void __print_allday(int y, int m, int d, int h, int n, int s)
+{
+       DBG(COLOR_RED"[INSERTED] allday instance %04d-%02d-%02d %02d:%02d:%02d"COLOR_END, y, m, d, h, n, s);
+}
+
+static void __get_allday_date(int calendar_system_type, UCalendar *ucal, const char *tzid, int wkst, int *y, int *m, int *d, int *h, int *n, int *s)
+{
+       UErrorCode ec = U_ZERO_ERROR;
+       if (NULL == ucal) return;
+
+       UCalendar *s_ucal = NULL;
+
+       switch (calendar_system_type)
+       {
+       case CALENDAR_SYSTEM_EAST_ASIAN_LUNISOLAR:
+               s_ucal = _cal_time_get_ucal(tzid, wkst);
+               ucal_setMillis(s_ucal, ucal_getMillis(ucal, &ec), &ec);
+               break;
+
+       default: //CALENDAR_SYSTEM_NONE:, CALENDAR_SYSTEM_GREGORIAN:
+               s_ucal = ucal;
+               break;
+       }
+       if (y) *y = ucal_get(s_ucal, UCAL_YEAR, &ec);
+       if (m) *m = ucal_get(s_ucal, UCAL_MONTH, &ec) + 1;
+       if (d) *d = ucal_get(s_ucal, UCAL_DATE, &ec);
+       if (h) *h = ucal_get(s_ucal, UCAL_HOUR_OF_DAY, &ec);
+       if (n) *n = ucal_get(s_ucal, UCAL_MINUTE, &ec);
+       if (s) *s = ucal_get(s_ucal, UCAL_SECOND, &ec);
+
+       if (CALENDAR_SYSTEM_EAST_ASIAN_LUNISOLAR == calendar_system_type) {
+               ucal_close(s_ucal);
+       }
+}
+
+static void __set_time_to_ucal(int calendar_system_type, UCalendar *ucal, calendar_time_s *t)
+{
+       retm_if(NULL == ucal, "Invalid parameter: ucal is NULL");
+       retm_if(NULL == t, "Invalid parameter: calendar_time_s is NULL");
+
+       UErrorCode ec = U_ZERO_ERROR;
+
+       switch (t->type)
+       {
+       case CALENDAR_TIME_UTIME:
+               ucal_setMillis(ucal, sec2ms(t->time.utime), &ec);
+               break;
+
+       case CALENDAR_TIME_LOCALTIME:
+               ucal_setDateTime(ucal, t->time.date.year, t->time.date.month -1, t->time.date.mday,
+                               t->time.date.hour, t->time.date.minute, t->time.date.second, &ec);
+               if (CALENDAR_SYSTEM_EAST_ASIAN_LUNISOLAR == calendar_system_type) {
+                       ucal_set(ucal, UCAL_EXTENDED_YEAR, t->time.date.year + CAL_LUNAR_CALENDAR_BASE_YEAR);
+               }
+               break;
+       }
+}
+
+static int __get_exdate_list(UCalendar *ucal, cal_event_s *event, GList **l, int *count)
+{
+       retvm_if (NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "ucal is NULL");
+       retvm_if (NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "event is NULL");
+
+       if (event->exdate == NULL || '\0' == *(event->exdate)) {
+               return CALENDAR_ERROR_NONE;
+       }
+
+       char **t = NULL;
+       t = g_strsplit_set(event->exdate, " ,", -1);
+       retvm_if (NULL == t, CALENDAR_ERROR_OUT_OF_MEMORY, "g_strsplit_set() is failed");;
+
+       DBG("[%s]", event->exdate);
+       int len = 0;
+       len = g_strv_length(t);
+       DBG("exdate len (%d)", len);
+
+       int i;
+       for (i = 0; i < len; i++) {
+               char *p = t[i];
+               if (NULL == p) {
+                       continue;
+               }
+               int y = 0, m = 0, d = 0;
+               int h = 0, n = 0, s = 0;
+               long long int lli = 0;
+               UCalendar *ucal2 = NULL;
+               UErrorCode ec = U_ZERO_ERROR;
+               switch (strlen(p))
+               {
+               case 8:
+                       DBG("ALLDAY instance");
+                       sscanf(p, "%04d%02d%02d", &y, &m, &d);
+
+                       ucal2 = ucal_clone(ucal, &ec);
+                       ucal_setDateTime(ucal2, y, m - 1, d, 0, 0, 0, &ec);
+                       lli = ms2sec(ucal_getMillis(ucal2, &ec));
+                       ucal_close(ucal2);
+                       break;
+
+               case 15:
+                       DBG("ALLDAY instance");
+                       sscanf(p, "%04d%02d%02dT%02d%02d%02d", &y, &m, &d, &h, &n, &s);
+
+                       ucal2 = ucal_clone(ucal, &ec);
+                       ucal_setDateTime(ucal2, y, m - 1, d, h, n, s, &ec);
+                       lli = ms2sec(ucal_getMillis(ucal2, &ec));
+                       ucal_close(ucal2);
+                       break;
+
+               case 16:
+                       DBG("NORMAL instance");
+                       sscanf(p, "%04d%02d%02dT%02d%02d%02dZ", &y, &m, &d, &h, &n, &s);
+                       lli = _cal_time_convert_itol(NULL, y, m, d, h, n, s);
+                       break;
+               }
+               DBG("%lld", lli);
+               *l = g_list_append(*l, lli2p(lli));
+       }
+       if (count) *count = len;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_update_exdate_mod(int original_event_id, char *recurrence_id)
+{
+       int dbret;
+       int i, j;
+       char **t = NULL;
+       char *p = NULL;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+
+       if (original_event_id < 1 || recurrence_id == NULL)
+       {
+               DBG("Nothing to update exdate mod");
+               return CALENDAR_ERROR_NONE;
+       }
+
+       DBG("recurrence_id[%s]", recurrence_id);
+       t = g_strsplit_set(recurrence_id, " ,", -1);
+       if (!t)
+       {
+               ERR("g_strsplit_set failed");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       for (i = 0; t[i]; i++)
+       {
+               p = t[i];
+               // remove space
+               j = 0;
+               while (p[j] == ' ') j++;
+
+               p = t[i] + j;
+               DBG("%d[%s]", i + 1, p);
+
+               int y = 0, m = 0, d = 0;
+               int h = 0, n = 0, s = 0;
+               char buf[32] = {0};
+               switch (strlen(p))
+               {
+               case 8:
+                       DBG("ALLDAY instance");
+                       sscanf(p, "%04d%02d%02d", &y, &m, &d);
+                       snprintf(buf, sizeof(buf), "%04d-%02d-%02dT%02d:%02d:%02d", y, m, d, 0, 0, 0);
+                       snprintf(query, sizeof(query),
+                                       "DELETE FROM %s "
+                                       "WHERE event_id = %d AND dtstart_datetime = '%s' ",
+                                       CAL_TABLE_ALLDAY_INSTANCE,
+                                       original_event_id, buf);
+                       break;
+
+               case 15:
+                       DBG("ALLDAY instance");
+                       sscanf(p, "%04d%02d%02dT%02d%02d%02d", &y, &m, &d, &h, &n, &s);
+                       snprintf(buf, sizeof(buf), "%04d-%02d-%02dT%02d:%02d:%02d", y, m, d, h, n, s);
+                       snprintf(query, sizeof(query),
+                                       "DELETE FROM %s "
+                                       "WHERE event_id = %d AND dtstart_datetime = '%s' ",
+                                       CAL_TABLE_ALLDAY_INSTANCE,
+                                       original_event_id, buf);
+                       break;
+
+               case 16:
+                       DBG("NORMAL instance");
+                       sscanf(p, "%04d%02d%02dT%02d%02d%02dZ",
+                                       &y, &m, &d, &h, &n, &s);
+                       snprintf(query, sizeof(query),
+                                       "DELETE FROM %s "
+                                       "WHERE event_id = %d AND dtstart_utime = %lld ",
+                                       CAL_TABLE_NORMAL_INSTANCE,
+                                       original_event_id, _cal_time_convert_itol(NULL, y, m, d, h, n, s));
+                       DBG("(%lld)", _cal_time_convert_itol(NULL, y, m, d, h, n, s));
+                       break;
+               }
+
+               if (strlen(p) == strlen("YYYYMMDDTHHMMSSZ")) {
+               } else {
+
+               }
+               dbret = _cal_db_util_query_exec(query);
+               if (dbret != CAL_DB_OK) {
+                       ERR("[%s]", query);
+                       ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+                       g_strfreev(t);
+                       switch (dbret)
+                       {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+       }
+       g_strfreev(t);
+       return CALENDAR_ERROR_NONE;
+}
+
+static inline int ___cal_db_instance_has_after(calendar_time_s *t1, calendar_time_s *t2)
+{
+       if (t1->type == CALENDAR_TIME_UTIME) {
+               if (t1->time.utime > t2->time.utime)
+                       return 1;
+               else
+                       return 0;
+       }
+
+       DBG("%d %d %d /%d %d %d", t1->time.date.year, t1->time.date.month, t1->time.date.mday,
+                       t2->time.date.year, t2->time.date.month, t2->time.date.mday);
+       if (t1->time.date.year > t2->time.date.year) {
+               DBG("exit year");
+               return 1;
+       } else if (t1->time.date.year < t2->time.date.year) {
+               return 0;
+       } else {
+               if (t1->time.date.month > t2->time.date.month) {
+                       return 1;
+               } else if (t1->time.date.month < t2->time.date.month) {
+                       return 0;
+               } else {
+                       if (t1->time.date.mday > t2->time.date.mday) {
+                               return 1;
+                       } else {
+                               return 0;
+                       }
+               }
+       }
+}
+
+static inline int __cal_db_instance_convert_mday(const char *str, int *mday)
+{
+       int d;
+
+       if (!str || !*str) {
+               ERR("Invalid argument: check mday[%s]", str);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       d = atoi(str);
+       if (d < 1 || d > 31) {
+               ERR("Invalid argument: check day(%d)", d);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       DBG("get mday[%s] and convert to int(%d)", str, d);
+       *mday = d;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_del_inundant(int event_id, calendar_time_s *st, cal_event_s *event)
+{
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int cnt;
+       char query[CAL_DB_SQL_MAX_LEN];
+
+       if (event->range_type != CALENDAR_RANGE_COUNT) {
+               return CALENDAR_ERROR_NONE;
+       }
+
+       cnt = event->count;
+       DBG("get count(%d) and del after this", cnt);
+
+       if (st->type == CALENDAR_TIME_UTIME) {
+               snprintf(query, sizeof(query), "DELETE FROM %s "
+                               "WHERE event_id = %d "
+                               "AND dtstart_utime > (SELECT dtstart_utime FROM %s "
+                               "WHERE event_id = %d ORDER BY dtstart_utime LIMIT %d, 1) ",
+                               CAL_TABLE_NORMAL_INSTANCE,
+                               event_id,
+                               CAL_TABLE_NORMAL_INSTANCE,
+                               event_id, cnt -1);
+
+       } else if (st->type == CALENDAR_TIME_LOCALTIME) {
+               snprintf(query, sizeof(query), "DELETE FROM %s "
+                               "WHERE event_id = %d "
+                               "AND dtstart_datetime > (SELECT dtstart_datetime FROM %s "
+                               "WHERE event_id = %d ORDER BY dtstart_datetime LIMIT %d, 1) ",
+                               CAL_TABLE_ALLDAY_INSTANCE,
+                               event_id,
+                               CAL_TABLE_ALLDAY_INSTANCE,
+                               event_id, cnt -1);
+       }
+
+       dbret = _cal_db_util_query_exec(query);
+       if (dbret != CAL_DB_OK)
+       {
+               DBG("query(%s)", query);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __convert_week_to_bits(const char *byday)
+{
+       retvm_if(NULL == byday, -1, "Invalid parameter:byday is NULL");
+       const char *week_text[7] = {"SU", "MO", "TU", "WE", "TH", "FR", "SA"};
+       int week = 0;
+       int i;
+       for (i = 0; i < 7; i++)
+       {
+               if (strstr(byday, week_text[i]))
+               {
+                       week |= (0x01 << i);
+               }
+       }
+       return week;
+}
+
+static int __cal_db_instance_get_duration(UCalendar *ucal, calendar_time_s *st, calendar_time_s *et, long long int *duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter:ucal is NULL");
+       retvm_if(NULL == st || NULL == et, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: st or et is NULL");
+
+       long long int _duration = -1;
+       UErrorCode ec = U_ZERO_ERROR;
+       UDate ud;
+
+       switch (st->type) {
+       case CALENDAR_TIME_UTIME:
+               if (st->time.utime > et->time.utime)
+               {
+                       ERR("check time: start(%lld) > end(%lld)", st->time.utime, et->time.utime);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               _duration = et->time.utime - st->time.utime;
+               break;
+
+       case CALENDAR_TIME_LOCALTIME:
+               ucal_setDateTime(ucal, et->time.date.year, et->time.date.month -1, et->time.date.mday,
+                               et->time.date.hour, et->time.date.minute, et->time.date.second, &ec);
+               ud = ucal_getMillis(ucal, &ec);
+
+               ucal_setDateTime(ucal, st->time.date.year, st->time.date.month -1, st->time.date.mday,
+                               st->time.date.hour, st->time.date.minute, st->time.date.second, &ec);
+
+               _duration = ucal_getFieldDifference(ucal, ud, UCAL_SECOND, &ec);
+               if (U_FAILURE(ec))
+               {
+                       ERR("ucal_getFieldDifference failed (%s)", u_errorName(ec));
+                       return ec;
+               }
+               break;
+       }
+
+       if (duration) *duration = _duration;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_insert_record(UCalendar *ucal, long long int duration, cal_event_s *event)//int type, int event_id)
+{
+       int ret;
+       long long int lli;
+       UErrorCode ec = U_ZERO_ERROR;
+       cal_instance_normal_s *normal = NULL;
+       cal_instance_allday_s *allday = NULL;
+       int id;
+
+       if (NULL == ucal)
+       {
+               ERR("Invalid parameter: ucal is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       switch (event->start.type)
+       {
+       case CALENDAR_TIME_UTIME:
+               normal = (cal_instance_normal_s*)calloc(1,sizeof(cal_instance_normal_s));
+               retvm_if(NULL == normal, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_instance_normal_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+               lli =  ms2sec(ucal_getMillis(ucal, &ec));
+//             __print_normal(event->system_type, ucal, event->start_tzid, event->wkst);
+
+               normal->event_id = event->index;
+               normal->start.type = event->start.type;
+               normal->start.time.utime =  lli;
+               normal->end.type = event->start.type;
+               normal->end.time.utime = lli + duration;
+               ret = _cal_db_instance_normal_insert_record(normal, &id);
+               free(normal);
+               if (CALENDAR_ERROR_NONE != ret)
+               {
+                       ERR("_cal_db_instance_normal_insert_record() failed");
+                       return ret;
+               }
+               break;
+       case CALENDAR_TIME_LOCALTIME:
+               allday = (cal_instance_allday_s*)calloc(1,sizeof(cal_instance_allday_s));
+               retvm_if(NULL == allday, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_instance_allday_s:sch) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
+
+               allday->event_id = event->index;
+               __get_allday_date(event->system_type, ucal, event->start_tzid, event->wkst,
+                               &(allday->start.time.date.year),
+                               &(allday->start.time.date.month),
+                               &(allday->start.time.date.mday),
+                               &(allday->start.time.date.hour),
+                               &(allday->start.time.date.minute),
+                               &(allday->start.time.date.second));
+               allday->start.type = event->start.type;
+
+//             __print_allday(allday->start.time.date.year, allday->start.time.date.month, allday->start.time.date.mday,
+//                             allday->start.time.date.hour, allday->start.time.date.minute, allday->start.time.date.second);
+
+               if (duration > 0) {
+                       UCalendar *ucal2 = NULL;
+                       ucal2 = ucal_clone(ucal, &ec);
+                       ucal_add(ucal2, UCAL_SECOND, duration, &ec);
+                       __get_allday_date(event->system_type, ucal2, event->start_tzid, event->wkst,
+                                       &(allday->end.time.date.year),
+                                       &(allday->end.time.date.month),
+                                       &(allday->end.time.date.mday),
+                                       &(allday->end.time.date.hour),
+                                       &(allday->end.time.date.minute),
+                                       &(allday->end.time.date.second));
+                       ucal_close(ucal2);
+
+               } else {
+                       allday->end = allday->start;
+
+               }
+               allday->end.type = event->start.type;
+
+               ret = _cal_db_instance_allday_insert_record(allday, &id);
+               free(allday);
+               if (CALENDAR_ERROR_NONE != ret)
+               {
+                       ERR("_cal_db_instance_allday_insert_record() failed");
+                       return ret;
+               }
+               break;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+/*
+ * return value means is_exit
+ * true: stop and exit loop
+ * false: continue
+ */
+static bool __insert_valid_record(UCalendar *ucal, cal_event_s *event, long long int duration, long long int dtstart_utime, long long int until_utime, int *count)
+{
+       retvm_if(NULL == ucal, true, "Invalid parameter: ucal is NULL");
+       retvm_if(NULL == event, true, "Invalid parameter: event is NULL");
+
+       UErrorCode ec = U_ZERO_ERROR;
+       long long int utime = ms2sec(ucal_getMillis(ucal, &ec));
+
+       calendar_time_s *st = &event->start;
+       retvm_if(NULL == st, true, "Invalid parameter: st is NULL");
+
+       if (utime < dtstart_utime) {
+               DBG("get time(%lld) is earlier than start(%lld), so skip", utime, dtstart_utime);
+               return false;
+       }
+
+       // check range
+       switch (event->range_type)
+       {
+       case CALENDAR_RANGE_UNTIL:
+       case CALENDAR_RANGE_NONE:
+               if (utime > until_utime)
+                       return true;
+               break;
+
+       case CALENDAR_RANGE_COUNT:
+               (*count)++;
+               if (*count > event->count)
+                       return true;
+
+               if (utime > CAL_ENDLESS_LIMIT_UTIME) { // event count is remained, it should not go over LIMIT
+                       DBG("stopped because dtstart(%lld) > LIMIT UTIME(%lld)", utime, (long long int)CAL_ENDLESS_LIMIT_UTIME);
+                       return true;
+               }
+               break;
+       }
+       __cal_db_instance_insert_record(ucal, duration, event);//->start.type, event->index);
+       return false;
+}
+
+static int __convert_wday_to_int(const char *wday)
+{
+       retvm_if(NULL == wday, 0, "Invalid paramter: wday is NULL");
+
+       const char *week_text[7] = {"SU", "MO", "TU", "WE", "TH", "FR", "SA"};
+       int i;
+       for (i = 0; i < 7; i++)
+       {
+               if (strstr(wday, week_text[i])) {
+                       return i + 1;
+               }
+       }
+       return 0;
+}
+
+static int __get_until_from_range(cal_event_s *event, calendar_time_s *until)
+{
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+       retvm_if(NULL == until, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: until is NULL");
+
+       long long int range = 0;
+       switch (event->range_type)
+       {
+       case CALENDAR_RANGE_COUNT:
+               DBG("range count");
+               break;
+
+       case CALENDAR_RANGE_UNTIL:
+               DBG("range until");
+               until->type = event->until.type;
+               switch (until->type)
+               {
+               case CALENDAR_TIME_UTIME:
+                       range = _cal_time_convert_itol(NULL, CAL_ENDLESS_LIMIT_YEAR,
+                                       CAL_ENDLESS_LIMIT_MONTH, CAL_ENDLESS_LIMIT_MDAY,
+                                       0, 0, 0);
+                       if (event->until.time.utime > range)
+                       {
+                               DBG("until time(%lld) > max, so set max(%lld)", event->until.time.utime, range);
+                               until->time.utime = range;
+                       }
+                       else
+                       {
+                               until->time.utime = event->until.time.utime;
+                       }
+                       break;
+
+               case CALENDAR_TIME_LOCALTIME:
+                       until->time.date.year = event->until.time.date.year > CAL_ENDLESS_LIMIT_YEAR ?
+                               CAL_ENDLESS_LIMIT_YEAR : event->until.time.date.year;
+                       until->time.date.month = event->until.time.date.month;
+                       until->time.date.mday = event->until.time.date.mday;
+                       until->time.date.hour = event->until.time.date.hour;
+                       until->time.date.minute = event->until.time.date.minute;
+                       until->time.date.second = event->until.time.date.second;
+                       break;
+               }
+               break;
+
+       case CALENDAR_RANGE_NONE:
+               DBG("range none");
+               until->type = event->until.type;
+               switch (until->type)
+               {
+               case CALENDAR_TIME_UTIME:
+                       until->time.utime = _cal_time_convert_itol(event->start_tzid,
+                                       CAL_ENDLESS_LIMIT_YEAR,
+                                       CAL_ENDLESS_LIMIT_MONTH,
+                                       CAL_ENDLESS_LIMIT_MDAY,
+                                       0, 0, 0);
+                       break;
+               case CALENDAR_TIME_LOCALTIME:
+                       until->time.date.year = CAL_ENDLESS_LIMIT_YEAR;
+                       until->time.date.month = CAL_ENDLESS_LIMIT_MONTH;
+                       until->time.date.mday = CAL_ENDLESS_LIMIT_MDAY;
+                       until->time.date.hour = 0;
+                       until->time.date.minute = 0;
+                       until->time.date.second = 0;
+                       break;
+               }
+               break;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_weekly_wday(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+
+       UErrorCode ec = U_ZERO_ERROR;
+       calendar_time_s until = {0};
+       __get_until_from_range(event, &until);
+       __set_time_to_ucal(event->system_type, ucal, &until); // set until before dtstart_utime
+       long long int until_utime = ms2sec(ucal_getMillis(ucal, &ec));
+
+       int week_bits = 0;
+       // if nowday in weekly
+       if (NULL == event->byday || '\0' == event->byday[0]) {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               int dtstart_wday = ucal_get(ucal, UCAL_DAY_OF_WEEK, &ec);
+               week_bits |= (0x01 << (dtstart_wday - 1));
+
+       } else {
+               week_bits = __convert_week_to_bits(event->byday);
+       }
+       DBG("week integer(0x%x)", week_bits);
+
+       //check exdate ----
+       GList *l = NULL;
+       int ex_count = 0;
+       __get_exdate_list(ucal, event, &l, &ex_count);
+       DBG("-------ex_count(%d)", ex_count);
+
+       int loop = 0;
+       int count = 0;
+       bool is_exit = false;
+       long long int last_utime = 0;
+       long long int curr_utime = 0;
+       while (false == is_exit)
+       {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               long long int dtstart_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               int woy = ucal_get(ucal, UCAL_WEEK_OF_YEAR , &ec);
+               ucal_set(ucal, UCAL_WEEK_OF_YEAR, woy + (event->interval *loop));
+               DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+
+               int i;
+               for (i = 0; i < 7; i++)
+               {
+                       if (week_bits & (0x01 << i)) {
+                               ucal_set(ucal, UCAL_DAY_OF_WEEK, i + 1);
+
+                               //check exdate ----
+                               bool is_skip = false;
+                               int i = 0;
+                               for (i = 0; i < ex_count; i++) {
+                                       time_t tt = (time_t)g_list_nth_data(l, i);
+                                       long long int lli = (long long int)tt;
+                                       if (lli == ms2sec(ucal_getMillis(ucal, &ec))) {
+                                               DBG("found exdate(%lld)", lli);
+                                               count++;
+                                               l = g_list_remove(l, lli2p(lli));
+                                               is_skip = true;
+                                               break;
+                                       }
+                               }
+                               if (true == is_skip) {
+                                       continue;
+                               }
+                               is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+                       }
+               }
+
+               curr_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               if ((last_utime == curr_utime) || (CAL_ENDLESS_LIMIT_FULL_DAY == loop)) {
+                       DBG("current utime is same as last utime, so stoppted");
+                       is_exit = true;
+               } else {
+                       last_utime = curr_utime;
+               }
+               loop++;
+       }
+       g_list_free(l);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_daily_mday(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+
+       UErrorCode ec = U_ZERO_ERROR;
+       calendar_time_s until = {0};
+       __get_until_from_range(event, &until);
+       __set_time_to_ucal(event->system_type, ucal, &until); // set until before dtstart_utime
+       long long int until_utime = ms2sec(ucal_getMillis(ucal, &ec));
+
+       // get bymonth into array
+       int bymonth[12] = {0};
+       int bymonth_len = 0;
+       bool has_bymonth = false;
+       if (event->bymonth && *(event->bymonth))
+       {
+               has_bymonth = true;
+
+               char **u = NULL;
+               u = g_strsplit_set(event->bymonth, " ,", -1);
+               retvm_if(NULL == u, CALENDAR_ERROR_OUT_OF_MEMORY, "g_strsplit_set() is failed");
+
+               bymonth_len = g_strv_length(u);
+               int i;
+               for (i = 0 ; i < bymonth_len; i++)
+               {
+                       bymonth[i] = atoi(u[i]);
+               }
+               g_strfreev(u);
+       }
+
+       //check exdate ----
+       GList *l = NULL;
+       int ex_count = 0;
+       __get_exdate_list(ucal, event, &l, &ex_count);
+       DBG("-------ex_count(%d)", ex_count);
+
+       calendar_time_s *st = &event->start;
+       __set_time_to_ucal(event->system_type, ucal, st);
+       long long int dtstart_utime = ms2sec(ucal_getMillis(ucal, &ec));
+       DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+
+       int loop = 0;
+       int count = 0;
+       bool is_exit = false;
+       long long int last_utime = 0;
+       long long int curr_utime = 0;
+       while (false == is_exit)
+       {
+               if (loop) ucal_add(ucal, UCAL_DAY_OF_YEAR, event->interval, &ec);
+
+               if (has_bymonth) {
+                       bool is_valid = false;
+                       int month = ucal_get(ucal, UCAL_MONTH, &ec) + 1;
+                       int j;
+                       for (j = 0; j < bymonth_len; j++)
+                       {
+                               if (month == bymonth[j]) {
+                                       is_valid = true;
+                                       break;
+                               }
+                       }
+                       if (false == is_valid) {
+                               DBG("Get month(%d) Not in bymonth", month);
+                               continue;
+                       }
+               }
+
+               //check exdate ----
+               bool is_skip = false;
+               int i = 0;
+               for (i = 0; i < ex_count; i++) {
+                       time_t tt = (time_t)g_list_nth_data(l, i);
+                       long long int lli = (long long int)tt;
+                       if (lli == ms2sec(ucal_getMillis(ucal, &ec))) {
+                               DBG("found exdate(%lld)", lli);
+                               count++;
+                               l = g_list_remove(l, lli2p(lli));
+                               is_skip = true;
+                               break;
+                       }
+               }
+               if (true == is_skip) {
+                       if (0 == loop) loop = 1;
+                       continue;
+               }
+               is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+
+               curr_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               if ((last_utime == curr_utime) || (CAL_ENDLESS_LIMIT_FULL_DAY == loop)) {
+                       DBG("current utime is same as last utime, so stoppted");
+                       is_exit = true;
+               } else {
+                       last_utime = curr_utime;
+               }
+               loop++;
+       }
+       g_list_free(l);
+       return CALENDAR_ERROR_NONE;
+}
+
+/* week integet: use integer bits for wday
+ * 0  0  0  0 |0  0  0  0 - bits
+ *   SA FR TH WE TU MO SU
+ */
+static int __convert_week_to_offset(UCalendar *ucal, int week_bits, int setpos)
+{
+       UErrorCode ec = U_ZERO_ERROR;
+
+       DBG("week_bits(%x), setpos", week_bits, setpos);
+
+       int offset = 0;
+       if (setpos >= 0) {
+               ucal_set(ucal, UCAL_DATE, 1); // set 1st day of month.
+               DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+               int first_wday = ucal_get(ucal, UCAL_DAY_OF_WEEK, &ec);
+               DBG("1st week(%d)", first_wday);
+
+               while (setpos > 0) {
+                       int index = ((first_wday + offset - 1) % 7);
+                       if (week_bits & (0x01 << index)) {
+                               setpos--;
+                       }
+                       offset++;
+               }
+               offset--; // to add from 1st day, sub 1.
+       }
+       else {
+               ucal_set(ucal, UCAL_DATE, 1);
+               ucal_add(ucal, UCAL_MONTH, 1, &ec);
+               ucal_add(ucal, UCAL_DAY_OF_YEAR, -1, &ec); // set the last day of the month.
+               DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+               int last_wday = ucal_get(ucal, UCAL_DAY_OF_WEEK, &ec);
+               DBG("last week(%d)", last_wday);
+
+               while (setpos < 0) {
+                       int index = (371 + last_wday - offset - 1) % 7; // to make positive, add 371(7*53): offset max is 365days
+                       if (week_bits & (0x40 >> index)) {
+                               setpos++;
+                       }
+                       offset++;
+               }
+               offset--;
+               offset *= -1;
+       }
+       DBG("offset(%d)", offset);
+       return offset;
+}
+
+static int __cal_db_instance_publish_record_setpos(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+
+       UErrorCode ec = U_ZERO_ERROR;
+
+       // get until
+       calendar_time_s until = {0};
+       __get_until_from_range(event, &until);
+       __set_time_to_ucal(event->system_type, ucal, &until); // set until before dtstart_utime
+       long long int until_utime = ms2sec(ucal_getMillis(ucal, &ec));
+
+       char **t = NULL;
+       t = g_strsplit_set(event->bysetpos, " ,", -1);
+       retvm_if(NULL == t, CALENDAR_ERROR_OUT_OF_MEMORY, "g_strsplit_set() is failed");
+
+       int len = g_strv_length(t);
+       DBG("len(%d)", len);
+
+       int i;
+       int loop = 0;
+       int count = 0;
+       bool is_exit = false;
+       long long int last_utime = 0;
+       long long int curr_utime = 0;
+       while (false == is_exit)
+       {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               long long int dtstart_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               //              int year = ucal_get(ucal, UCAL_YEAR, &ec);
+               //              int month = ucal_get(ucal, UCAL_MONTH, &ec) + 1;
+
+               switch (event->freq)
+               {
+               case CALENDAR_RECURRENCE_YEARLY:
+                       DBG("Yearly loop(%d)", loop);
+                       ucal_add(ucal, UCAL_YEAR, event->interval * loop, &ec);
+
+                       if (event->byyearday && event->byyearday[0] != '\0')
+                       {
+                               ucal_set(ucal, UCAL_MONTH, 0);
+                               ucal_set(ucal, UCAL_DAY_OF_YEAR, 1);
+
+                               for (i = 0; i < len; i++) // handle setpos
+                               {
+                                       int setpos = atoi(t[i]);
+                                       DBG("(%lld) + (%d)", ms2sec(ucal_getMillis(ucal, &ec)), setpos);
+                                       ucal_add(ucal, UCAL_DAY_OF_YEAR, setpos, &ec);
+                                       DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+                               }
+                       }
+                       else if (event->bymonth && event->bymonth[0] != '\0')
+                       {
+                               char **u = NULL;
+                               u = g_strsplit_set(event->bymonth, " ,", -1);
+                               if (NULL == u) {
+                                       is_exit = true;
+                                       break;
+                               }
+                               int mlen = g_strv_length(u);
+                               DBG("bymonth len(%d)", mlen);
+
+                               int j;
+                               for (j = 0; j < mlen; j++)
+                               {
+                                       int month = atoi(u[j]); // set month
+                                       DBG("month(%d)", month);
+
+                                       for (i = 0; i < len; i++) //from: same as monthly
+                                       {
+                                               ucal_set(ucal, UCAL_MONTH, month - 1);
+                                               int setpos = atoi(t[i]);
+
+                                               if (event->byday && event->byday[0] != '\0')
+                                               {
+                                                       int week_bits = __convert_week_to_bits(event->byday);
+                                                       int offset = __convert_week_to_offset(ucal, week_bits, setpos);
+                                                       DBG("byday (%lld) + (%d)", ms2sec(ucal_getMillis(ucal, &ec)), offset);
+                                                       ucal_add(ucal, UCAL_DAY_OF_YEAR, offset, &ec);
+                                                       DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+
+                                               }
+                                               else // bymonthday
+                                               {
+                                                       DBG("bymonthday");
+                                                       DBG("Not impletemented");
+                                                       is_exit = true;
+                                                       j = mlen;
+                                                       break;
+                                               }
+                                               is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+                                       }// end same as monthly
+                               }
+                               g_strfreev(u);
+                       }
+                       else
+                       {
+                               DBG("Not impletemented");
+                               is_exit = true;
+                               break;
+                       }
+                       break;
+
+               case CALENDAR_RECURRENCE_MONTHLY:
+                       ucal_add(ucal, UCAL_MONTH, event->interval * loop, &ec);
+                       DBG("Monthly (%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+
+                       int month = ucal_get(ucal, UCAL_MONTH, &ec) + 1;
+                       DBG("month(%d)", month);
+
+                       for (i = 0; i < len; i++)
+                       {
+                               ucal_set(ucal, UCAL_MONTH, month - 1);
+                               int setpos = atoi(t[i]);
+
+                               if (event->byday && event->byday[0] != '\0')
+                               {
+                                       int week_bits = __convert_week_to_bits(event->byday);
+                                       int offset = __convert_week_to_offset(ucal, week_bits, setpos);
+                                       DBG("byday (%lld) + (%d)", ms2sec(ucal_getMillis(ucal, &ec)), offset);
+                                       ucal_add(ucal, UCAL_DAY_OF_YEAR, offset, &ec);
+                                       DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+                               }
+                               else // bymonthday
+                               {
+                                       DBG("bymonthday");
+                                       DBG("Not impletemented");
+                                       is_exit = true;
+                                       break;
+                               }
+                               is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+                       }
+                       break;
+
+               case CALENDAR_RECURRENCE_WEEKLY:
+                       DBG("Weekly");
+                       DBG("Not impletemented");
+                       is_exit = true;
+                       break;
+
+               case CALENDAR_RECURRENCE_DAILY:
+                       DBG("Daily");
+                       DBG("Not impletemented");
+                       is_exit = true;
+                       break;
+               }
+
+               curr_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               if ((last_utime == curr_utime) || (CAL_ENDLESS_LIMIT_FULL_DAY == loop)) {
+                       DBG("current utime is same as last utime, so stoppted");
+                       is_exit = true;
+               } else {
+                       last_utime = curr_utime;
+               }
+               loop++;
+       }
+       g_strfreev(t);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_yearly_yday(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+       retvm_if(NULL == event->byyearday || '\0' == event->byyearday[0],
+                       CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: no byyearday");
+
+       UErrorCode ec = U_ZERO_ERROR;
+       calendar_time_s until = {0};
+       __get_until_from_range(event, &until);
+       __set_time_to_ucal(event->system_type, ucal, &until); // set until before dtstart_utime
+       long long int until_utime = ms2sec(ucal_getMillis(ucal, &ec));
+
+       char **t = NULL;
+       int len = 0;
+
+       t = g_strsplit_set(event->byyearday, " ,", -1);
+       len = g_strv_length(t);
+       DBG("len(%d)", len);
+
+       //check exdate ----
+       GList *l = NULL;
+       int ex_count = 0;
+       __get_exdate_list(ucal, event, &l, &ex_count);
+       DBG("-------ex_count(%d)", ex_count);
+
+       int loop = 0;
+       int count = 0;
+       bool is_exit = false;
+       long long int last_utime = 0;
+       long long int curr_utime = 0;
+       while (false == is_exit)
+       {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               long long int dtstart_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               //              int year = ucal_get(ucal, UCAL_YEAR, &ec);
+               DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+               ucal_add(ucal, UCAL_YEAR, event->interval * loop, &ec);
+               DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+
+               int i;
+               for (i = 0; i < len; i++)
+               {
+                       ucal_set(ucal, UCAL_DAY_OF_YEAR, atoi(t[i]));
+                       DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+
+                       //check exdate ----
+                       bool is_skip = false;
+                       int k = 0;
+                       for (k = 0; k < ex_count; k++) {
+                               time_t tt = (time_t)g_list_nth_data(l, k);
+                               long long int lli = (long long int)tt;
+                               if (lli == ms2sec(ucal_getMillis(ucal, &ec))) {
+                                       DBG("found exdate(%lld)", lli);
+                                       count++;
+                                       l = g_list_remove(l, lli2p(lli));
+                                       is_skip = true;
+                                       break;
+                               }
+                       }
+                       if (true == is_skip) {
+                               continue;
+                       }
+                       is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+               }
+
+               curr_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               if ((last_utime == curr_utime) || (CAL_ENDLESS_LIMIT_FULL_DAY == loop)) {
+                       DBG("current utime is same as last utime, so stoppted");
+                       is_exit = true;
+               } else {
+                       last_utime = curr_utime;
+               }
+               loop++;
+       }
+       g_strfreev(t);
+       g_list_free(l);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_yearly_weekno(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+       retvm_if(NULL == event->byweekno || '\0' == event->byweekno[0],
+                       CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: no byweekno");
+
+       UErrorCode ec = U_ZERO_ERROR;
+       calendar_time_s until = {0};
+       __get_until_from_range(event, &until);
+       __set_time_to_ucal(event->system_type, ucal, &until); // set until before dtstart_utime
+       long long int until_utime = ms2sec(ucal_getMillis(ucal, &ec));
+
+       // get byday
+       int week_bits = 0;
+       // if nowday in weekly
+       if (NULL == event->byday || '\0' == event->byday[0]) {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               int dtstart_wday = ucal_get(ucal, UCAL_DAY_OF_WEEK, &ec);
+               week_bits |= (0x01 << (dtstart_wday - 1));
+
+       } else {
+               week_bits = __convert_week_to_bits(event->byday);
+       }
+       DBG("week integer(0x%x)", week_bits);
+
+       char **t = NULL;
+       int len = 0;
+
+       t = g_strsplit_set(event->byweekno, " ,", -1);
+       len = g_strv_length(t);
+       DBG("len(%d)", len);
+
+       //check exdate ----
+       GList *l = NULL;
+       int ex_count = 0;
+       __get_exdate_list(ucal, event, &l, &ex_count);
+       DBG("-------ex_count(%d)", ex_count);
+
+       int loop = 0;
+       int count = 0;
+       bool is_exit = false;
+       long long int last_utime = 0;
+       long long int curr_utime = 0;
+       while (false == is_exit)
+       {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               long long int dtstart_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               ucal_add(ucal, UCAL_YEAR, (event->interval * loop), &ec);
+               DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+
+               int i;
+               for (i = 0 ; i < len; i++)
+               {
+                       DBG("woy(%d)", ucal_get(ucal, UCAL_WEEK_OF_YEAR, &ec));
+                       ucal_set(ucal, UCAL_WEEK_OF_YEAR, atoi(t[i]));
+                       DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+
+                       int j;
+                       for (j = 0; j < 7; j++)
+                       {
+                               if (week_bits & (0x01 << j)) {
+                                       ucal_set(ucal, UCAL_DAY_OF_WEEK, j + 1);
+                                       DBG("%d (%lld)", j + 1, ms2sec(ucal_getMillis(ucal, &ec)));
+
+                                       //check exdate ----
+                                       bool is_skip = false;
+                                       int k = 0;
+                                       for (k = 0; k < ex_count; k++) {
+                                               time_t tt = (time_t)g_list_nth_data(l, k);
+                                               long long int lli = (long long int)tt;
+                                               if (lli == ms2sec(ucal_getMillis(ucal, &ec))) {
+                                                       DBG("found exdate(%lld)", lli);
+                                                       count++;
+                                                       l = g_list_remove(l, lli2p(lli));
+                                                       is_skip = true;
+                                                       break;
+                                               }
+                                       }
+                                       if (true == is_skip) {
+                                               continue;
+                                       }
+                                       is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+                               }
+                       }
+               }
+
+               curr_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               if ((last_utime == curr_utime) || (CAL_ENDLESS_LIMIT_FULL_DAY == loop)) {
+                       DBG("current utime is same as last utime, so stoppted");
+                       is_exit = true;
+               } else {
+                       last_utime = curr_utime;
+               }
+               loop++;
+       }
+       g_strfreev(t);
+       g_list_free(l);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_yearly_wday(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+
+       UErrorCode ec = U_ZERO_ERROR;
+       calendar_time_s until = {0};
+       __get_until_from_range(event, &until);
+       __set_time_to_ucal(event->system_type, ucal, &until); // set until before dtstart_utime
+       long long int until_utime = ms2sec(ucal_getMillis(ucal, &ec));
+
+       // get bymonth into array
+       int bymonth[12] = {0};
+       int bymonth_len = 0;
+       if (event->bymonth && *(event->bymonth))
+       {
+               char **u = NULL;
+               u = g_strsplit_set(event->bymonth, " ,", -1);
+               retvm_if(NULL == u, CALENDAR_ERROR_OUT_OF_MEMORY, "g_strsplit_set() is failed");
+
+               bymonth_len = g_strv_length(u);
+               int i;
+               for (i = 0 ; i < bymonth_len; i++)
+               {
+                       bymonth[i] = atoi(u[i]);
+               }
+               g_strfreev(u);
+
+       } else {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               int month = ucal_get(ucal, UCAL_MONTH, &ec) + 1;
+               bymonth[0] = month;
+               bymonth_len = 1;
+       }
+
+       // get bymonthday into array
+       int bymonthday[1024] = {0};
+       int bymonthday_len = 0;
+       bool has_bymonthday = false;
+       if (event->bymonthday && *(event->bymonthday)) {
+               has_bymonthday = true;
+
+               char **u = NULL;
+               u = g_strsplit_set(event->bymonthday, " ,", -1);
+               retvm_if(NULL == u, CALENDAR_ERROR_OUT_OF_MEMORY, "g_strsplit_set() is failed");
+
+               bymonthday_len = g_strv_length(u);
+               int i;
+               for (i = 0 ; i < bymonthday_len; i++)
+               {
+                       bymonthday[i] = atoi(u[i]);
+               }
+               g_strfreev(u);
+       }
+
+       char **t = NULL;
+       int len = 0;
+
+       // if nowday in weekly
+       if (NULL == event->byday || '\0' == event->byday[0]) {
+               const char *week_text[7] = {"SU", "MO", "TU", "WE", "TH", "FR", "SA"};
+
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               int nth = ucal_get(ucal, UCAL_DAY_OF_WEEK_IN_MONTH, &ec);
+               int dtstart_wday = ucal_get(ucal, UCAL_DAY_OF_WEEK, &ec);
+               char buf[32] = {0};
+               snprintf(buf, sizeof(buf), "%d%s", nth, week_text[dtstart_wday -1]);
+               DBG("set byday[%s]", buf);
+
+               t = g_strsplit_set(buf, " ,", -1);
+               len = 1;
+
+       } else {
+               t = g_strsplit_set(event->byday, " ,", -1);
+               len = g_strv_length(t);
+       }
+       DBG("[%s] len(%d)", event->byday, len);
+
+       //check exdate ----
+       GList *l = NULL;
+       int ex_count = 0;
+       __get_exdate_list(ucal, event, &l, &ex_count);
+       DBG("-------ex_count(%d)", ex_count);
+
+       int loop = 0;
+       int count = 0;
+       bool is_exit = false;
+       long long int last_utime = 0;
+       long long int curr_utime = 0;
+       while (false == is_exit)
+       {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               long long int dtstart_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               //              int year = ucal_get(ucal, UCAL_YEAR, &ec);
+               ucal_add(ucal, UCAL_YEAR, event->interval * loop, &ec);
+
+               int k;
+               for (k = 0; k < bymonth_len; k++)
+               {
+                       ucal_set(ucal, UCAL_MONTH, bymonth[k] - 1);
+                       DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+
+                       int i;
+                       for (i = 0; i < len; i++)
+                       {
+                               // get nth, wday
+                               if (strlen(t[i]) > 2) { // -3SU, +2SA
+                                       int nth  = 0;
+                                       char wday[32] = {0};
+
+                                       sscanf(t[i], "%d%s", &nth, wday); // -3SU, +2SA
+                                       DBG("nth(%d) wday[%s]", nth, wday);
+
+                                       // set nth, wday
+                                       if (nth > 0) {
+                                               ucal_set(ucal, UCAL_DATE, 1);
+                                               int wday_int = __convert_wday_to_int(wday);
+                                               ucal_set(ucal, UCAL_DAY_OF_WEEK, wday_int);
+                                               ucal_set(ucal, UCAL_DAY_OF_WEEK_IN_MONTH, nth > 4 ? -1 : nth);
+
+                                       } else {
+                                               ucal_add(ucal, UCAL_YEAR, 1, &ec);
+                                               ucal_set(ucal, UCAL_MONTH, 0);
+                                               ucal_set(ucal, UCAL_DATE, 1);
+                                               int wday_int = __convert_wday_to_int(wday);
+                                               ucal_set(ucal, UCAL_DAY_OF_WEEK, wday_int);
+                                               ucal_set(ucal, UCAL_DAY_OF_WEEK_IN_MONTH, 1);
+                                               ucal_add(ucal, UCAL_DAY_OF_WEEK_IN_MONTH, nth, &ec);
+                                       }
+                                       DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+
+                                       //check exdate ----
+                                       bool is_skip = false;
+                                       int k = 0;
+                                       for (k = 0; k < ex_count; k++) {
+                                               time_t tt = (time_t)g_list_nth_data(l, k);
+                                               long long int lli = (long long int)tt;
+                                               if (lli == ms2sec(ucal_getMillis(ucal, &ec))) {
+                                                       DBG("found exdate(%lld)", lli);
+                                                       count++;
+                                                       l = g_list_remove(l, lli2p(lli));
+                                                       is_skip = true;
+                                                       break;
+                                               }
+                                       }
+                                       if (true == is_skip) {
+                                               continue;
+                                       }
+
+                                       is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+
+                               } else { // SU, SA: no week num: means all week:1TH,2TH,3TH.., so needs another byevent->system_typex
+                                       char wday[32] = {0};
+                                       sscanf(t[i], "%s", wday);
+
+                                       int wday_int = __convert_wday_to_int(wday);
+                                       DBG("wday[%s], wday_int(%d)", wday, wday_int);
+
+                                       if (has_bymonthday) { // bymonthday
+                                               DBG("has bymonthday");
+                                               int j;
+                                               for (j = 0; j < bymonthday_len; j++)
+                                               {
+                                                       ucal_set(ucal, UCAL_MONTH, ucal_get(ucal, UCAL_MONTH, &ec));
+                                                       ucal_set(ucal, UCAL_DATE, bymonthday[j]);
+                                                       DBG("set date(%d), (%lld)", bymonthday[j], ms2sec(ucal_getMillis(ucal, &ec)));
+                                                       int w = ucal_get(ucal, UCAL_DAY_OF_WEEK, &ec);
+                                                       if (wday_int != w) {
+                                                               DBG("get wday(%d) != want wday(%d)", w, wday_int);
+                                                               continue;
+                                                       }
+                                                       DBG("found");
+
+                                                       //check exdate ----
+                                                       bool is_skip = false;
+                                                       int k = 0;
+                                                       for (k = 0; k < ex_count; k++) {
+                                                               time_t tt = (time_t)g_list_nth_data(l, k);
+                                                               long long int lli = (long long int)tt;
+                                                               if (lli == ms2sec(ucal_getMillis(ucal, &ec))) {
+                                                                       DBG("found exdate(%lld)", lli);
+                                                                       count++;
+                                                                       l = g_list_remove(l, lli2p(lli));
+                                                                       is_skip = true;
+                                                                       break;
+                                                               }
+                                                       }
+                                                       if (true == is_skip) {
+                                                               continue;
+                                                       }
+                                                       is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+                                                       if (true == is_exit) break;
+                                               }
+
+                                       } else {
+                                               int j;
+                                               int month = ucal_get(ucal, UCAL_MONTH, &ec) + 1;
+                                               for (j = 0; j < 6; j++)
+                                               {
+                                                       ucal_set(ucal, UCAL_MONTH, ucal_get(ucal, UCAL_MONTH, &ec));
+                                                       ucal_set(ucal, UCAL_DATE, 1);
+                                                       ucal_set(ucal, UCAL_DAY_OF_WEEK, wday_int);
+                                                       ucal_set(ucal, UCAL_DAY_OF_WEEK_IN_MONTH, j + 1);
+                                                       DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+                                                       int get_month = ucal_get(ucal, UCAL_MONTH, &ec) + 1;
+                                                       if (month != get_month) break;
+
+                                                       //check exdate ----
+                                                       bool is_skip = false;
+                                                       int k = 0;
+                                                       for (k = 0; k < ex_count; k++) {
+                                                               time_t tt = (time_t)g_list_nth_data(l, k);
+                                                               long long int lli = (long long int)tt;
+                                                               if (lli == ms2sec(ucal_getMillis(ucal, &ec))) {
+                                                                       DBG("found exdate(%lld)", lli);
+                                                                       count++;
+                                                                       l = g_list_remove(l, lli2p(lli));
+                                                                       is_skip = true;
+                                                                       break;
+                                                               }
+                                                       }
+                                                       if (true == is_skip) {
+                                                               continue;
+                                                       }
+                                                       is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               curr_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               if ((last_utime == curr_utime) || (CAL_ENDLESS_LIMIT_FULL_DAY == loop)) {
+                       DBG("current utime is same as last utime, so stoppted");
+                       is_exit = true;
+               } else {
+                       last_utime = curr_utime;
+               }
+               loop++;
+       }
+       g_strfreev(t);
+       g_list_free(l);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_yearly_mday(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+
+       UErrorCode ec = U_ZERO_ERROR;
+       calendar_time_s until = {0};
+       __get_until_from_range(event, &until);
+       __set_time_to_ucal(event->system_type, ucal, &until); // set until before dtstart_utime
+       long long int until_utime = ms2sec(ucal_getMillis(ucal, &ec));
+
+       // get bymonth into array
+       int bymonth[12] = {0};
+       int bymonth_len = 0;
+       if (event->bymonth && *(event->bymonth))
+       {
+               char **u = NULL;
+               u = g_strsplit_set(event->bymonth, " ,", -1);
+               retvm_if(NULL == u, CALENDAR_ERROR_OUT_OF_MEMORY, "g_strsplit_set() is failed");
+
+               bymonth_len = g_strv_length(u);
+               int i;
+               for (i = 0 ; i < bymonth_len; i++)
+               {
+                       bymonth[i] = atoi(u[i]);
+               }
+               g_strfreev(u);
+
+       } else {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               int month = ucal_get(ucal, UCAL_MONTH, &ec) + 1;
+               bymonth[0] = month;
+               bymonth_len = 1;
+       }
+       DBG("bymonth len(%d)", bymonth_len);
+
+       // get bymonthday into array
+       int bymonthday[1024] = {0};
+       int bymonthday_len = 0;
+       if (event->bymonthday && *(event->bymonthday)) {
+               char **u = NULL;
+               u = g_strsplit_set(event->bymonthday, " ,", -1);
+               retvm_if(NULL == u, CALENDAR_ERROR_OUT_OF_MEMORY, "g_strsplit_set() is failed");
+
+               bymonthday_len = g_strv_length(u);
+               int i;
+               for (i = 0 ; i < bymonthday_len; i++)
+               {
+                       bymonthday[i] = atoi(u[i]);
+               }
+               g_strfreev(u);
+
+       } else {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               int dtstart_mday = ucal_get(ucal, UCAL_DATE, &ec);
+               bymonthday[0] = dtstart_mday;
+               bymonthday_len = 1;
+       }
+       DBG("bymonthday len(%d)", bymonthday_len);
+
+       //check exdate ----
+       GList *l = NULL;
+       int ex_count = 0;
+       __get_exdate_list(ucal, event, &l, &ex_count);
+       DBG("-------ex_count(%d)", ex_count);
+
+       int loop = 0;
+       int count = 0;
+       bool is_exit = false;
+       long long int last_utime = 0;
+       long long int curr_utime = 0;
+       while (false == is_exit)
+       {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               long long int dtstart_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               //              int year = ucal_get(ucal, UCAL_YEAR, &ec);
+               ucal_add(ucal, UCAL_YEAR, event->interval *loop, &ec);
+               DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+
+               int j;
+               for (j = 0; j < bymonth_len; j++)
+               {
+                       ucal_set(ucal, UCAL_MONTH, bymonth[j] - 1);
+                       DBG("month(%d) (%lld)", bymonth[j] -1, ms2sec(ucal_getMillis(ucal, &ec)));
+
+                       int i;
+                       for (i = 0 ; i < bymonthday_len; i++)
+                       {
+                               if (bymonthday[i] > 0) {
+                                       ucal_set(ucal, UCAL_MONTH, ucal_get(ucal, UCAL_MONTH, &ec));
+                                       ucal_set(ucal, UCAL_DATE, bymonthday[i]);
+                                       int get_mday = ucal_get(ucal, UCAL_DATE, &ec);
+                                       if (get_mday != bymonthday[i]) {
+                                               DBG("bymonthday(%d) but get (%d) from icu", bymonthday[i], get_mday);
+                                               continue;
+                                       }
+
+                               } else if (bymonthday[i] < 0) {
+                                       // goto end of the month
+                                       ucal_set(ucal, UCAL_MONTH, ucal_get(ucal, UCAL_MONTH, &ec));
+                                       ucal_set(ucal, UCAL_DATE, 1);
+                                       ucal_add(ucal, UCAL_MONTH, 1, &ec);
+                                       ucal_add(ucal, UCAL_DAY_OF_YEAR, bymonthday[i], &ec);
+
+                               } else { // 0 is invalid
+                                       DBG("Invalid bymonthday(%d)", bymonthday[i]);
+                                       continue;
+                               }
+                               //check exdate ----
+                               bool is_skip = false;
+                               int k = 0;
+                               for (k = 0; k < ex_count; k++) {
+                                       time_t tt = (time_t)g_list_nth_data(l, k);
+                                       long long int lli = (long long int)tt;
+                                       if (lli == ms2sec(ucal_getMillis(ucal, &ec))) {
+                                               DBG("found exdate(%lld)", lli);
+                                               count++;
+                                               l = g_list_remove(l, lli2p(lli));
+                                               is_skip = true;
+                                               break;
+                                       }
+                               }
+                               if (true == is_skip) {
+                                       continue;
+                               }
+                               is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+                       }
+               }
+
+               curr_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               if ((last_utime == curr_utime) || (CAL_ENDLESS_LIMIT_FULL_DAY == loop)) {
+                       DBG("current utime is same as last utime, so stoppted");
+                       is_exit = true;
+               } else {
+                       last_utime = curr_utime;
+               }
+               loop++;
+       }
+       g_list_free(l);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_record_yearly(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       if (NULL == ucal)
+       {
+               ERR("Invalid parameter: ucal is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+       if (NULL == event)
+       {
+               ERR("Invalid parameter: event is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (event->byyearday && strlen(event->byyearday) > 0) {
+               __cal_db_instance_publish_yearly_yday(ucal, event, duration);
+
+       } else if (event->byweekno && strlen(event->byweekno) > 0) {
+               __cal_db_instance_publish_yearly_weekno(ucal, event, duration);
+
+       } else {
+               if (event->byday && *event->byday) {
+                       __cal_db_instance_publish_yearly_wday(ucal, event, duration);
+
+               } else {
+                       __cal_db_instance_publish_yearly_mday(ucal, event, duration);
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_monthly_wday(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+
+       UErrorCode ec = U_ZERO_ERROR;
+       calendar_time_s until = {0};
+       __get_until_from_range(event, &until);
+       __set_time_to_ucal(event->system_type, ucal, &until); // set until before dtstart_utime
+       long long int until_utime = ms2sec(ucal_getMillis(ucal, &ec));
+
+       // get bymonthday into array
+       int bymonthday[1024] = {0};
+       int bymonthday_len = 0;
+       bool has_bymonthday = false;
+       if (event->bymonthday && *(event->bymonthday)) {
+               has_bymonthday = true;
+
+               char **u = NULL;
+               u = g_strsplit_set(event->bymonthday, " ,", -1);
+               retvm_if(NULL == u, CALENDAR_ERROR_OUT_OF_MEMORY, "g_strsplit_set() is failed");
+
+               bymonthday_len = g_strv_length(u);
+               int i;
+               for (i = 0 ; i < bymonthday_len; i++)
+               {
+                       bymonthday[i] = atoi(u[i]);
+               }
+               g_strfreev(u);
+       }
+
+       char **t = NULL;
+       int len = 0;
+
+       // if nowday in weekly
+       if (NULL == event->byday || '\0' == event->byday[0]) {
+               const char *week_text[7] = {"SU", "MO", "TU", "WE", "TH", "FR", "SA"};
+
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               int week_nth = ucal_get(ucal, UCAL_DAY_OF_WEEK_IN_MONTH, &ec);
+               int dtstart_wday = ucal_get(ucal, UCAL_DAY_OF_WEEK, &ec);
+               char buf[32] = {0};
+               snprintf(buf, sizeof(buf), "%d%s", week_nth, week_text[dtstart_wday -1]);
+               DBG("set byday[%s]", buf);
+
+               t = g_strsplit_set(buf, " ,", -1);
+               len = 1;
+
+       } else {
+               t = g_strsplit_set(event->byday, " ,", -1);
+               len = g_strv_length(t);
+       }
+       DBG("[%s] len(%d)", event->byday, len);
+
+       //check exdate ----
+       GList *l = NULL;
+       int ex_count = 0;
+       __get_exdate_list(ucal, event, &l, &ex_count);
+       DBG("-------ex_count(%d)", ex_count);
+
+       int loop = 0;
+       int count = 0;
+       bool is_exit = false;
+       long long int last_utime = 0;
+       long long int curr_utime = 0;
+       while (false == is_exit)
+       {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               long long int dtstart_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               //              int month = ucal_get(ucal, UCAL_MONTH, &ec) + 1;
+               ucal_add(ucal, UCAL_MONTH, event->interval * loop, &ec);
+               DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+
+               int i;
+               for (i = 0; i < len; i++)
+               {
+                       if (strlen(t[i]) == 0) continue;
+                       // get nth, wday
+                       if (strlen(t[i]) > 2) { // -3SU, +2SA
+                               int nth = 0;
+                               char wday[32] = {0};
+
+                               sscanf(t[i], "%d%s", &nth, wday); // -3SU, +2SA
+                               DBG("nth(%d) wday[%s]", nth, wday);
+                               if (nth > 4) nth = -1;
+
+                               // set nth, wday
+                               if (nth > 0) {
+                                       ucal_set(ucal, UCAL_MONTH, ucal_get(ucal, UCAL_MONTH, &ec));
+                                       ucal_set(ucal, UCAL_DATE, 1);
+
+                               } else {
+                                       // goto end of the month
+                                       ucal_set(ucal, UCAL_MONTH, ucal_get(ucal, UCAL_MONTH, &ec));
+                                       ucal_set(ucal, UCAL_DATE, 1);
+                                       ucal_add(ucal, UCAL_MONTH, 1, &ec);
+                                       ucal_add(ucal, UCAL_DAY_OF_YEAR, -1, &ec);
+                               }
+
+                               int wday_int = __convert_wday_to_int(wday);
+                               ucal_set(ucal, UCAL_DAY_OF_WEEK, wday_int);
+                               ucal_set(ucal, UCAL_DAY_OF_WEEK_IN_MONTH, nth);
+                               DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+                               is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+
+                       } else { // SU, SA: no week num: means all week:1TH,2TH,3TH.., so needs another byevent->system_typex
+                               char wday[32] = {0};
+                               sscanf(t[i], "%s", wday);
+
+                               int wday_int = __convert_wday_to_int(wday);
+                               DBG("wday[%s], wday_int(%d)", wday, wday_int);
+
+                               if (has_bymonthday) { // bymonthday
+                                       DBG("has bymonthday");
+                                       int j;
+                                       for (j = 0; j < bymonthday_len; j++)
+                                       {
+                                               ucal_set(ucal, UCAL_MONTH, ucal_get(ucal, UCAL_MONTH, &ec));
+                                               ucal_set(ucal, UCAL_DATE, bymonthday[j]);
+                                               DBG("set date(%d), (%lld)", bymonthday[j], ms2sec(ucal_getMillis(ucal, &ec)));
+                                               int w = ucal_get(ucal, UCAL_DAY_OF_WEEK, &ec);
+                                               if (wday_int != w) {
+                                                       DBG("get wday(%d) != want wday(%d)", w, wday_int);
+                                                       continue;
+                                               }
+                                               DBG("found");
+
+                                               //check exdate ----
+                                               bool is_skip = false;
+                                               int k = 0;
+                                               for (k = 0; k < ex_count; k++) {
+                                                       time_t tt = (time_t)g_list_nth_data(l, k);
+                                                       long long int lli = (long long int)tt;
+                                                       if (lli == ms2sec(ucal_getMillis(ucal, &ec))) {
+                                                               DBG("found exdate(%lld)", lli);
+                                                               count++;
+                                                               l = g_list_remove(l, lli2p(lli));
+                                                               is_skip = true;
+                                                               break;
+                                                       }
+                                               }
+                                               if (true == is_skip) {
+                                                       continue;
+                                               }
+                                               is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+                                       }
+
+                               } else {
+                                       int week_bits = __convert_week_to_bits(event->byday);
+                                       DBG("week integer(0x%x)", week_bits);
+
+                                       int j;
+                                       int month = ucal_get(ucal, UCAL_MONTH, &ec) + 1;
+                                       for (j = 0; j < 6; j++)
+                                       {
+                                               ucal_set(ucal, UCAL_MONTH, ucal_get(ucal, UCAL_MONTH, &ec));
+                                               ucal_set(ucal, UCAL_DATE, 1);
+                                               bool month_changed = false;
+                                               int k = 0;
+                                               for (k = 0; k < 7; k++) {
+                                                       if (0 == (week_bits & (0x01 << k))) continue;
+
+                                                       ucal_set(ucal, UCAL_DAY_OF_WEEK, k + 1);
+                                                       ucal_set(ucal, UCAL_DAY_OF_WEEK_IN_MONTH, j + 1);
+                                                       DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+                                                       int get_month = ucal_get(ucal, UCAL_MONTH, &ec) + 1;
+                                                       if (month != get_month) {
+                                                               DBG("get month(%d) is not same with (%d)", get_month, month);
+                                                               month_changed = true;
+                                                               break;
+                                                       }
+                                                       //check exdate ----
+                                                       bool is_skip = false;
+                                                       int k = 0;
+                                                       for (k = 0; k < ex_count; k++) {
+                                                               time_t tt = (time_t)g_list_nth_data(l, k);
+                                                               long long int lli = (long long int)tt;
+                                                               if (lli == ms2sec(ucal_getMillis(ucal, &ec))) {
+                                                                       DBG("found exdate(%lld)", lli);
+                                                                       count++;
+                                                                       l = g_list_remove(l, lli2p(lli));
+                                                                       is_skip = true;
+                                                                       break;
+                                                               }
+                                                       }
+                                                       if (true == is_skip) {
+                                                               continue;
+                                                       }
+                                                       is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+                                                       if (true == is_exit) break;
+                                               }
+                                               if (true == is_exit) break;
+                                               if (true == month_changed) break;
+                                       }
+                               }
+                       }
+               }
+
+               curr_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               if ((last_utime == curr_utime) || (CAL_ENDLESS_LIMIT_FULL_DAY == loop)) {
+                       DBG("current utime is same as last utime, so stoppted");
+                       is_exit = true;
+               } else {
+                       last_utime = curr_utime;
+               }
+               loop++;
+       }
+       g_strfreev(t);
+       g_list_free(l);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_monthly_mday(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+
+       UErrorCode ec = U_ZERO_ERROR;
+       calendar_time_s until = {0};
+       __get_until_from_range(event, &until);
+       __set_time_to_ucal(event->system_type, ucal, &until); // set until before dtstart_utime
+       long long int until_utime = ms2sec(ucal_getMillis(ucal, &ec));
+
+       // get bymonthday into array
+       int bymonthday[1024] = {0};
+       int bymonthday_len = 0;
+       if (event->bymonthday && *(event->bymonthday)) {
+               DBG("[%s]", event->bymonthday);
+               char **u = NULL;
+               u = g_strsplit_set(event->bymonthday, " ,", -1);
+               retvm_if(NULL == u, CALENDAR_ERROR_OUT_OF_MEMORY, "g_strsplit_set() is failed");
+
+               bymonthday_len = g_strv_length(u);
+               int i;
+               for (i = 0 ; i < bymonthday_len; i++)
+               {
+                       bymonthday[i] = atoi(u[i]);
+               }
+               g_strfreev(u);
+
+       } else {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               int dtstart_mday = ucal_get(ucal, UCAL_DATE, &ec);
+               bymonthday[0] = dtstart_mday;
+               bymonthday_len = 1;
+       }
+       DBG("len(%d)", bymonthday_len);
+
+       //check exdate ----
+       GList *l = NULL;
+       int ex_count = 0;
+       __get_exdate_list(ucal, event, &l, &ex_count);
+       DBG("-------ex_count(%d)", ex_count);
+
+       int loop = 0;
+       int count = 0;
+       bool is_exit = false;
+       long long int last_utime = 0;
+       long long int curr_utime = 0;
+       while (false == is_exit)
+       {
+               calendar_time_s *st = &event->start;
+               __set_time_to_ucal(event->system_type, ucal, st);
+               long long int dtstart_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               //              int month = ucal_get(ucal, UCAL_MONTH, &ec) + 1;
+               ucal_add(ucal, UCAL_MONTH, event->interval * loop, &ec);
+
+               int i;
+               for (i = 0 ; i < bymonthday_len; i++)
+               {
+                       if (bymonthday[i] > 0) {
+                               ucal_set(ucal, UCAL_MONTH, ucal_get(ucal, UCAL_MONTH, &ec));
+                               ucal_set(ucal, UCAL_DATE, bymonthday[i]);
+                               int get_mday = ucal_get(ucal, UCAL_DATE, &ec);
+                               if (get_mday != bymonthday[i]) {
+                                       DBG("bymonthday(%d) but get (%d) from icu", bymonthday[i], get_mday);
+                                       continue;
+                               }
+
+                       } else if (bymonthday[i] < 0) {
+                               // goto end of the month
+                               ucal_set(ucal, UCAL_MONTH, ucal_get(ucal, UCAL_MONTH, &ec));
+                               ucal_set(ucal, UCAL_DATE, 1);
+                               ucal_add(ucal, UCAL_MONTH, 1, &ec);
+                               ucal_add(ucal, UCAL_DAY_OF_YEAR, bymonthday[i], &ec);
+                               DBG("(%lld)", ms2sec(ucal_getMillis(ucal, &ec)));
+
+                       } else { // 0 is invalid
+                               DBG("Invalid bymonthday(%d)", bymonthday[i]);
+                               continue;
+                       }
+
+                       //check exdate ----
+                       bool is_skip = false;
+                       int k = 0;
+                       for (k = 0; k < ex_count; k++) {
+                               time_t tt = (time_t)g_list_nth_data(l, k);
+                               long long int lli = (long long int)tt;
+                               if (lli == ms2sec(ucal_getMillis(ucal, &ec))) {
+                                       DBG("found exdate(%lld)", lli);
+                                       count++;
+                                       l = g_list_remove(l, lli2p(lli));
+                                       is_skip = true;
+                                       break;
+                               }
+                       }
+                       if (true == is_skip) {
+                               continue;
+                       }
+                       is_exit = __insert_valid_record(ucal, event, duration, dtstart_utime, until_utime, &count);
+                       if (true == is_exit) break;
+               }
+
+               curr_utime = ms2sec(ucal_getMillis(ucal, &ec));
+               if ((last_utime == curr_utime) || (CAL_ENDLESS_LIMIT_FULL_DAY == loop)) {
+                       DBG("current utime is same as last utime, so stoppted");
+                       is_exit = true;
+               } else {
+                       last_utime = curr_utime;
+               }
+               loop++;
+       }
+       g_list_free(l);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_record_monthly(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter:ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+
+       if (event->byday && strlen(event->byday) > 0) {
+               __cal_db_instance_publish_monthly_wday(ucal, event, duration);
+
+       } else {
+               __cal_db_instance_publish_monthly_mday(ucal, event, duration);
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_record_weekly(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter:ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+
+       __cal_db_instance_publish_weekly_wday(ucal, event, duration);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_record_daily(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter:ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+
+       __cal_db_instance_publish_daily_mday(ucal, event, duration);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_record_once(UCalendar *ucal, cal_event_s *event, long long int duration)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter:ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+
+       calendar_time_s *st = &event->start;
+       __set_time_to_ucal(event->system_type, ucal, st);
+       __cal_db_instance_insert_record(ucal, duration, event);//event->start.type, event->index);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_publish_record_details(UCalendar *ucal, cal_event_s *event)
+{
+       retvm_if(NULL == ucal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter:ucal is NULL");
+       retvm_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: event is NULL");
+
+       long long int duration = -1;
+       int exception_freq = 0; // for exception
+
+       __cal_db_instance_get_duration(ucal, &event->start, &event->end, &duration);
+       warn_if (duration < 0, "Invalid duration (%lld)", duration);
+
+       if (event->original_event_id > 0)
+       {
+               DBG("this is exception event so publish only one instance");
+               exception_freq = event->freq;
+               event->freq = CALENDAR_RECURRENCE_NONE;
+       }
+
+       DBG("event interval(%d)", event->interval);
+       if (event->interval < 1)
+       {
+               DBG("Invalid interval, so set 1");
+               event->interval = 1;
+       }
+
+       if (event->bysetpos && event->bysetpos[0] != '\0')
+       {
+               DBG("setpos");
+               __cal_db_instance_publish_record_setpos(ucal, event, duration);
+       }
+       else
+       {
+               DBG("No setpos");
+               switch (event->freq)
+               {
+               case CALENDAR_RECURRENCE_YEARLY:
+                       __cal_db_instance_publish_record_yearly(ucal, event, duration);
+                       break;
+
+               case CALENDAR_RECURRENCE_MONTHLY:
+                       __cal_db_instance_publish_record_monthly(ucal, event, duration);
+                       break;
+
+               case CALENDAR_RECURRENCE_WEEKLY:
+                       __cal_db_instance_publish_record_weekly(ucal, event, duration);
+                       break;
+
+               case CALENDAR_RECURRENCE_DAILY:
+                       __cal_db_instance_publish_record_daily(ucal, event, duration);
+                       break;
+
+               case CALENDAR_RECURRENCE_NONE:
+               default:
+                       __cal_db_instance_publish_record_once(ucal, event, duration);
+                       break;
+
+               }
+       }
+
+       if (event->original_event_id > 0)
+       {
+               DBG("return freq for exception event");
+               event->freq = exception_freq;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_instance_update_exdate_del(int id, char *exdate)
+{
+       int dbret;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char **t = NULL;
+       char *p = NULL;
+
+       if (exdate == NULL || strlen(exdate) == 0)
+       {
+               DBG("Nothing to update exdate del");
+               return CALENDAR_ERROR_NONE;
+       }
+
+       DBG("exdate[%s]", exdate);
+       t = g_strsplit_set(exdate, " ,", -1);
+       if (!t)
+       {
+               ERR("g_strsplit_set failed");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       int i;
+       for (i = 0; t[i]; i++) {
+               if (NULL == t[i] || '\0' == *t[i]) continue;
+
+               int y = 0, m = 0, d = 0;
+               int h = 0, n = 0, s = 0;
+
+               p = t[i];
+               DBG("exdate[%s]", p);
+               int len = strlen(p);
+               switch (len)
+               {
+               case 8: // 20141212
+                       DBG("ALLDAY instance");
+                       sscanf(p, "%04d%02d%02d", &y, &m, &d);
+                       snprintf(query, sizeof(query), "DELETE FROM %s "
+                                       "WHERE event_id = %d AND dtstart_datetime = '%04d-%02d-%02dT%02d:%02d:%02d' ",
+                                       CAL_TABLE_ALLDAY_INSTANCE, id, y, m, d, h, n, s);
+                       break;
+
+               case 15: // 20141212T000000
+                       sscanf(p, "%04d%02d%02dT%02d%02d%02d", &y, &m, &d, &h, &n, &s);
+                       snprintf(query, sizeof(query), "DELETE FROM %s "
+                                       "WHERE event_id = %d AND dtstart_datetime = '%04d-%02d-%02dT%02d:%02d:%02d' ",
+                                       CAL_TABLE_ALLDAY_INSTANCE, id, y, m, d, h, n, s);
+                       DBG("localtime instance");
+                       break;
+
+               case 16: // 20141212T000000Z
+                       sscanf(p, "%04d%02d%02dT%02d%02d%02dZ", &y, &m, &d, &h, &n, &s);
+                       snprintf(query, sizeof(query), "DELETE FROM %s "
+                                       "WHERE event_id = %d AND dtstart_utime = %lld ",
+                                       CAL_TABLE_NORMAL_INSTANCE, id, _cal_time_convert_itol(NULL, y, m, d, h, n, s));
+                       DBG("normal instance (%lld)", _cal_time_convert_itol(NULL, y, m, d, h, n, s));
+                       break;
+               }
+
+               dbret = _cal_db_util_query_exec(query);
+               if (dbret != CAL_DB_OK) {
+                       ERR("[%s]", query);
+                       ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+                       g_strfreev(t);
+                       switch (dbret)
+                       {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+       }
+       g_strfreev(t);
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_instance_publish_record(calendar_record_h record)
+{
+       retvm_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid argument: record is NULL");
+
+       cal_event_s *event = NULL;
+       event = (cal_event_s *)(record);
+
+       UCalendar *ucal = _cal_time_open_ucal(event->system_type,
+                       event->start.type == CALENDAR_TIME_UTIME ? event->start_tzid : NULL,
+                       event->wkst);
+
+       __cal_db_instance_publish_record_details(ucal, event);
+       __cal_db_instance_del_inundant(event->index, &event->start, event);
+       __cal_db_instance_update_exdate_mod(event->original_event_id, event->recurrence_id);
+
+       ucal_close(ucal);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_instance_get_now(long long int *current)
+{
+       *current = ms2sec(ucal_getNow());
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_instance_discard_record(int index)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       DBG("delete normal");
+       snprintf(query, sizeof(query), "DELETE FROM %s WHERE event_id = %d ",
+                       CAL_TABLE_NORMAL_INSTANCE, index);
+
+       dbret = _cal_db_util_query_exec(query);
+       if (CAL_DB_OK != dbret)
+       {
+               DBG("query[%s]", query);
+               ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       DBG("delete allday");
+       snprintf(query, sizeof(query), "DELETE FROM %s WHERE event_id = %d ",
+                       CAL_TABLE_ALLDAY_INSTANCE, index);
+
+       dbret = _cal_db_util_query_exec(query);
+       if (CAL_DB_OK != dbret)
+       {
+               ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
diff --git a/native/cal_db_instance.h b/native/cal_db_instance.h
new file mode 100644 (file)
index 0000000..0439f6f
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_DB_INSTANCE_H__
+#define __CALENDAR_SVC_DB_INSTANCE_H__
+
+int _cal_db_instance_publish_record(calendar_record_h record);
+int _cal_db_instance_discard_record(int index);
+int _cal_db_instance_get_now(long long int *current);
+int _cal_db_instance_update_exdate_del(int id, char *exdate);
+
+#endif // __CALENDAR_SVC_DB_INSTANCE_H__
diff --git a/native/cal_db_instance_helper.c b/native/cal_db_instance_helper.c
new file mode 100755 (executable)
index 0000000..0f70ae9
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "cal_typedef.h"
+#include "cal_db.h"
+#include "cal_db_util.h"
+#include "cal_internal.h"
+#include "calendar_errors.h"
+#include "cal_db_instance_helper.h"
+
+int _cal_db_instance_normal_insert_record(cal_instance_normal_s *normal, int* id)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       retvm_if(NULL == normal, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid argument: cal_instance_normal_s is NULL");
+
+       snprintf(query, sizeof(query),
+                       "INSERT INTO %s ("
+                       "event_id, "
+                       "dtstart_utime, dtend_utime"
+                       ") VALUES ( "
+                       "%d, "
+                       "%lld, %lld) ",
+                       CAL_TABLE_NORMAL_INSTANCE,
+                       normal->event_id,
+                       normal->start.time.utime, normal->end.time.utime);
+
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       dbret = _cal_db_util_query_exec(query);
+       if (dbret != CAL_DB_OK) {
+               ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+               switch (dbret) {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       if (id) *id = _cal_db_util_last_insert_id();
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_instance_allday_insert_record(cal_instance_allday_s *allday, int* id)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       retvm_if(NULL == allday, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid argument: cal_instance_allday_s is NULL");
+
+       snprintf(query, sizeof(query),
+                       "INSERT INTO %s ("
+                       "event_id, "
+                       "dtstart_datetime, dtend_datetime"
+                       ") VALUES ( "
+                       "%d, "
+                       "'%04d-%02d-%02dT%02d:%02d:%02d', '%04d-%02d-%02dT%02d:%02d:%02d') ",
+                       CAL_TABLE_ALLDAY_INSTANCE,
+                       allday->event_id,
+                       allday->start.time.date.year, allday->start.time.date.month, allday->start.time.date.mday,
+                       allday->start.time.date.hour, allday->start.time.date.minute, allday->start.time.date.second,
+                       allday->end.time.date.year, allday->end.time.date.month, allday->end.time.date.mday,
+                       allday->end.time.date.hour, allday->end.time.date.minute, allday->end.time.date.second);
+
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       dbret = _cal_db_util_query_exec(query);
+       if (dbret != CAL_DB_OK) {
+               ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+               switch (dbret) {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       if (id) *id = _cal_db_util_last_insert_id();
+
+       return CALENDAR_ERROR_NONE;
+}
+
diff --git a/native/cal_db_instance_helper.h b/native/cal_db_instance_helper.h
new file mode 100755 (executable)
index 0000000..8d66f51
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_DB_INSTANCE_HELPER_H__
+#define __CALENDAR_SVC_DB_INSTANCE_HELPER_H__
+
+int _cal_db_instance_normal_insert_record(cal_instance_normal_s *normal, int* id);
+int _cal_db_instance_allday_insert_record(cal_instance_allday_s *normal, int* id);
+
+#endif // __CALENDAR_SVC_DB_INSTANCE_HELPER_H__
diff --git a/native/cal_db_plugin_alarm.c b/native/cal_db_plugin_alarm.c
new file mode 100644 (file)
index 0000000..c743766
--- /dev/null
@@ -0,0 +1,517 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#ifdef CAL_NATIVE
+#include <alarm.h>
+#endif
+
+#include "calendar_db.h"
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_time.h"
+#include "cal_record.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_db_query.h"
+#include "cal_db_instance.h"
+#include "cal_db_alarm.h"
+
+//static int __cal_db_alarm_get_record(int id, calendar_record_h* out_record);
+static int __cal_db_alarm_get_all_records(int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_alarm_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_alarm_get_count(int *out_count);
+static int __cal_db_alarm_get_count_with_query(calendar_query_h query, int *out_count);
+
+cal_db_plugin_cb_s _cal_db_alarm_plugin_cb = {
+       .is_query_only = false,
+       .insert_record=NULL,
+       .get_record=NULL,                       //__cal_db_alarm_get_record,
+       .update_record=NULL,
+       .delete_record=NULL,
+       .get_all_records=__cal_db_alarm_get_all_records,
+       .get_records_with_query=__cal_db_alarm_get_records_with_query,
+       .insert_records=NULL,
+       .update_records=NULL,
+       .delete_records=NULL,
+       .get_count=__cal_db_alarm_get_count,
+       .get_count_with_query=__cal_db_alarm_get_count_with_query,
+       .replace_record=NULL,
+       .replace_records=NULL
+};
+
+static void __cal_db_alarm_get_stmt(sqlite3_stmt *stmt,calendar_record_h record)
+{
+       cal_alarm_s *alarm = NULL;
+       int index;
+       const unsigned char *temp;
+
+       alarm = (cal_alarm_s*)(record);
+
+       index = 0;
+       alarm->parent_id = sqlite3_column_int(stmt, index++);
+       alarm->remind_tick = sqlite3_column_int(stmt, index++);
+       alarm->remind_tick_unit = sqlite3_column_int(stmt, index++);
+
+       temp = sqlite3_column_text(stmt, index++);
+       alarm->alarm_description = SAFE_STRDUP(temp);
+
+       alarm->alarm.type = sqlite3_column_int(stmt, index++);
+       index++; // alarm_id
+       temp = sqlite3_column_text(stmt, index++);
+       alarm->alarm_summary = SAFE_STRDUP(temp);
+
+       alarm->alarm_action = sqlite3_column_int(stmt, index++);
+
+       temp = sqlite3_column_text(stmt, index++);
+       alarm->alarm_attach = SAFE_STRDUP(temp);
+
+       if (alarm->alarm.type == CALENDAR_TIME_UTIME)
+       {
+               alarm->alarm.time.utime = sqlite3_column_int64(stmt,index++);
+               index++; // datetime
+       }
+       else
+       {
+               index++; // utime
+               temp = sqlite3_column_text(stmt, index++);
+               if (temp) {
+                       int y = 0, m = 0, d = 0;
+                       int h = 0, n = 0, s = 0;
+                       switch (strlen((const char *)temp))
+                       {
+                       case 8:
+                               sscanf((const char *)temp, "%04d%02d%02d", &y, &m, &d);
+                               alarm->alarm.time.date.year = y;
+                               alarm->alarm.time.date.month = m;
+                               alarm->alarm.time.date.mday = d;
+                               break;
+
+                       case 15:
+                               sscanf((const char *)temp, "%04d%02d%02dT%02d%02d%02d", &y, &m, &d, &h, &n, &s);
+                               alarm->alarm.time.date.year = y;
+                               alarm->alarm.time.date.month = m;
+                               alarm->alarm.time.date.mday = d;
+                               alarm->alarm.time.date.hour = h;
+                               alarm->alarm.time.date.minute = n;
+                               alarm->alarm.time.date.second = s;
+                               break;
+                       }
+               }
+       }
+       alarm->id = sqlite3_column_int(stmt, index++);
+}
+
+static int __cal_db_alarm_get_all_records(int offset, int limit, calendar_list_h* out_list )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char offsetquery[CAL_DB_SQL_MAX_LEN] = {0};
+       char limitquery[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = calendar_list_create(out_list);
+
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       if (offset > 0) {
+               snprintf(offsetquery, sizeof(offsetquery), "OFFSET %d", offset);
+       }
+       if (limit > 0) {
+               snprintf(limitquery, sizeof(limitquery), "LIMIT %d", limit);
+       }
+       snprintf(query, sizeof(query), "SELECT *, rowid FROM %s %s %s",
+                       CAL_TABLE_ALARM,limitquery,offsetquery);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_list_destroy(*out_list, true);
+               *out_list = NULL;
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               calendar_record_h record = NULL;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_alarm._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE ) {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+               __cal_db_alarm_get_stmt(stmt,record);
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE ) {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+       }
+       sqlite3_finalize(stmt);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_db_alarm_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record)
+{
+       cal_alarm_s *alarm = NULL;
+       const unsigned char *temp;
+
+       alarm = (cal_alarm_s*)(record);
+
+       switch(property) {
+       case CAL_PROPERTY_ALARM_TICK:
+               alarm->remind_tick = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_ALARM_TICK_UNIT:
+               alarm->remind_tick_unit = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_ALARM_DESCRIPTION:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               alarm->alarm_description = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_ALARM_PARENT_ID:
+               alarm->parent_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_ALARM_SUMMARY:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               alarm->alarm_summary = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_ALARM_ACTION:
+               alarm->alarm_action = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_ALARM_ATTACH:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               alarm->alarm_attach = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_ALARM_ALARM:
+               alarm->alarm.type = sqlite3_column_int(stmt, *stmt_count);
+               if (alarm->alarm.type == CALENDAR_TIME_UTIME) {
+                       *stmt_count = *stmt_count+1;
+                       alarm->alarm.time.utime = sqlite3_column_int64(stmt, *stmt_count);
+                       *stmt_count = *stmt_count+1;
+                       sqlite3_column_text(stmt, *stmt_count);  //alarm_datetime
+
+               } else {
+                       *stmt_count = *stmt_count+1; // utime
+                       *stmt_count = *stmt_count+1;
+                       temp = sqlite3_column_text(stmt, *stmt_count);
+                       if (temp) {
+                               int y = 0, m = 0, d = 0;
+                               int h = 0, n = 0, s = 0;
+                               switch (strlen((const char *)temp))
+                               {
+                               case 8:
+                                       sscanf((const char *)temp, "%04d%02d%02d", &y, &m, &d);
+                                       alarm->alarm.time.date.year = y;
+                                       alarm->alarm.time.date.month = m;
+                                       alarm->alarm.time.date.mday = d;
+                                       break;
+
+                               case 15:
+                                       sscanf((const char *)temp, "%04d%02d%02dT%02d%02d%02d", &y, &m, &d, &h, &n, &s);
+                                       alarm->alarm.time.date.year = y;
+                                       alarm->alarm.time.date.month = m;
+                                       alarm->alarm.time.date.mday = d;
+                                       alarm->alarm.time.date.hour = h;
+                                       alarm->alarm.time.date.minute = n;
+                                       alarm->alarm.time.date.second = s;
+                                       break;
+                               }
+                       }
+               }
+               break;
+       default:
+               sqlite3_column_int(stmt, *stmt_count);
+               break;
+       }
+
+       *stmt_count = *stmt_count+1;
+}
+
+static void __cal_db_alarm_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record)
+{
+       int i=0;
+       int stmt_count = 0;
+
+       for(i=0;i<projection_count;i++)
+               __cal_db_alarm_get_property_stmt(stmt,projection[i],&stmt_count,record);
+}
+
+static int __cal_db_alarm_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list )
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *projection = NULL;
+       char *order = NULL;
+       GSList *bind_text = NULL, *cursor = NULL;
+       char *query_str = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int i = 0;
+       char *table_name;
+
+       que = (cal_query_s *)query;
+
+       if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_ALARM)) {
+               table_name = SAFE_STRDUP(CAL_TABLE_ALARM);
+       }
+       else {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+               //table_name = SAFE_STRDUP(CAL_TABLE_NORMAL_INSTANCE);
+       }
+
+       // make filter
+       if (que->filter) {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE) {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // make projection
+       ret = _cal_db_query_create_projection(query, &projection);
+
+       // query - projection
+       if (projection) {
+               _cal_db_append_string(&query_str, "SELECT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, "FROM");
+               _cal_db_append_string(&query_str, table_name);
+               CAL_FREE(projection);
+       }
+       else {
+               _cal_db_append_string(&query_str, "SELECT *, rowid FROM ");
+               _cal_db_append_string(&query_str, table_name);
+       }
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition) {
+               _cal_db_append_string(&query_str, "WHERE");
+               _cal_db_append_string(&query_str, condition);
+               CAL_FREE(condition);
+       }
+
+       // ORDER
+       ret = _cal_db_query_create_order(query, condition, &order);
+       if (order) {
+               _cal_db_append_string(&query_str, order);
+               CAL_FREE(order);
+       }
+
+       char buf[32] = {0};
+       if (0 < limit) {
+               snprintf(buf, sizeof(buf), "LIMIT %d", limit);
+               _cal_db_append_string(&query_str, buf);
+               if (0 < offset) {
+                       snprintf(buf, sizeof(buf), "OFFSET %d", offset);
+                       _cal_db_append_string(&query_str, buf);
+               }
+       }
+
+       // query
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt) {
+               CAL_DBG("%s",query_str);
+               if (bind_text) {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       // bind text
+       if (bind_text)  {
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++) {
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+               }
+       }
+
+       ret = calendar_list_create(out_list);
+       if (ret != CALENDAR_ERROR_NONE) {
+               if (bind_text) {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("calendar_list_create() Failed");
+               sqlite3_finalize(stmt);
+               return ret;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_alarm._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE ) {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+
+                       if (bind_text) {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       CAL_FREE(query_str);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+               if (que->projection_count > 0) {
+                       _cal_record_set_projection(record,
+                                       que->projection, que->projection_count, que->property_count);
+
+                       __cal_db_alarm_get_projection_stmt(stmt,
+                                       que->projection, que->projection_count,
+                                       record);
+               }
+               else {
+                       __cal_db_alarm_get_stmt(stmt,record);
+               }
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE ) {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+
+                       if (bind_text) {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       CAL_FREE(query_str);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+       }
+
+       if (bind_text) {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       CAL_FREE(query_str);
+
+       sqlite3_finalize(stmt);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_alarm_get_count(int *out_count)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       int count = 0;
+       int ret;
+
+       retvm_if(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       snprintf(query, sizeof(query), "SELECT count(*) FROM %s ", CAL_TABLE_ALARM);
+
+       ret = _cal_db_util_query_get_first_int_result(query, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               return ret;
+       }
+       CAL_DBG("%s=%d",query,count);
+
+       *out_count = count;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_alarm_get_count_with_query(calendar_query_h query, int *out_count)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *table_name;
+       int count = 0;
+       GSList *bind_text = NULL;
+
+       que = (cal_query_s *)query;
+
+       if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_ALARM))   {
+               table_name = SAFE_STRDUP(CAL_TABLE_ALARM);
+       }
+       else {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       // make filter
+       if (que->filter) {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE) {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       char *query_str = NULL;
+       // query - select from
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, table_name);
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition) {
+               _cal_db_append_string(&query_str, "WHERE");
+               _cal_db_append_string(&query_str, condition);
+               CAL_FREE(condition);
+       }
+
+       // query
+       ret = _cal_db_util_query_get_first_int_result(query_str, bind_text, &count);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               if (bind_text) {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("%s=%d",query_str,count);
+
+       *out_count = count;
+
+       if (bind_text) {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
diff --git a/native/cal_db_plugin_attendee.c b/native/cal_db_plugin_attendee.c
new file mode 100644 (file)
index 0000000..31750dc
--- /dev/null
@@ -0,0 +1,482 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+
+#include "cal_db_util.h"
+#include "cal_db_query.h"
+#include "cal_db_attendee.h"
+
+static int __cal_db_attendee_get_all_records(int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_attendee_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_attendee_get_count(int *out_count);
+static int __cal_db_attendee_get_count_with_query(calendar_query_h query, int *out_count);
+// static int __cal_db_attendee_get_record(int id, calendar_record_h* out_record)
+
+cal_db_plugin_cb_s _cal_db_attendee_plugin_cb = {
+       .is_query_only = false,
+       .insert_record=NULL,
+       .get_record=NULL,               // __cal_db_attendee_get_record
+       .update_record=NULL,
+       .delete_record=NULL,
+       .get_all_records=__cal_db_attendee_get_all_records,
+       .get_records_with_query=__cal_db_attendee_get_records_with_query,
+       .insert_records=NULL,
+       .update_records=NULL,
+       .delete_records=NULL,
+       .get_count=__cal_db_attendee_get_count,
+       .get_count_with_query=__cal_db_attendee_get_count_with_query,
+       .replace_record=NULL,
+       .replace_records=NULL
+};
+
+static void __cal_db_attendee_get_stmt(sqlite3_stmt *stmt,calendar_record_h record)
+{
+       cal_attendee_s *attendee = NULL;
+       int index;
+       const unsigned char *temp;
+
+       attendee = (cal_attendee_s*)(record);
+       index = 0;
+
+       attendee->parent_id = sqlite3_column_int(stmt, index++);
+
+       temp = sqlite3_column_text(stmt, index++);
+       attendee->attendee_name = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, index++);
+       attendee->attendee_email = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, index++);
+       attendee->attendee_number = SAFE_STRDUP(temp);
+
+       attendee->attendee_status = sqlite3_column_int(stmt, index++);
+       attendee->attendee_ct_index = sqlite3_column_int(stmt, index++);
+       attendee->attendee_role = sqlite3_column_int(stmt, index++);
+       attendee->attendee_rsvp = sqlite3_column_int(stmt, index++);
+
+       temp = sqlite3_column_text(stmt, index++);
+       attendee->attendee_group = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, index++);
+       attendee->attendee_delegator_uri = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, index++);
+       attendee->attendee_uid = SAFE_STRDUP(temp);
+
+       attendee->attendee_cutype = sqlite3_column_int(stmt, index++);
+
+       temp = sqlite3_column_text(stmt, index++);
+       attendee->attendee_delegatee_uri = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, index++);
+       attendee->attendee_member = SAFE_STRDUP(temp);
+
+       attendee->id = sqlite3_column_int(stmt, index++);
+}
+
+static int __cal_db_attendee_get_all_records(int offset, int limit, calendar_list_h* out_list)
+{
+       int ret;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char offsetquery[CAL_DB_SQL_MAX_LEN] = {0};
+       char limitquery[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter: calendar_list_h is NULL");
+       ret = calendar_list_create(out_list);
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_DB_FAILED,
+                       "calendar_list_create() failed");
+
+       if (limit > 0)  {
+               snprintf(limitquery, sizeof(limitquery), "LIMIT %d ", limit);
+       }
+       if (offset > 0) {
+               snprintf(offsetquery, sizeof(offsetquery), "OFFSET %d ", offset);
+       }
+       snprintf(query, sizeof(query), "SELECT *, rowid FROM %s %s %s ",
+                       CAL_TABLE_ATTENDEE, limitquery, offsetquery);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)       {
+               ERR("_cal_db_util_query_prepare() failed");
+               calendar_list_destroy(*out_list, true);
+               *out_list = NULL;
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       calendar_record_h record = NULL;
+
+       while (CAL_DB_ROW == _cal_db_util_stmt_step(stmt))      {
+               ret = calendar_record_create(_calendar_attendee._uri, &record);
+               if (CALENDAR_ERROR_NONE != ret) {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+               //
+               __cal_db_attendee_get_stmt(stmt,record);
+
+               ret = calendar_list_add(*out_list, record);
+               if (CALENDAR_ERROR_NONE != ret) {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+       }
+       sqlite3_finalize(stmt);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_db_attendee_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record)
+{
+       cal_attendee_s *attendee = NULL;
+       const unsigned char *temp;
+
+       attendee = (cal_attendee_s*)(record);
+
+       switch(property) {
+       case CAL_PROPERTY_ATTENDEE_NUMBER:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               attendee->attendee_number = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_ATTENDEE_CUTYPE:
+               attendee->attendee_cutype = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_ATTENDEE_CT_INDEX:
+               attendee->attendee_ct_index = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_ATTENDEE_UID:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               attendee->attendee_uid = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_ATTENDEE_GROUP:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               attendee->attendee_group = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_ATTENDEE_EMAIL:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               attendee->attendee_email = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_ATTENDEE_ROLE:
+               attendee->attendee_role = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_ATTENDEE_STATUS:
+               attendee->attendee_status = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_ATTENDEE_RSVP:
+               attendee->attendee_rsvp = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_ATTENDEE_DELEGATEE_URI:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               attendee->attendee_delegatee_uri = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_ATTENDEE_DELEGATOR_URI:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               attendee->attendee_delegator_uri = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_ATTENDEE_NAME:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               attendee->attendee_name = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_ATTENDEE_MEMBER:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               attendee->attendee_member = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_ATTENDEE_PARENT_ID:
+               attendee->parent_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       default:
+               sqlite3_column_int(stmt, *stmt_count);
+               break;
+       }
+       *stmt_count = *stmt_count+1;
+}
+
+static void __cal_db_attendee_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record)
+{
+       int i=0;
+       int stmt_count = 0;
+
+       for(i=0;i<projection_count;i++)
+               __cal_db_attendee_get_property_stmt(stmt,projection[i],&stmt_count,record);
+}
+
+static int __cal_db_attendee_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *projection = NULL;
+       char *order = NULL;
+       GSList *bind_text = NULL, *cursor = NULL;
+       char *query_str = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int i = 0;
+       char *table_name;
+
+       que = (cal_query_s *)query;
+
+       if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_ATTENDEE)) {
+               table_name = SAFE_STRDUP(CAL_TABLE_ATTENDEE);
+       }
+       else {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+               //table_name = SAFE_STRDUP(CAL_TABLE_NORMAL_INSTANCE);
+       }
+
+       // make filter
+       if (que->filter) {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE) {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // make projection
+       ret = _cal_db_query_create_projection(query, &projection);
+
+       // query - projection
+       if (projection) {
+               _cal_db_append_string(&query_str, "SELECT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, "FROM");
+               _cal_db_append_string(&query_str, table_name);
+               CAL_FREE(projection);
+       }
+       else {
+               _cal_db_append_string(&query_str, "SELECT *, rowid FROM ");
+               _cal_db_append_string(&query_str, table_name);
+       }
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition) {
+               _cal_db_append_string(&query_str, "WHERE");
+               _cal_db_append_string(&query_str, condition);
+               CAL_FREE(condition);
+       }
+
+       // ORDER
+       ret = _cal_db_query_create_order(query, condition, &order);
+       if (order) {
+               _cal_db_append_string(&query_str, order);
+               CAL_FREE(order);
+       }
+
+       char buf[32] = {0};
+       if (0 < limit) {
+               snprintf(buf, sizeof(buf), "LIMIT %d", limit);
+               _cal_db_append_string(&query_str, buf);
+               if (0 < offset) {
+                       snprintf(buf, sizeof(buf), "OFFSET %d", offset);
+                       _cal_db_append_string(&query_str, buf);
+               }
+       }
+
+       // query
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt) {
+               if (bind_text) {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       CAL_DBG("%s",query_str);
+
+       // bind text
+       if (bind_text)  {
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+       }
+
+       //
+       ret = calendar_list_create(out_list);
+       if (ret != CALENDAR_ERROR_NONE) {
+               if (bind_text) {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("calendar_list_create() Failed");
+               sqlite3_finalize(stmt);
+               return ret;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_attendee._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE ) {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+
+                       if (bind_text) {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       CAL_FREE(query_str);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+               if (que->projection_count > 0) {
+                       _cal_record_set_projection(record,
+                                       que->projection, que->projection_count, que->property_count);
+
+                       __cal_db_attendee_get_projection_stmt(stmt,
+                                       que->projection, que->projection_count,
+                                       record);
+               }
+               else {
+                       __cal_db_attendee_get_stmt(stmt,record);
+               }
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE ) {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+
+                       if (bind_text) {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       CAL_FREE(query_str);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+       }
+
+       if (bind_text) {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       CAL_FREE(query_str);
+       sqlite3_finalize(stmt);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_attendee_get_count(int *out_count)
+{
+       int ret;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       int count = 0;
+
+       retvm_if(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       snprintf(query, sizeof(query), "SELECT count(*) FROM %s ", CAL_TABLE_ATTENDEE);
+
+       ret = _cal_db_util_query_get_first_int_result(query, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               return ret;
+       }
+       CAL_DBG("%s=%d",query,count);
+
+       *out_count = count;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_attendee_get_count_with_query(calendar_query_h query, int *out_count)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *query_str = NULL;
+       char *table_name;
+       int count = 0;
+       GSList *bind_text = NULL;
+
+       que = (cal_query_s *)query;
+
+       if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_ATTENDEE)) {
+               table_name = SAFE_STRDUP(CAL_TABLE_ATTENDEE);
+       }
+       else {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       // make filter
+       if (que->filter) {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE) {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // query - select from
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, table_name);
+       CAL_FREE(table_name);
+
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition) {
+               _cal_db_append_string(&query_str, "WHERE");
+               _cal_db_append_string(&query_str, condition);
+               CAL_FREE(condition);
+       }
+
+       // query
+       ret = _cal_db_util_query_get_first_int_result(query_str, bind_text, &count);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               if (bind_text) {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("%s=%d",query_str,count);
+
+       *out_count = count;
+
+       if (bind_text) {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
diff --git a/native/cal_db_plugin_calendar.c b/native/cal_db_plugin_calendar.c
new file mode 100644 (file)
index 0000000..2e9060b
--- /dev/null
@@ -0,0 +1,1154 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+
+#include "cal_db.h"
+#include "cal_db_util.h"
+#include "cal_db_query.h"
+#include "cal_access_control.h"
+
+#ifdef CAL_IPC_SERVER
+#include "cal_server_calendar_delete.h"
+#endif
+#include "cal_access_control.h"
+
+/*
+ * db plugin function
+ */
+static int __cal_db_calendar_insert_record( calendar_record_h record, int* id );
+static int __cal_db_calendar_get_record( int id, calendar_record_h* out_record );
+static int __cal_db_calendar_update_record( calendar_record_h record );
+static int __cal_db_calendar_delete_record( int id );
+static int __cal_db_calendar_get_all_records( int offset, int limit, calendar_list_h* out_list );
+static int __cal_db_calendar_get_records_with_query( calendar_query_h query, int offset, int limit, calendar_list_h* out_list );
+static int __cal_db_calendar_insert_records(const calendar_list_h list, int** ids);
+static int __cal_db_calendar_update_records(const calendar_list_h list);
+static int __cal_db_calendar_delete_records(int ids[], int count);
+static int __cal_db_calendar_get_count(int *out_count);
+static int __cal_db_calendar_get_count_with_query(calendar_query_h query, int *out_count);
+static int __cal_db_calendar_replace_record(calendar_record_h record, int id);
+static int __cal_db_calendar_replace_records(const calendar_list_h list, int ids[], int count);
+
+/*
+ * static function
+ */
+static void __cal_db_calendar_get_stmt(sqlite3_stmt *stmt,calendar_record_h record);
+static void __cal_db_calendar_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int stmt_count, calendar_record_h record);
+static void __cal_db_calendar_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record);
+static int __cal_db_calendar_update_projection(calendar_record_h record);
+
+cal_db_plugin_cb_s _cal_db_calendar_plugin_cb = {
+       .is_query_only=false,
+       .insert_record=__cal_db_calendar_insert_record,
+       .get_record=__cal_db_calendar_get_record,
+       .update_record=__cal_db_calendar_update_record,
+       .delete_record=__cal_db_calendar_delete_record,
+       .get_all_records=__cal_db_calendar_get_all_records,
+       .get_records_with_query=__cal_db_calendar_get_records_with_query,
+       .insert_records=__cal_db_calendar_insert_records,
+       .update_records=__cal_db_calendar_update_records,
+       .delete_records=__cal_db_calendar_delete_records,
+       .get_count=__cal_db_calendar_get_count,
+       .get_count_with_query=__cal_db_calendar_get_count_with_query,
+       .replace_record = __cal_db_calendar_replace_record,
+       .replace_records = __cal_db_calendar_replace_records
+};
+
+static bool __cal_db_calendar_check_value_validation(cal_calendar_s* calendar)
+{
+       retvm_if (NULL == calendar, CALENDAR_ERROR_INVALID_PARAMETER, "calendar is NULL");
+
+       switch (calendar->store_type) {
+       case CALENDAR_BOOK_TYPE_NONE:
+       case CALENDAR_BOOK_TYPE_EVENT:
+       case CALENDAR_BOOK_TYPE_TODO:
+               return true;
+
+       default:
+               ERR("store type is invalid(%d)", calendar->store_type);
+               return false;
+       }
+       return true;
+}
+
+static int __cal_db_calendar_insert_record( calendar_record_h record, int* id )
+{
+       char query[CAL_DB_SQL_MAX_LEN];
+       int index = 0;
+       sqlite3_stmt *stmt;
+       cal_calendar_s* calendar =  (cal_calendar_s*)(record);
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       char *client_label = NULL;
+
+       // !! error check
+       retv_if(NULL == calendar, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (false == __cal_db_calendar_check_value_validation(calendar)) {
+               ERR("_cal_db_calendar_check_value_validation() is failed");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       client_label = _cal_access_control_get_label();
+
+       snprintf(query, sizeof(query), "INSERT INTO %s(uid,updated,name,description,"
+                       "color,location,"
+                       "visibility,"
+                       "sync_event,"
+                       "account_id,store_type,sync_data1,sync_data2,sync_data3,sync_data4,"
+                       "mode, owner_label) "
+                       "VALUES( ?, %ld, ?, ?, ?, ?, %d, %d, %d, %d"
+                       ", ?, ?, ?, ?"
+                       ", %d, ?)",
+                       CAL_TABLE_CALENDAR,
+                       //calendar->uid,
+                       calendar->updated,
+                       //calendar->name,
+                       //calendar->description,
+                       //calendar->color,
+                       //calendar->location,
+                       calendar->visibility,
+                       calendar->sync_event,
+                       calendar->account_id,
+                       calendar->store_type,
+                       calendar->mode);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt) {
+               ERR("_cal_db_util_query_prepare() Failed");
+               CAL_FREE(client_label);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       if (calendar->uid)
+               _cal_db_util_stmt_bind_text(stmt, 1, calendar->uid);
+
+       if (calendar->name)
+               _cal_db_util_stmt_bind_text(stmt, 2, calendar->name);
+
+       if (calendar->description)
+               _cal_db_util_stmt_bind_text(stmt, 3, calendar->description);
+
+       if (calendar->color)
+               _cal_db_util_stmt_bind_text(stmt, 4, calendar->color);
+
+       if (calendar->location)
+               _cal_db_util_stmt_bind_text(stmt, 5, calendar->location);
+
+       // sync1~4
+       if (calendar->sync_data1)
+               _cal_db_util_stmt_bind_text(stmt, 6, calendar->sync_data1 );
+       if (calendar->sync_data2)
+               _cal_db_util_stmt_bind_text(stmt, 7, calendar->sync_data2 );
+       if (calendar->sync_data3)
+               _cal_db_util_stmt_bind_text(stmt, 8, calendar->sync_data3 );
+       if (calendar->sync_data4)
+               _cal_db_util_stmt_bind_text(stmt, 9, calendar->sync_data4 );
+
+       if (client_label)
+               _cal_db_util_stmt_bind_text(stmt, 10, client_label );
+
+       dbret = _cal_db_util_stmt_step(stmt);
+
+       if (CAL_DB_DONE != dbret) {
+               sqlite3_finalize(stmt);
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+               CAL_FREE(client_label);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       index = _cal_db_util_last_insert_id();
+       sqlite3_finalize(stmt);
+       CAL_FREE(client_label);
+       // access control
+       _cal_access_control_reset();
+
+       //_cal_record_set_int(record, _calendar_book.id,index);
+       if (id)
+       {
+               *id = index;
+       }
+
+       _cal_db_util_notify(CAL_NOTI_TYPE_CALENDAR);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_calendar_get_record( int id, calendar_record_h* out_record )
+{
+       char query[CAL_DB_SQL_MAX_LEN];
+       sqlite3_stmt *stmt = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int ret = 0;
+
+       ret = calendar_record_create(_calendar_book._uri ,out_record);
+       if (ret != CALENDAR_ERROR_NONE) {
+               ERR("record create fail");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       snprintf(query, sizeof(query), "SELECT * FROM %s WHERE id=%d "
+                       "AND (deleted = 0)",
+                       CAL_TABLE_CALENDAR,     id);
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() Failed");
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (dbret != CAL_DB_ROW) {
+               ERR("Failed to step stmt(%d)", dbret);
+               sqlite3_finalize(stmt);
+               switch (dbret) {
+               case CAL_DB_DONE:
+                       return CALENDAR_ERROR_DB_RECORD_NOT_FOUND;
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       __cal_db_calendar_get_stmt(stmt, *out_record);
+
+       sqlite3_finalize(stmt);
+       stmt = NULL;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_calendar_update_record( calendar_record_h record )
+{
+       //int rc = -1;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_calendar_s* calendar =  (cal_calendar_s*)(record);
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       retv_if(NULL == calendar, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (false == __cal_db_calendar_check_value_validation(calendar)) {
+               ERR("_cal_db_calendar_check_value_validation() is failed");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (calendar->common.properties_flags != NULL) {
+               return __cal_db_calendar_update_projection(record);
+       }
+
+       snprintf(query, sizeof(query), "UPDATE %s SET "
+                       "updated = %ld,"
+                       "name = ?,"
+                       "description = ?,"
+                       "color = ?,"
+                       "location = ?,"
+                       "visibility = %d,"
+                       "sync_event = %d,"
+                       "account_id = %d,"
+                       "store_type = %d, "
+                       "sync_data1 = ?, "
+                       "sync_data2 = ?, "
+                       "sync_data3 = ?, "
+                       "sync_data4 = ?,"
+                       "mode = %d "
+                       "WHERE id = %d",
+                       CAL_TABLE_CALENDAR,
+                       calendar->updated,
+                       calendar->visibility,
+                       calendar->sync_event,
+                       calendar->account_id,
+                       calendar->store_type,
+                       calendar->mode,
+                       calendar->index);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() Failed");
+
+       if (calendar->name)
+               _cal_db_util_stmt_bind_text(stmt, 1, calendar->name);
+
+       if (calendar->description)
+               _cal_db_util_stmt_bind_text(stmt, 2, calendar->description);
+
+       if (calendar->color)
+               _cal_db_util_stmt_bind_text(stmt, 3, calendar->color);
+
+       if (calendar->location)
+               _cal_db_util_stmt_bind_text(stmt, 4, calendar->location);
+
+       // sync_data1~4
+       if (calendar->sync_data1)
+               _cal_db_util_stmt_bind_text(stmt, 5, calendar->sync_data1);
+       if (calendar->sync_data2)
+               _cal_db_util_stmt_bind_text(stmt, 6, calendar->sync_data2);
+       if (calendar->sync_data3)
+               _cal_db_util_stmt_bind_text(stmt, 7, calendar->sync_data3);
+       if (calendar->sync_data4)
+               _cal_db_util_stmt_bind_text(stmt, 8, calendar->sync_data4);
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret) {
+               sqlite3_finalize(stmt);
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+               switch (dbret) {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       sqlite3_finalize(stmt);
+
+       _cal_db_util_notify(CAL_NOTI_TYPE_CALENDAR);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_calendar_delete_record( int id )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int calendar_book_id = -1;
+
+       snprintf(query, sizeof(query), "SELECT id FROM %s WHERE id = %d",
+                       CAL_TABLE_CALENDAR, id);
+       ret = _cal_db_util_query_get_first_int_result(query, NULL, &calendar_book_id);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_db_util_query_get_first_int_result(%d) failed", ret);
+               return ret;
+       }
+
+#ifdef CAL_IPC_SERVER
+       int count = 0;
+       int count2 = 0;
+       // get instance count
+       snprintf(query, sizeof(query), "select count(*) from %s",
+                       CAL_TABLE_NORMAL_INSTANCE);
+       ret = _cal_db_util_query_get_first_int_result(query, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               return ret;
+       }
+
+       snprintf(query, sizeof(query), "select count(*) from %s",
+                       CAL_TABLE_ALLDAY_INSTANCE);
+       ret = _cal_db_util_query_get_first_int_result(query,NULL, &count2);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               return ret;
+       }
+
+       count += count2;
+
+       if( count > 1000 )
+       {
+               snprintf(query, sizeof(query), "UPDATE %s SET deleted = 1 WHERE id = %d",
+                               CAL_TABLE_CALENDAR, id);
+               dbret = _cal_db_util_query_exec(query);
+               if (CAL_DB_OK != dbret)
+               {
+                       ERR("_cal_db_util_query_exec() Failed(%d)", dbret);
+                       switch (dbret)
+                       {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+               _cal_server_calendar_delete_start();
+       }
+       else
+       {
+#endif
+               snprintf(query, sizeof(query), "DELETE FROM %s WHERE id = %d",
+                               CAL_TABLE_CALENDAR, id);
+               dbret = _cal_db_util_query_exec(query);
+               if (CAL_DB_OK != dbret)
+               {
+                       ERR("_cal_db_util_query_exec() Failed(%d)", dbret);
+                       switch (dbret)
+                       {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+
+               snprintf(query, sizeof(query), "DELETE FROM %s WHERE calendar_id = %d",
+                               CAL_TABLE_SCHEDULE, id);
+               dbret = _cal_db_util_query_exec(query);
+               if (CAL_DB_OK != dbret) {
+                       ERR("_cal_db_util_query_exec() Failed(%d)", dbret);
+                       switch (dbret)
+                       {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+#ifdef CAL_IPC_SERVER
+       }
+#endif
+
+       snprintf(query, sizeof(query), "DELETE FROM %s WHERE calendar_id = %d",
+                       CAL_TABLE_DELETED, id);
+       dbret = _cal_db_util_query_exec(query);
+       if (CAL_DB_OK != dbret) {
+               ERR("_cal_db_util_query_exec() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       // access control
+       _cal_access_control_reset();
+
+       _cal_db_util_notify(CAL_NOTI_TYPE_CALENDAR);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_calendar_replace_record(calendar_record_h record, int id)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_calendar_s* calendar =  (cal_calendar_s*)(record);
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       retv_if(NULL == calendar, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (false == __cal_db_calendar_check_value_validation(calendar)) {
+               ERR("_cal_db_calendar_check_value_validation() is failed");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       calendar->index = id;
+       if (calendar->common.properties_flags != NULL) {
+               return __cal_db_calendar_update_projection(record);
+       }
+
+       snprintf(query, sizeof(query), "UPDATE %s SET "
+                       "updated = %ld,"
+                       "name = ?,"
+                       "description = ?,"
+                       "color = ?,"
+                       "location = ?,"
+                       "visibility = %d,"
+                       "sync_event = %d,"
+                       "account_id = %d,"
+                       "store_type = %d, "
+                       "sync_data1 = ?, "
+                       "sync_data2 = ?, "
+                       "sync_data3 = ?, "
+                       "sync_data4 = ?, "
+                       "mode = %d "
+                       "WHERE id = %d",
+                       CAL_TABLE_CALENDAR,
+                       calendar->updated,
+                       calendar->visibility,
+                       calendar->sync_event,
+                       calendar->account_id,
+                       calendar->store_type,
+                       calendar->mode,
+                       id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() Failed");
+
+       if (calendar->name)
+               _cal_db_util_stmt_bind_text(stmt, 1, calendar->name);
+
+       if (calendar->description)
+               _cal_db_util_stmt_bind_text(stmt, 2, calendar->description);
+
+       if (calendar->color)
+               _cal_db_util_stmt_bind_text(stmt, 3, calendar->color);
+
+       if (calendar->location)
+               _cal_db_util_stmt_bind_text(stmt, 4, calendar->location);
+
+       // sync_data1~4
+       if (calendar->sync_data1)
+               _cal_db_util_stmt_bind_text(stmt, 5, calendar->sync_data1);
+       if (calendar->sync_data2)
+               _cal_db_util_stmt_bind_text(stmt, 6, calendar->sync_data2);
+       if (calendar->sync_data3)
+               _cal_db_util_stmt_bind_text(stmt, 7, calendar->sync_data3);
+       if (calendar->sync_data4)
+               _cal_db_util_stmt_bind_text(stmt, 8, calendar->sync_data4);
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret) {
+               sqlite3_finalize(stmt);
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+               switch (dbret) {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       sqlite3_finalize(stmt);
+
+       _cal_db_util_notify(CAL_NOTI_TYPE_CALENDAR);
+       return CALENDAR_ERROR_NONE;
+}
+
+
+static int __cal_db_calendar_get_all_records( int offset, int limit, calendar_list_h* out_list )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char offsetquery[CAL_DB_SQL_MAX_LEN] = {0};
+       char limitquery[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = calendar_list_create(out_list);
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       if (offset > 0) {
+               snprintf(offsetquery, sizeof(offsetquery), "OFFSET %d", offset);
+       }
+       if (limit > 0) {
+               snprintf(limitquery, sizeof(limitquery), "LIMIT %d", limit);
+       }
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT * FROM");
+       _cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
+       _cal_db_append_string(&query_str, "WHERE deleted = 0");
+       _cal_db_append_string(&query_str, limitquery);
+       _cal_db_append_string(&query_str, offsetquery);
+
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_list_destroy(*out_list, true);
+               *out_list = NULL;
+               CAL_FREE(query_str);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_book._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE ) {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+               __cal_db_calendar_get_stmt(stmt,record);
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE ) {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_calendar_get_records_with_query( calendar_query_h query, int offset, int limit, calendar_list_h* out_list )
+{
+       cal_query_s *que = NULL;
+       int i = 0;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       GSList *bind_text = NULL, *cursor = NULL;
+       sqlite3_stmt *stmt = NULL;
+
+       que = (cal_query_s *)query;
+
+       // make filter
+       if (que->filter) {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE) {
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // make projection
+       char *projection = NULL;
+       ret = _cal_db_query_create_projection(query, &projection);
+
+       char *query_str = NULL;
+       // query - projection
+       if (projection) {
+               _cal_db_append_string(&query_str, "SELECT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, "FROM");
+               _cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
+               CAL_FREE(projection);
+       }
+       else {
+               _cal_db_append_string(&query_str, "SELECT * FROM");
+               _cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
+       }
+
+       // query - condition
+       if (condition) {
+               _cal_db_append_string(&query_str,  "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ") AND (deleted = 0)");
+       }
+
+       // ORDER
+       char *order = NULL;
+       ret = _cal_db_query_create_order(query, condition, &order);
+       if (order) {
+               _cal_db_append_string(&query_str, order);
+               CAL_FREE(order);
+       }
+       CAL_FREE(condition);
+
+       // limit, offset
+       char buf[32] = {0};
+       if (limit > 0) {
+               snprintf(buf, sizeof(buf), "LIMIT %d", limit);
+               _cal_db_append_string(&query_str, buf);
+
+               if (offset > 0) {
+                       snprintf(buf, sizeof(buf), "OFFSET %d", offset);
+                       _cal_db_append_string(&query_str, buf);
+               }
+       }
+
+       // query
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt) {
+               if (bind_text) {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       CAL_DBG("%s",query_str);
+
+       // bind text
+       if (bind_text) {
+               g_slist_length(bind_text);
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+       }
+
+       ret = calendar_list_create(out_list);
+       if (ret != CALENDAR_ERROR_NONE) {
+               if (bind_text) {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               ERR("calendar_list_create() Failed");
+               sqlite3_finalize(stmt);
+               CAL_FREE(query_str);
+               return ret;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_book._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE ) {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+
+                       if (bind_text) {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+
+               if (que->projection_count > 0) {
+                       _cal_record_set_projection(record,
+                                       que->projection, que->projection_count, que->property_count);
+
+                       __cal_db_calendar_get_projection_stmt(stmt,
+                                       que->projection, que->projection_count,
+                                       record);
+               }
+               else {
+                       __cal_db_calendar_get_stmt(stmt,record);
+               }
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE ) {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+
+                       if (bind_text) {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+
+       if (bind_text) {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_calendar_insert_records(const calendar_list_h list, int** ids)
+{
+       calendar_record_h record;
+       int ret = 0;
+       int count = 0;
+       int i=0;
+       int *id = NULL;
+
+       ret = calendar_list_get_count(list, &count);
+       if (ret != CALENDAR_ERROR_NONE) {
+               ERR("list get error");
+               return ret;
+       }
+
+       id = calloc(1, sizeof(int)*count);
+
+       retvm_if(NULL == id, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc fail");
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE) {
+               ERR("list first error");
+               CAL_FREE(id);
+               return ret;
+       }
+
+       do {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE) {
+                       if( __cal_db_calendar_insert_record(record, &id[i]) != CALENDAR_ERROR_NONE) {
+                               ERR("db insert error");
+                               CAL_FREE(id);
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+               i++;
+       } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+
+       if(ids) {
+               *ids = id;
+       }
+       else {
+               CAL_FREE(id);
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_calendar_update_records(const calendar_list_h list)
+{
+       calendar_record_h record;
+       int ret = 0;
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE) {
+               ERR("list first error");
+               return ret;
+       }
+
+       do {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE) {
+                       if( __cal_db_calendar_update_record(record) != CALENDAR_ERROR_NONE) {
+                               ERR("db insert error");
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+       } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_calendar_delete_records(int ids[], int count)
+{
+       int i=0;
+
+       for(i=0;i<count;i++) {
+               if (__cal_db_calendar_delete_record(ids[i]) != CALENDAR_ERROR_NONE) {
+                       ERR("delete failed");
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_calendar_replace_records(const calendar_list_h list, int ids[], int count)
+{
+       calendar_record_h record;
+       int i = 0;
+       int ret = 0;
+
+       if (NULL == list) {
+               ERR("Invalid argument: list is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE) {
+               ERR("list first error");
+               return ret;
+       }
+
+       for (i = 0; i < count; i++) {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE) {
+                       if( __cal_db_calendar_replace_record(record, ids[i]) != CALENDAR_ERROR_NONE) {
+                               ERR("db insert error");
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+               if (CALENDAR_ERROR_NO_DATA != calendar_list_next(list)) {
+                       break;
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_calendar_get_count(int *out_count)
+{
+       retvm_if(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
+       _cal_db_append_string(&query_str, "WHERE deleted = 0");
+
+       int ret = 0;
+       int count = 0;
+       ret = _cal_db_util_query_get_first_int_result(query_str, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+       CAL_FREE(query_str);
+
+       *out_count = count;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_calendar_get_count_with_query(calendar_query_h query, int *out_count)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *table_name;
+       int count = 0;
+       GSList *bind_text = NULL;
+
+       que = (cal_query_s *)query;
+
+       if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_CALENDAR)) {
+               table_name = SAFE_STRDUP(CAL_TABLE_CALENDAR);
+       }
+       else {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       // make filter
+       if (que->filter) {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE) {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       char *query_str = NULL;
+       // query - select from
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, table_name);
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition) {
+               _cal_db_append_string(&query_str, "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ") AND (deleted = 0)");
+               CAL_FREE(condition);
+       }
+
+       // query
+       ret = _cal_db_util_query_get_first_int_result(query_str, bind_text, &count);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               if (bind_text) {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+
+       if (out_count)
+               *out_count = count;
+
+       if (bind_text) {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_db_calendar_get_stmt(sqlite3_stmt *stmt,calendar_record_h record)
+{
+       cal_calendar_s* calendar =  (cal_calendar_s*)(record);
+       int count = 0;
+       const unsigned char *temp;
+
+       calendar->index = sqlite3_column_int(stmt, count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       calendar->uid = SAFE_STRDUP(temp);
+
+       calendar->updated = sqlite3_column_int(stmt, count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       calendar->name = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       calendar->description = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       calendar->color = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       calendar->location = SAFE_STRDUP(temp);
+
+       calendar->visibility = sqlite3_column_int(stmt, count++);
+       calendar->sync_event = sqlite3_column_int(stmt, count++);
+       calendar->is_deleted = sqlite3_column_int(stmt, count++);
+       calendar->account_id = sqlite3_column_int(stmt, count++);
+       calendar->store_type = sqlite3_column_int(stmt, count++);
+
+       //sync_data1~4
+       temp = sqlite3_column_text(stmt, count++);
+       calendar->sync_data1 = SAFE_STRDUP(temp);
+       temp = sqlite3_column_text(stmt, count++);
+       calendar->sync_data2 = SAFE_STRDUP(temp);
+       temp = sqlite3_column_text(stmt, count++);
+       calendar->sync_data3 = SAFE_STRDUP(temp);
+       temp = sqlite3_column_text(stmt, count++);
+       calendar->sync_data4 = SAFE_STRDUP(temp);
+
+       //deleted
+       sqlite3_column_int(stmt, count++);
+
+       // mode
+       calendar->mode = sqlite3_column_int(stmt, count++);
+
+       // owner_label
+       sqlite3_column_text(stmt, count++);
+}
+
+static void __cal_db_calendar_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int stmt_count, calendar_record_h record)
+{
+       cal_calendar_s* calendar =  (cal_calendar_s*)(record);
+       const unsigned char *temp;
+
+       switch(property) {
+       case CAL_PROPERTY_CALENDAR_ID:
+               calendar->index = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_CALENDAR_UID:
+               temp = sqlite3_column_text(stmt, stmt_count);
+               calendar->uid = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_CALENDAR_NAME:
+               temp = sqlite3_column_text(stmt, stmt_count);
+               calendar->name = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_CALENDAR_DESCRIPTION:
+               temp = sqlite3_column_text(stmt, stmt_count);
+               calendar->description = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_CALENDAR_COLOR:
+               temp = sqlite3_column_text(stmt, stmt_count);
+               calendar->color = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_CALENDAR_LOCATION:
+               temp = sqlite3_column_text(stmt, stmt_count);
+               calendar->location = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_CALENDAR_VISIBILITY:
+               calendar->visibility = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_EVENT:
+               calendar->sync_event = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_CALENDAR_ACCOUNT_ID:
+               calendar->account_id = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_CALENDAR_STORE_TYPE:
+               calendar->store_type = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA1:
+               temp = sqlite3_column_text(stmt, stmt_count);
+               calendar->sync_data1 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA2:
+               temp = sqlite3_column_text(stmt, stmt_count);
+               calendar->sync_data1 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA3:
+               temp = sqlite3_column_text(stmt, stmt_count);
+               calendar->sync_data1 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_CALENDAR_SYNC_DATA4:
+               temp = sqlite3_column_text(stmt, stmt_count);
+               calendar->sync_data1 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_CALENDAR_MODE:
+               calendar->mode = sqlite3_column_int(stmt, stmt_count);
+               break;
+       default:
+               break;
+       }
+
+       return;
+}
+
+static void __cal_db_calendar_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record)
+{
+       int i=0;
+
+       for(i=0;i<projection_count;i++)
+               __cal_db_calendar_get_property_stmt(stmt,projection[i],i,record);
+}
+
+static int __cal_db_calendar_update_projection(calendar_record_h record)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_calendar_s* calendar =  (cal_calendar_s*)(record);
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int ret = CALENDAR_ERROR_NONE;
+       char* set = NULL;
+       GSList *bind_text = NULL;
+       GSList *cursor = NULL;
+
+       ret = _cal_db_query_create_projection_update_set(record,&set,&bind_text);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       snprintf(query, sizeof(query), "UPDATE %s SET %s "
+                       "WHERE id = %d",
+                       CAL_TABLE_CALENDAR,set,
+                       calendar->index);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt) {
+               ERR("_cal_db_util_query_prepare() Failed");
+               CAL_FREE(set);
+               if(bind_text) {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       // bind
+       if (bind_text) {
+               int i = 0;
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+       }
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret) {
+               sqlite3_finalize(stmt);
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+
+               CAL_FREE(set);
+               if(bind_text) {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+
+               switch (dbret) {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       sqlite3_finalize(stmt);
+
+       _cal_db_util_notify(CAL_NOTI_TYPE_CALENDAR);
+
+       CAL_FREE(set);
+       if(bind_text) {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/native/cal_db_plugin_event.c b/native/cal_db_plugin_event.c
new file mode 100644 (file)
index 0000000..eb33f0c
--- /dev/null
@@ -0,0 +1,2921 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "calendar_db.h"
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_time.h"
+#include "cal_record.h"
+#include "cal_list.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_db_rrule.h"
+#include "cal_db_query.h"
+#include "cal_db_alarm.h"
+#include "cal_db_instance.h"
+#include "cal_db_attendee.h"
+#include "cal_db_extended.h"
+#include "cal_db_event.h"
+#include "cal_access_control.h"
+
+static int __cal_db_event_insert_record(calendar_record_h record, int* id);
+static int __cal_db_event_get_record(int id, calendar_record_h* out_record);
+static int __cal_db_event_update_record(calendar_record_h record);
+static int __cal_db_event_delete_record(int id);
+static int __cal_db_event_get_all_records(int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_event_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_event_insert_records(const calendar_list_h list, int** ids);
+static int __cal_db_event_update_records(const calendar_list_h list);
+static int __cal_db_event_delete_records(int ids[], int count);
+static int __cal_db_event_get_count(int *out_count);
+static int __cal_db_event_get_count_with_query(calendar_query_h query, int *out_count);
+static int __cal_db_event_replace_record(calendar_record_h record, int id);
+static int __cal_db_event_replace_records(const calendar_list_h list, int ids[], int count);
+/*
+ * static function
+ */
+static void __cal_db_event_get_stmt(sqlite3_stmt *stmt,bool is_view_table,calendar_record_h record,
+               int *exception, int *extended);
+static void __cal_db_event_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record);
+static void __cal_db_event_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record);
+static int __cal_db_event_update_dirty(calendar_record_h record, int is_dirty_in_time);
+/*  // under construction
+        bool __cal_db_event_check_changed_rrule(record);
+ */
+static int __cal_db_event_exception_get_records(int original_id, cal_list_s *list);
+static int __cal_db_event_exception_delete_with_id(int original_id);
+static int __cal_db_event_exception_get_ids(int original_id, GList **out_list);
+static int __cal_db_event_exception_update(cal_list_s *exception_list_s, int original_id, int calendar_id, int is_dirty_in_time, time_t time_diff, int old_type, int new_type);
+static int __cal_db_event_get_deleted_data(int id, int* calendar_book_id, int* created_ver, int* original_event_id, char** recurrence_id);
+static int __cal_db_event_exdate_insert_normal(int event_id, const char* original_exdate, const char* exdate, int **exception_id, int *exception_len);
+static bool __cal_db_event_check_calendar_book_type(calendar_record_h record);
+
+cal_db_plugin_cb_s _cal_db_event_plugin_cb = {
+       .is_query_only = false,
+       .insert_record = __cal_db_event_insert_record,
+       .get_record = __cal_db_event_get_record,
+       .update_record = __cal_db_event_update_record,
+       .delete_record = __cal_db_event_delete_record,
+       .get_all_records = __cal_db_event_get_all_records,
+       .get_records_with_query = __cal_db_event_get_records_with_query,
+       .insert_records = __cal_db_event_insert_records,
+       .update_records = __cal_db_event_update_records,
+       .delete_records = __cal_db_event_delete_records,
+       .get_count = __cal_db_event_get_count,
+       .get_count_with_query = __cal_db_event_get_count_with_query,
+       .replace_record = __cal_db_event_replace_record,
+       .replace_records = __cal_db_event_replace_records
+};
+
+static int __cal_db_event_insert_record(calendar_record_h record, int* id)
+{
+       retv_if(NULL == record, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(false == __cal_db_event_check_calendar_book_type(record), CALENDAR_ERROR_INVALID_PARAMETER);
+       cal_event_s *event = (cal_event_s *)record;
+       return _cal_db_event_insert_record(record, event->original_event_id, id);
+}
+
+enum {
+       DIRTY_INIT = -1,
+       DIRTY_IN_OTHER = 0,
+       DIRTY_IN_TIME,
+};
+
+static int __cal_db_event_get_record(int id, calendar_record_h* out_record)
+{
+       char query[CAL_DB_SQL_MAX_LEN];
+       int ret = 0;
+       sqlite3_stmt *stmt = NULL;
+       cal_event_s *event = NULL;
+       cal_rrule_s *rrule = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int exception = 0, extended = 0;
+       calendar_record_h record_calendar;
+       calendar_book_sync_event_type_e sync_event_type = CALENDAR_BOOK_SYNC_EVENT_FOR_ME;
+
+       ret = calendar_record_create( _calendar_event._uri ,out_record);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("calendar_record_create(%d)", ret);
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       event = (cal_event_s*)(*out_record);
+
+       snprintf(query, sizeof(query),
+                       "SELECT * FROM %s "
+                       "WHERE id = %d AND (type = %d OR type = %d) AND calendar_id IN "
+                       "(select id from %s where deleted = 0)",
+                       CAL_TABLE_SCHEDULE,
+                       id, CALENDAR_BOOK_TYPE_EVENT, CALENDAR_BOOK_TYPE_NONE,
+                       CAL_TABLE_CALENDAR);
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               SEC_ERR("query[%s]", query);
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_record_destroy(*out_record, true);
+               *out_record = NULL;
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (dbret != CAL_DB_ROW)
+       {
+               SEC_ERR("query[%s]", query);
+               ERR("Failed to step stmt(%d)", dbret);
+               sqlite3_finalize(stmt);
+               calendar_record_destroy(*out_record, true);
+               *out_record = NULL;
+               switch (dbret)
+               {
+               case CAL_DB_DONE:
+                       ERR("Failed to find record(id:%d, ret:%d)", id, dbret);
+                       return CALENDAR_ERROR_DB_RECORD_NOT_FOUND;
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       __cal_db_event_get_stmt(stmt, false, *out_record, &exception, &extended);
+       sqlite3_finalize(stmt);
+       stmt = NULL;
+
+       //check
+       ret = _cal_db_get_record(_calendar_book._uri, event->calendar_id, &record_calendar);
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               ret = calendar_record_get_int(record_calendar,
+                               _calendar_book.sync_event, (int *)&sync_event_type);
+               calendar_record_destroy(record_calendar, true);
+       }
+       if (event->is_deleted == 1
+                       && sync_event_type != CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_REMAIN
+               )
+       {
+               calendar_record_destroy(*out_record, true);
+               *out_record = NULL;
+               return CALENDAR_ERROR_DB_RECORD_NOT_FOUND;
+       }
+
+       if (_cal_db_rrule_get_rrule(event->index, &rrule) == CALENDAR_ERROR_NONE )
+       {
+               _cal_db_rrule_set_rrule_to_event(rrule, *out_record);
+               CAL_FREE(rrule);
+       }
+
+       if (event->has_alarm == 1)
+               _cal_db_alarm_get_records(event->index, event->alarm_list);
+
+       if (event->has_attendee == 1)
+               _cal_db_attendee_get_records(event->index, event->attendee_list);
+
+       if (exception == 1)
+               __cal_db_event_exception_get_records(event->index, event->exception_list);
+
+       if (extended == 1)
+               _cal_db_extended_get_records(event->index, CALENDAR_RECORD_TYPE_EVENT, event->extended_list);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __is_dirty_in_time(calendar_record_h record)
+{
+       cal_record_s *rec = (cal_record_s *)record;
+       retvm_if (NULL == record, false, "Invalid parameter: record id NULL");
+       retvm_if (NULL == rec->view_uri, false, "Invalid parameter: view_uri is NULL");
+
+       int count = 0;
+       const cal_property_info_s *info = _cal_view_get_property_info(rec->view_uri, &count);
+       retvm_if (NULL == info, false, "_cal_view_get_property_info() is failed");
+
+       int i;
+       int is_dirty_in_time = DIRTY_IN_OTHER;
+       for (i = 0; i < count; i++) {
+               if (false == _cal_record_check_property_flag(record, info[i].property_id , CAL_PROPERTY_FLAG_DIRTY)) {
+                       continue;
+               }
+               switch (info[i].property_id) {
+               case CAL_PROPERTY_EVENT_START:
+               case CAL_PROPERTY_EVENT_END:
+               case CAL_PROPERTY_EVENT_START_TZID:
+               case CAL_PROPERTY_EVENT_END_TZID:
+               case CAL_PROPERTY_EVENT_FREQ:
+               case CAL_PROPERTY_EVENT_RANGE_TYPE:
+               case CAL_PROPERTY_EVENT_UNTIL:
+               case CAL_PROPERTY_EVENT_COUNT:
+               case CAL_PROPERTY_EVENT_INTERVAL:
+               case CAL_PROPERTY_EVENT_BYSECOND:
+               case CAL_PROPERTY_EVENT_BYMINUTE:
+               case CAL_PROPERTY_EVENT_BYHOUR:
+               case CAL_PROPERTY_EVENT_BYDAY:
+               case CAL_PROPERTY_EVENT_BYMONTHDAY:
+               case CAL_PROPERTY_EVENT_BYYEARDAY:
+               case CAL_PROPERTY_EVENT_BYWEEKNO:
+               case CAL_PROPERTY_EVENT_BYMONTH:
+               case CAL_PROPERTY_EVENT_BYSETPOS:
+               case CAL_PROPERTY_EVENT_WKST:
+
+                       is_dirty_in_time = DIRTY_IN_TIME;
+                       break;
+               }
+               if (DIRTY_IN_OTHER != is_dirty_in_time) break;
+       }
+       DBG("%sirty in time", DIRTY_IN_OTHER == is_dirty_in_time ? "Not d" : "D");
+       return is_dirty_in_time;
+}
+
+time_t __get_time_diff(char *old_tzid, calendar_time_s *old, char *new_tzid, calendar_time_s *new)
+{
+       retvm_if (NULL == old, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: old time is NULL");
+       retvm_if (NULL == new, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: new time is NULL");
+
+       time_t diff = 0;
+       switch (old->type)
+       {
+       case CALENDAR_TIME_UTIME:
+               switch (new->type)
+               {
+               case CALENDAR_TIME_UTIME:
+                       DBG("%lld - %lld", old->time.utime, new->time.utime);
+                       diff = old->time.utime - new->time.utime;
+                       break;
+               case CALENDAR_TIME_LOCALTIME:
+                       DBG("type is changed(%d) -> (%d)", old->type, new->type);
+                       diff = old->time.utime - _cal_time_convert_itol(new_tzid,
+                                       new->time.date.year, new->time.date.month, new->time.date.mday,
+                                       new->time.date.hour, new->time.date.minute, new->time.date.second);
+                       break;
+               }
+               break;
+       case CALENDAR_TIME_LOCALTIME:
+               switch (new->type)
+               {
+               case CALENDAR_TIME_UTIME:
+                       DBG("type is changed(%d) -> (%d)", old->type, new->type);
+                       diff = _cal_time_convert_itol(old_tzid,
+                                       old->time.date.year, old->time.date.month, old->time.date.mday,
+                                       old->time.date.hour, old->time.date.minute, old->time.date.second) - new->time.utime;
+                       break;
+               case CALENDAR_TIME_LOCALTIME:
+                       diff = _cal_time_convert_itol(old_tzid,
+                                       old->time.date.year, old->time.date.month, old->time.date.mday,
+                                       old->time.date.hour, old->time.date.minute, old->time.date.second)
+                               - _cal_time_convert_itol(new_tzid, new->time.date.year, new->time.date.month, new->time.date.mday,
+                                               new->time.date.hour, new->time.date.minute, new->time.date.second);
+                       break;
+               }
+               break;
+       }
+       DBG("-------------time diff(%ld)", diff);
+       return diff;
+}
+
+static int __get_time_shifted_field(char *old_field, int old_type, int new_type, time_t time_diff, char **new_field)
+{
+       if (NULL == old_field || '\0' == *old_field) {
+               return CALENDAR_ERROR_NONE;
+       }
+
+       gchar **t = NULL;
+       t = g_strsplit_set(old_field, " ,", -1);
+       retvm_if (NULL == t, CALENDAR_ERROR_DB_FAILED, "g_strsplit_set() is failed");
+
+       int len_t = g_strv_length(t);
+
+       int len_field = strlen(old_field);
+       char *new = NULL;
+       new = calloc(len_field + (len_t * 8) + 1, sizeof(char)); // add (len_t * 8) for YYYYMMDD -> YYYYMMDDTHHMMSSZ
+       if (NULL == new) {
+               ERR("calloc() is failed");
+               g_strfreev(t);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       struct tm tm = {0};
+       time_t tt = 0;
+
+       int len = 0;
+       int i;
+       for (i = 0; i < len_t; i++) {
+               int y = 0, m = 0, d = 0;
+               int h = 0, n = 0, s = 0;
+               switch (old_type)
+               {
+               case CALENDAR_TIME_UTIME:
+                       sscanf(t[i],  "%04d%02d%02dT%02d%02d%02dZ", &y, &m, &d, &h, &n, &s);
+                       break;
+
+               case CALENDAR_TIME_LOCALTIME:
+                       switch (strlen(t[i]))
+                       {
+                       case 8: // YYYYMMDD
+                               sscanf(t[i],  "%04d%02d%02d", &y, &m, &d);
+                               break;
+
+                       case 15: //YYYYMMDDTHHMMSS
+                               sscanf(t[i],  "%04d%02d%02dT%02d%02d%02d", &y, &m, &d, &h, &n, &s);
+                               break;
+                       }
+                       break;
+               } // ct.type end switch
+
+               tm.tm_year = y - 1900;
+               tm.tm_mon = m - 1;
+               tm.tm_mday = d;
+               tm.tm_hour = h;
+               tm.tm_min = n;
+               tm.tm_sec = s;
+
+               char buf[32] = {0};
+               switch (new_type)
+               {
+               case CALENDAR_TIME_UTIME:
+                       switch (strlen(t[i])) // check original type
+                       {
+                       case 8: // YYYYMMDD
+                       case 15: //YYYYMMDDTHHMMSS
+                               tt = timelocal(&tm) - time_diff;
+                               gmtime_r(&tt, &tm);
+                               snprintf(buf, sizeof(buf), "%s%04d%02d%02dT%02d%02d%02dZ",
+                                               i == 0 ? "" : ",", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+                                               tm.tm_hour, tm.tm_min, tm.tm_sec);
+                               break;
+
+                       case 16: //YYYYMMDDTHHMMSSZ
+                               tt = timegm(&tm) - time_diff;
+                               gmtime_r(&tt, &tm);
+                               snprintf(buf, sizeof(buf), "%s%04d%02d%02dT%02d%02d%02dZ",
+                                               i == 0 ? "" : ",", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+                                               tm.tm_hour, tm.tm_min, tm.tm_sec);
+                               break;
+                       }
+
+                       break;
+
+               case CALENDAR_TIME_LOCALTIME:
+                       switch (strlen(t[i]))
+                       {
+                       case 8: // YYYYMMDD
+                               tt = timegm(&tm) - time_diff;
+                               gmtime_r(&tt, &tm);
+                               snprintf(buf, sizeof(buf), "%s%04d%02d%02d",
+                                               i == 0 ? "" : ",", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
+                               break;
+
+                       case 15: //YYYYMMDDTHHMMSS
+                               tt = timegm(&tm) - time_diff;
+                               gmtime_r(&tt, &tm);
+                               snprintf(buf, sizeof(buf), "%s%04d%02d%02dT%02d%02d%02d",
+                                               i == 0 ? "" : ",", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+                                               tm.tm_hour, tm.tm_min, tm.tm_sec);
+                               break;
+
+                       case 16: //YYYYMMDDTHHMMSSZ
+                               tt = timegm(&tm) - time_diff;
+                               localtime_r(&tt, &tm);
+                               snprintf(buf, sizeof(buf), "%s%04d%02d%02dT%02d%02d%02d",
+                                               i == 0 ? "" : ",", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
+                                               tm.tm_hour, tm.tm_min, tm.tm_sec);
+                               break;
+                       }
+                       break;
+               }
+               len += snprintf(new +len, len_field + (len_t * 8) + 1 -len, "%s", buf);
+       }
+       g_strfreev(t);
+
+       if (new_field)
+               *new_field = new;
+       else
+               free(new);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __update_exdate(cal_event_s *rec, time_t time_diff)
+{
+       retvm_if (NULL == rec, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: rec is NULL");
+       if (NULL == rec->exdate || '\0' == *rec->exdate)
+               return CALENDAR_ERROR_NONE;
+       if (0 == time_diff)
+               return CALENDAR_ERROR_NONE;
+
+       int ret;
+       calendar_record_h db_record = NULL;
+       ret = calendar_db_get_record(_calendar_event._uri, rec->index, &db_record);
+       retvm_if(ret != CALENDAR_ERROR_NONE, ret, "calendar_db_get_record fail(%d)", ret);
+
+       // get time diff
+       char *db_tzid = NULL;
+       calendar_record_get_str_p(db_record, _calendar_event.start_tzid, &db_tzid);
+       calendar_time_s ct = {0};
+       calendar_record_get_caltime(db_record, _calendar_event.start_time, &ct);
+
+       char *new_exdate = NULL;
+       __get_time_shifted_field(rec->exdate, ct.type, rec->start.type, time_diff, &new_exdate);
+       free(rec->exdate);
+       rec->exdate = new_exdate;
+       DBG("new exdate[%s]", new_exdate);
+
+       calendar_record_destroy(db_record, true);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __update_recurrence_id(calendar_record_h exception, int old_type, int new_type, time_t time_diff)
+{
+       ENTER();
+
+       cal_event_s *rec = (cal_event_s *)exception;
+       retvm_if (NULL == rec, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: rec is NULL");
+       if (NULL == rec->recurrence_id) {
+               DBG("No recurrence_id");
+               return CALENDAR_ERROR_NONE;
+       }
+
+       char *new_recurrence_id = NULL;
+       __get_time_shifted_field(rec->recurrence_id, rec->start.type, new_type, time_diff, &new_recurrence_id);
+       free(rec->recurrence_id);
+       rec->recurrence_id = new_recurrence_id;
+       DBG("new recurrence_id[%s]", new_recurrence_id);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __update_record(calendar_record_h record, int is_dirty_in_time)
+{
+       int ret;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char dtstart_datetime[32] = {0};
+       char dtend_datetime[32] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_event_s* event =  (cal_event_s*)(record);
+       cal_rrule_s *rrule = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int has_alarm = 0;
+       int timezone_id = 0;
+       int input_ver = 0;
+
+       retv_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(false == __cal_db_event_check_calendar_book_type(record), CALENDAR_ERROR_INVALID_PARAMETER);
+
+
+       ret = _cal_db_event_check_value_validation(event);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_event_check_value_validation() failed");
+               return ret;
+       }
+
+       // access control
+       if (_cal_access_control_have_write_permission(event->calendar_id) == false)
+       {
+               ERR("_cal_access_control_have_write_permission() failed");
+               return CALENDAR_ERROR_PERMISSION_DENIED;
+       }
+
+       if (event->common.properties_flags != NULL)
+       {
+               if (DIRTY_INIT == is_dirty_in_time) {
+                       is_dirty_in_time = __is_dirty_in_time(record);
+               }
+               return __cal_db_event_update_dirty(record, is_dirty_in_time);
+       }
+       int time_diff = 0;
+       calendar_time_s ct = {0};
+       if (DIRTY_IN_TIME == is_dirty_in_time) {
+               calendar_record_h old_record = NULL;
+               ret = calendar_db_get_record(_calendar_event._uri, event->index, &old_record);
+               if (CALENDAR_ERROR_NONE != ret) {
+                       ERR("calendar_db_get_record fail(%d)", ret);
+                       return ret;
+               }
+
+               // get time diff
+               char *old_tzid = NULL;
+               calendar_record_get_str_p(old_record, _calendar_event.start_tzid, &old_tzid);
+               calendar_record_get_caltime(old_record, _calendar_event.start_time, &ct);
+               time_diff = __get_time_diff(old_tzid, &ct, event->start_tzid, &event->start);
+               calendar_record_destroy(old_record, true);
+       }
+
+       has_alarm = _cal_db_alarm_has_alarm(event->alarm_list);
+       _cal_time_get_timezone_from_table(event->start_tzid, NULL, &timezone_id);
+       input_ver = _cal_db_util_get_next_ver();
+       int is_allday = 0;
+       if (CALENDAR_TIME_LOCALTIME == event->start.type
+                       && (0 == event->start.time.date.hour)
+                       && (0 == event->start.time.date.minute)
+                       && (0 == event->start.time.date.second)
+                       && (0 == event->end.time.date.hour)
+                       && (0 == event->end.time.date.minute)
+                       && (0 == event->end.time.date.second)) {
+               is_allday = 1;
+       }
+       snprintf(query, sizeof(query), "UPDATE %s SET "
+                       "changed_ver = %d,"
+                       "type = %d,"
+                       "summary = ?,"
+                       "description = ?,"
+                       "location = ?,"
+                       "categories = ?,"
+                       "exdate = ?,"
+                       "task_status = %d,"
+                       "priority = %d,"
+                       "timezone = %d, "
+                       "contact_id = %d, "
+                       "busy_status = %d, "
+                       "sensitivity = %d, "
+                       "uid = ?, "
+                       "organizer_name = ?, "
+                       "organizer_email = ?, "
+                       "meeting_status = %d, "
+                       "calendar_id = %d, "
+                       "original_event_id = %d,"
+                       "latitude = %lf,"
+                       "longitude = %lf,"
+                       "email_id = %d,"
+                       "completed_time = %lld,"
+                       "progress = %d, "
+                       "dtstart_type = %d, "
+                       "dtstart_utime = %lld, "
+                       "dtstart_datetime = ?, "
+                       "dtstart_tzid = ?, "
+                       "dtend_type = %d, "
+                       "dtend_utime = %lld, "
+                       "dtend_datetime = ?, "
+                       "dtend_tzid = ?, "
+                       "last_mod = strftime('%%s', 'now'), "
+                       "rrule_id = %d, "
+                       "recurrence_id = ?, "
+                       "rdate = ?, "
+                       "has_attendee = %d, "
+                       "has_alarm = %d, "
+                       "system_type = %d, "
+                       "updated = %ld, "
+                       "sync_data1 = ?, "
+                       "sync_data2 = ?, "
+                       "sync_data3 = ?, "
+                       "sync_data4 = ?,"
+                       "has_exception = %d, "
+                       "has_extended = %d, "
+                       "freq = %d, "
+                       "is_allday = %d "
+                       "WHERE id = %d;",
+               CAL_TABLE_SCHEDULE,
+               input_ver,
+               CAL_SCH_TYPE_EVENT,/*event->cal_type,*/
+               event->event_status,
+               event->priority,
+               event->timezone ? event->timezone : timezone_id,
+               event->contact_id,
+               event->busy_status,
+               event->sensitivity,
+               event->meeting_status,
+               event->calendar_id,
+               event->original_event_id,
+               event->latitude,
+               event->longitude,
+               event->email_id,
+               (long long int)0,//event->completed_time,
+               0,//event->progress,
+               event->start.type,
+               event->start.type == CALENDAR_TIME_UTIME ? event->start.time.utime : 0,
+               event->end.type,
+               event->end.type == CALENDAR_TIME_UTIME ? event->end.time.utime : 0,
+               event->freq > 0 ? 1 : 0,
+               (event->attendee_list && 0 < event->attendee_list->count)? 1: 0,
+               has_alarm,
+               event->system_type,
+               event->updated,
+               (event->exception_list && 0 < event->exception_list->count)? 1 : 0,
+               (event->extended_list && 0 < event->extended_list->count)? 1 : 0,
+               event->freq,
+               is_allday,
+               event->index);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() Failed");
+
+       int index = 1;
+
+       if (event->summary)
+               _cal_db_util_stmt_bind_text(stmt, index, event->summary);
+       index++;
+
+       if (event->description)
+               _cal_db_util_stmt_bind_text(stmt, index, event->description);
+       index++;
+
+       if (event->location)
+               _cal_db_util_stmt_bind_text(stmt, index, event->location);
+       index++;
+
+       if (event->categories)
+               _cal_db_util_stmt_bind_text(stmt, index, event->categories);
+       index++;
+
+       if (event->exdate) {
+               if (DIRTY_IN_TIME == is_dirty_in_time) {
+                       __update_exdate(event, time_diff);
+               }
+               _cal_db_util_stmt_bind_text(stmt, index, event->exdate);
+       }
+       index++;
+
+       if (event->uid)
+               _cal_db_util_stmt_bind_text(stmt, index, event->uid);
+       index++;
+
+       if (event->organizer_name)
+               _cal_db_util_stmt_bind_text(stmt, index, event->organizer_name);
+       index++;
+
+       if (event->organizer_email)
+               _cal_db_util_stmt_bind_text(stmt, index, event->organizer_email);
+       index++;
+
+       if (CALENDAR_TIME_LOCALTIME == event->start.type)
+       {
+               snprintf(dtstart_datetime, sizeof(dtstart_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               event->start.time.date.year,
+                               event->start.time.date.month,
+                               event->start.time.date.mday,
+                               event->start.time.date.hour,
+                               event->start.time.date.minute,
+                               event->start.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, index, dtstart_datetime);
+       }
+       index++;
+
+       if (event->start_tzid)
+               _cal_db_util_stmt_bind_text(stmt, index, event->start_tzid);
+       index++;
+
+       if (CALENDAR_TIME_LOCALTIME == event->end.type)
+       {
+               snprintf(dtend_datetime, sizeof(dtend_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               event->end.time.date.year,
+                               event->end.time.date.month,
+                               event->end.time.date.mday,
+                               event->end.time.date.hour,
+                               event->end.time.date.minute,
+                               event->end.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, index, dtend_datetime);
+       }
+       index++;
+
+       if (event->end_tzid)
+               _cal_db_util_stmt_bind_text(stmt, index, event->end_tzid);
+       index++;
+
+       if (event->recurrence_id)
+               _cal_db_util_stmt_bind_text(stmt, index, event->recurrence_id);
+       index++;
+       if (event->rdate)
+               _cal_db_util_stmt_bind_text(stmt, index, event->rdate);
+       index++;
+       if (event->sync_data1)
+               _cal_db_util_stmt_bind_text(stmt, index, event->sync_data1);
+       index++;
+       if (event->sync_data2)
+               _cal_db_util_stmt_bind_text(stmt, index, event->sync_data2);
+       index++;
+       if (event->sync_data3)
+               _cal_db_util_stmt_bind_text(stmt, index, event->sync_data3);
+       index++;
+       if (event->sync_data4)
+               _cal_db_util_stmt_bind_text(stmt, index, event->sync_data4);
+       index++;
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret) {
+               sqlite3_finalize(stmt);
+               ERR("sqlite3_step() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       sqlite3_finalize(stmt);
+
+       // update parent event changed ver in case this event is exception mod
+       // which is original_event_id > 0
+       _cal_db_event_update_original_event_version(event->original_event_id, input_ver);
+
+       _cal_db_rrule_set_default(record);
+       _cal_db_rrule_get_rrule_from_event(record, &rrule);
+       _cal_db_rrule_update_record(event->index, rrule); // if rrule turns none, update 0.
+       CAL_FREE(rrule);
+
+       if (DIRTY_IN_TIME == is_dirty_in_time) {
+               _cal_db_instance_discard_record(event->index);
+               _cal_db_instance_publish_record(record);
+
+       } else {
+               // check exdate
+               _cal_db_instance_update_exdate_del(event->index, event->exdate);
+       }
+
+       _cal_db_alarm_delete_with_id(event->index);
+       _cal_db_attendee_delete_with_id(event->index);
+       _cal_db_extended_delete_with_id(event->index, CALENDAR_RECORD_TYPE_EVENT);
+
+       if (event->alarm_list && 0 < event->alarm_list->count) {
+               ret = _cal_db_alarm_insert_records(event->alarm_list, event->index);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_alarm_insert_records() failed(%x)", ret);
+       }
+
+       if (event->attendee_list && 0 < event->attendee_list->count) {
+               ret = _cal_db_attendee_insert_records(event->attendee_list, event->index);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_attendee_insert_records() failed(%x)", ret);
+       }
+
+       if (event->exception_list && 0 < event->exception_list->count) {
+               ret = __cal_db_event_exception_update(event->exception_list, event->index, event->calendar_id, is_dirty_in_time, time_diff, ct.type, event->start.type);
+               warn_if(CALENDAR_ERROR_NONE != ret, "__cal_db_event_exception_update() Failed(%d)", ret);
+       }
+
+       if (event->extended_list && 0 < event->extended_list->count) {
+               ret = _cal_db_extended_insert_records(event->extended_list, event->index, CALENDAR_RECORD_TYPE_EVENT);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_extended_insert_records() Failed(%d)", ret);
+       }
+
+       _cal_db_util_notify(CAL_NOTI_TYPE_EVENT);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_update_record(calendar_record_h record)
+{
+       return __update_record(record, DIRTY_INIT);
+}
+
+static int __cal_db_event_add_exdate(int original_event_id, char* recurrence_id)
+{
+       char query[CAL_DB_SQL_MAX_LEN];
+       sqlite3_stmt *stmt = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       if (original_event_id < 0)
+       {
+               return CALENDAR_ERROR_NONE;
+       }
+       DBG("This is exception mod event");
+       if (NULL == recurrence_id)
+       {
+               ERR("This event should have recurrence_id");
+               return CALENDAR_ERROR_NONE;
+       }
+       DBG("Exdate parent(id:%d) and recurrence_id[%s]", original_event_id, recurrence_id);
+
+       // get exdate from original event.
+       snprintf(query, sizeof(query), "SELECT exdate FROM %s WHERE id = %d ",
+                       CAL_TABLE_SCHEDULE, original_event_id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               SEC_ERR("query[%s]", query);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       // add recurrence id to end of the exdate of original event.
+       const unsigned char *temp = NULL;
+       int len = 0;
+       char *exdate = NULL;
+       if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               temp = sqlite3_column_text(stmt, 0);
+               if (NULL == temp || strlen((char *)temp) < 1)
+               {
+                       exdate = strdup(recurrence_id);
+                       DBG("append first exdate[%s]", exdate);
+               }
+               else
+               {
+                       if (strstr((char *)temp, recurrence_id))
+                       {
+                               DBG("warn: recurrence id already is registered to exdate");
+                               sqlite3_finalize(stmt);
+                               return CALENDAR_ERROR_NONE;
+                       }
+                       len = strlen((const char *)temp) + strlen(recurrence_id) + 2;
+                       exdate = calloc(len, sizeof(char));
+                       if (NULL == exdate)
+                       {
+                               ERR("calloc() failed");
+                               sqlite3_finalize(stmt);
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+                       snprintf(exdate, len, "%s,%s", temp, recurrence_id);
+                       DBG("append [%s] to aleady has exdate [%s]", temp, recurrence_id);
+               }
+       }
+       else
+       {
+               DBG("Failed to get exdate: event_id(%d)", original_event_id);
+       }
+       sqlite3_finalize(stmt);
+       stmt = NULL;
+
+       // update exdate
+       DBG("update to recurrence id to exdate[%s]", exdate);
+       int input_ver = _cal_db_util_get_next_ver();
+       snprintf(query, sizeof(query), "UPDATE %s SET exdate = ?, changed_ver=%d WHERE id = %d ",
+                       CAL_TABLE_SCHEDULE, input_ver, original_event_id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               SEC_ERR("query[%s]", query);
+               ERR("_cal_db_util_query_prepare() failed");
+               if (exdate) free(exdate);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       int index = 1;
+       _cal_db_util_stmt_bind_text(stmt, index, exdate);
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       sqlite3_finalize(stmt);
+       if (CAL_DB_DONE != dbret) {
+               ERR("sqlite3_step() Failed(%d)", dbret);
+               if (exdate) free(exdate);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       if (exdate) free(exdate);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_delete_record(int id)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int calendar_book_id;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       int created_ver = 0;
+       int original_event_id = 0;
+       char *recurrence_id = NULL;
+       calendar_book_sync_event_type_e sync_event_type = CALENDAR_BOOK_SYNC_EVENT_FOR_ME;
+
+       DBG("delete record(id:%d)", id);
+       retvm_if(id < 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid argument: id < 0");
+
+       // get calendar_id, created_ver, original_event_id, recurrence_id
+       ret = __cal_db_event_get_deleted_data(id, &calendar_book_id, &created_ver, &original_event_id, &recurrence_id);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               DBG("__cal_db_event_get_deleted_data() failed");
+               return ret;
+       }
+
+       //access control
+       if (_cal_access_control_have_write_permission(calendar_book_id) == false)
+       {
+               ERR("fail");
+               CAL_FREE(recurrence_id);
+               return CALENDAR_ERROR_PERMISSION_DENIED;
+       }
+
+       if (original_event_id > 0)
+       {
+               // start:add record to exdate if this record is exception mod.
+               __cal_db_event_add_exdate(original_event_id, recurrence_id);
+       }
+       CAL_FREE(recurrence_id);
+
+       snprintf(query, sizeof(query), "SELECT sync_event FROM %s WHERE id = %d ",
+                       CAL_TABLE_CALENDAR, calendar_book_id);
+       ret = _cal_db_util_query_get_first_int_result(query, NULL, (int *)&sync_event_type);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               return ret;
+       }
+       DBG("sync_event_type(%d)", sync_event_type);
+
+       if (sync_event_type == CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_REMAIN)
+       {
+               DBG("set is_delete");
+               snprintf(query, sizeof(query),
+                               "UPDATE %s "
+                               "SET is_deleted = 1, "
+                               "changed_ver = %d, "
+                               "last_mod = strftime('%%s','now') "
+                               "WHERE id = %d ",
+                               CAL_TABLE_SCHEDULE,
+                               _cal_db_util_get_next_ver(),
+                               id);
+
+               dbret = _cal_db_util_query_exec(query);
+               if (dbret != CAL_DB_OK)
+               {
+                       DBG("query[%s]", query);
+                       ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+                       switch (dbret)
+                       {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+
+               DBG("attendee, alarm and rrule will be deleted by trigger after sync clean");
+
+       } else
+       {
+               _cal_db_util_get_next_ver();
+
+               DBG("delete event");
+               snprintf(query, sizeof(query), "DELETE FROM %s WHERE id = %d ",
+                               CAL_TABLE_SCHEDULE, id);
+
+               dbret = _cal_db_util_query_exec(query);
+               if(CAL_DB_OK != dbret)
+               {
+                       DBG("query[%s]", query);
+                       ERR("_cal_db_util_query_exec() Failed");
+                       switch (dbret)
+                       {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+
+               DBG("attendee, alarm and rrule is deleted by trigger");
+       }
+
+        _cal_db_instance_discard_record(id);
+       _cal_db_util_notify(CAL_NOTI_TYPE_EVENT);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_get_all_records(int offset, int limit, calendar_list_h* out_list)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char offsetquery[CAL_DB_SQL_MAX_LEN] = {0};
+       char limitquery[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = calendar_list_create(out_list);
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       if (offset > 0)
+       {
+               snprintf(offsetquery, sizeof(offsetquery), "OFFSET %d", offset);
+       }
+       if (limit > 0)
+       {
+               snprintf(limitquery, sizeof(limitquery), "LIMIT %d", limit);
+       }
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT * FROM");
+       _cal_db_append_string(&query_str, CAL_VIEW_TABLE_EVENT);
+       _cal_db_append_string(&query_str, limitquery);
+       _cal_db_append_string(&query_str, offsetquery);
+
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_list_destroy(*out_list, true);
+               *out_list = NULL;
+               CAL_FREE(query_str);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               int exception=0, extended=0;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_event._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+               __cal_db_event_get_stmt(stmt, true, record, &exception, &extended);
+
+               // child
+               int has_attendee = 0, has_alarm = 0;
+               int record_id = 0;
+               cal_event_s* pevent = (cal_event_s*) record;
+               calendar_record_get_int(record, _calendar_event.id, &record_id);
+               if(calendar_record_get_int(record, _calendar_event.has_attendee,&has_attendee) == CALENDAR_ERROR_NONE)
+               {
+                       if( has_attendee == 1)
+                       {
+                               _cal_db_attendee_get_records(record_id, pevent->attendee_list);
+                       }
+               }
+               if(calendar_record_get_int(record, _calendar_event.has_alarm,&has_alarm) == CALENDAR_ERROR_NONE)
+               {
+                       if( has_alarm == 1)
+                       {
+                               _cal_db_alarm_get_records(record_id, pevent->alarm_list);
+                       }
+               }
+
+               if (exception == 1)
+                       __cal_db_event_exception_get_records(record_id, pevent->exception_list);
+               if (extended == 1)
+                       _cal_db_extended_get_records(record_id, CALENDAR_RECORD_TYPE_EVENT, pevent->extended_list);
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list)
+{
+       cal_query_s *que = NULL;
+       calendar_list_h list = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *projection = NULL;
+       GSList *bind_text = NULL, *cursor = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int i = 0;
+       char *table_name;
+
+       if (NULL == query || NULL == out_list)
+       {
+               ERR("Invalid parameter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       que = (cal_query_s *)query;
+
+       if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_EVENT))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_EVENT);
+       }
+       else if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_EVENT_CALENDAR))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_EVENT_CALENDAR);
+       }
+       else if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_EVENT_CALENDAR_ATTENDEE))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_EVENT_CALENDAR_ATTENDEE);
+       }
+       else
+       {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+               //table_name = SAFE_STRDUP(CAL_TABLE_NORMAL_INSTANCE);
+       }
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // make projection
+       ret = _cal_db_query_create_projection(query, &projection);
+
+       char *query_str = NULL;
+       // query - projection
+       if (projection)
+       {
+               _cal_db_append_string(&query_str, "SELECT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, "FROM");
+               _cal_db_append_string(&query_str, table_name);
+               CAL_FREE(projection);
+       }
+       else
+       {
+               _cal_db_append_string(&query_str, "SELECT * FROM");
+               _cal_db_append_string(&query_str, table_name);
+       }
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+       }
+
+       // ORDER
+       char *order = NULL;
+       ret = _cal_db_query_create_order(query, condition, &order);
+       if (order)
+       {
+               _cal_db_append_string(&query_str, order);
+               CAL_FREE(order);
+       }
+       CAL_FREE(condition);
+
+       // limit, offset
+       char buf[32] = {0};
+       if (limit > 0)
+       {
+               snprintf(buf, sizeof(buf), "LIMIT %d", limit);
+               _cal_db_append_string(&query_str, buf);
+
+               if (offset > 0)
+               {
+                       snprintf(buf, sizeof(buf), "OFFSET %d", offset);
+                       _cal_db_append_string(&query_str, buf);
+               }
+       }
+       CAL_DBG("%s",query_str);
+
+       // query
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       // bind text
+       if (bind_text)
+       {
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+               {
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+               }
+       }
+
+       //
+       ret = calendar_list_create(&list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               ERR("calendar_list_create() Failed");
+               sqlite3_finalize(stmt);
+               CAL_FREE(query_str);
+               return ret;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               int exception = 1, extended = 1;
+               int attendee = 1, alarm = 1;
+
+               // stmt -> record
+               ret = calendar_record_create(_calendar_event._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(list, true);
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+               if (que->projection_count > 0)
+               {
+                       _cal_record_set_projection(record,
+                                       que->projection, que->projection_count, que->property_count);
+
+                       __cal_db_event_get_projection_stmt(stmt,
+                                       que->projection, que->projection_count,
+                                       record);
+               }
+               else
+               {
+                       cal_event_s *event = NULL;
+                       __cal_db_event_get_stmt(stmt,true,record, &exception, &extended);
+                       event = (cal_event_s*)(record);
+                       if (event)
+                       {
+                               attendee = event->has_attendee;
+                               alarm = event->has_alarm;
+                       }
+               }
+
+               // child
+               if (_cal_db_query_find_projection_property(query,CAL_PROPERTY_EVENT_CALENDAR_ALARM) == true && alarm == 1)
+               {
+                       cal_event_s* pevent = (cal_event_s*) record;
+                       _cal_db_alarm_get_records(pevent->index, pevent->alarm_list);
+               }
+               if (_cal_db_query_find_projection_property(query,CAL_PROPERTY_EVENT_CALENDAR_ATTENDEE) == true && attendee == 1)
+               {
+                       cal_event_s* pevent = (cal_event_s*) record;
+                       _cal_db_attendee_get_records(pevent->index, pevent->attendee_list);
+               }
+               if (_cal_db_query_find_projection_property(query,CAL_PROPERTY_EVENT_EXCEPTION) == true && exception ==1)
+               {
+                       cal_event_s* pevent = (cal_event_s*) record;
+                       __cal_db_event_exception_get_records(pevent->index, pevent->exception_list);
+               }
+               if (_cal_db_query_find_projection_property(query,CAL_PROPERTY_EVENT_EXTENDED) == true && extended ==1)
+               {
+                       cal_event_s* pevent = (cal_event_s*) record;
+                       _cal_db_extended_get_records(pevent->index, CALENDAR_RECORD_TYPE_EVENT, pevent->extended_list);
+               }
+
+               ret = calendar_list_add(list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(list, true);
+                       calendar_record_destroy(record, true);
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+
+       *out_list = list;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_insert_records(const calendar_list_h list, int** ids)
+{
+       calendar_record_h record;
+       int ret = 0;
+       int count = 0;
+       int i=0;
+       int *id = NULL;
+
+       ret = calendar_list_get_count(list, &count);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list get error");
+               return ret;
+       }
+
+       id = calloc(1, sizeof(int)*count);
+
+       retvm_if(NULL == id, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc fail");
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list first error");
+               CAL_FREE(id);
+               return ret;
+       }
+       do
+       {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE)
+               {
+                       if( __cal_db_event_insert_record(record, &id[i]) != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("db insert error");
+                               CAL_FREE(id);
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+               i++;
+       } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+
+       if(ids)
+       {
+               *ids = id;
+       }
+       else
+       {
+               CAL_FREE(id);
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_update_records(const calendar_list_h list)
+{
+       calendar_record_h record;
+       int ret = 0;
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list first error");
+               return ret;
+       }
+       do
+       {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE)
+               {
+                       if( __cal_db_event_update_record(record) != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("db insert error");
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+       } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_delete_records(int ids[], int count)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       int i = 0;
+
+       for(i = 0; i < count; i++)
+       {
+               ret = __cal_db_event_delete_record(ids[i]);
+               if (CALENDAR_ERROR_NONE != ret)
+               {
+                       ERR("delete failed");
+                       return ret;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_get_count(int *out_count)
+{
+       retvm_if(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, CAL_VIEW_TABLE_EVENT);
+
+       int ret = 0;
+       int count = 0;
+       ret = _cal_db_util_query_get_first_int_result(query_str, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+       CAL_FREE(query_str);
+
+       *out_count = count;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_get_count_with_query(calendar_query_h query, int *out_count)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *table_name;
+       int count = 0;
+       GSList *bind_text = NULL;
+
+       que = (cal_query_s *)query;
+
+       if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_EVENT))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_EVENT);
+       }
+       else if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_EVENT_CALENDAR))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_EVENT_CALENDAR);
+       }
+       else if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_EVENT_CALENDAR_ATTENDEE))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_EVENT_CALENDAR_ATTENDEE);
+       }
+       else
+       {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+               //table_name = SAFE_STRDUP(CAL_TABLE_NORMAL_INSTANCE);
+       }
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       char *query_str = NULL;
+       // query - select from
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, table_name);
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str,  "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+               CAL_FREE(condition);
+       }
+
+       // query
+       ret = _cal_db_util_query_get_first_int_result(query_str, bind_text, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+
+       if (out_count) *out_count = count;
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_replace_record(calendar_record_h record, int id)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char dtstart_datetime[32] = {0};
+       char dtend_datetime[32] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_event_s* event =  (cal_event_s*)(record);
+       cal_rrule_s *rrule = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int has_alarm = 0;
+       int timezone_id = 0;
+       int input_ver = 0;
+
+       retv_if(NULL == event, CALENDAR_ERROR_INVALID_PARAMETER);
+       event->index = id;
+
+       // access control
+       if (_cal_access_control_have_write_permission(event->calendar_id) == false)
+       {
+               ERR("_cal_access_control_have_write_permission() failed");
+               return CALENDAR_ERROR_PERMISSION_DENIED;
+       }
+       if (event->common.properties_flags != NULL)
+       {
+               return __cal_db_event_update_dirty(record, -1);
+       }
+       has_alarm = _cal_db_alarm_has_alarm(event->alarm_list);
+       _cal_time_get_timezone_from_table(event->start_tzid, NULL, &timezone_id);
+       input_ver = _cal_db_util_get_next_ver();
+       int is_allday = 0;
+       if (CALENDAR_TIME_LOCALTIME == event->start.type
+                       && (0 == event->start.time.date.hour)
+                       && (0 == event->start.time.date.minute)
+                       && (0 == event->start.time.date.second)
+                       && (0 == event->end.time.date.hour)
+                       && (0 == event->end.time.date.minute)
+                       && (0 == event->end.time.date.second)) {
+               is_allday = 1;
+       }
+
+       snprintf(query, sizeof(query), "UPDATE %s SET "
+                       "changed_ver = %d,"
+                       "type = %d,"
+                       "summary = ?,"
+                       "description = ?,"
+                       "location = ?,"
+                       "categories = ?,"
+                       "exdate = ?,"
+                       "task_status = %d,"
+                       "priority = %d,"
+                       "timezone = %d, "
+                       "contact_id = %d, "
+                       "busy_status = %d, "
+                       "sensitivity = %d, "
+                       "uid = ?, "
+                       "organizer_name = ?, "
+                       "organizer_email = ?, "
+                       "meeting_status = %d, "
+                       "calendar_id = %d, "
+                       "original_event_id = %d,"
+                       "latitude = %lf,"
+                       "longitude = %lf,"
+                       "email_id = %d,"
+                       "completed_time = %lld,"
+                       "progress = %d, "
+                       "dtstart_type = %d, "
+                       "dtstart_utime = %lld, "
+                       "dtstart_datetime = ?, "
+                       "dtstart_tzid = ?, "
+                       "dtend_type = %d, "
+                       "dtend_utime = %lld, "
+                       "dtend_datetime = ?, "
+                       "dtend_tzid = ?, "
+                       "last_mod = strftime('%%s', 'now'), "
+                       "rrule_id = %d, "
+                       "recurrence_id = ?, "
+                       "rdate = ?, "
+                       "has_attendee = %d, "
+                       "has_alarm = %d, "
+                       "system_type = %d, "
+                       "updated = %ld, "
+                       "sync_data1 = ?, "
+                       "sync_data2 = ?, "
+                       "sync_data3 = ?, "
+                       "sync_data4 = ?, "
+                       "freq = %d, "
+                       "is_allday = %d "
+                       "WHERE id = %d ",
+               CAL_TABLE_SCHEDULE,
+               input_ver,
+               CAL_SCH_TYPE_EVENT,/*event->cal_type,*/
+               event->event_status,
+               event->priority,
+               event->timezone ? event->timezone : timezone_id,
+               event->contact_id,
+               event->busy_status,
+               event->sensitivity,
+               event->meeting_status,
+               event->calendar_id,
+               event->original_event_id,
+               event->latitude,
+               event->longitude,
+               event->email_id,
+               (long long int)0,//event->completed_time,
+               0,//event->progress,
+               event->start.type,
+               event->start.type == CALENDAR_TIME_UTIME ? event->start.time.utime : 0,
+               event->end.type,
+               event->end.type == CALENDAR_TIME_UTIME ? event->end.time.utime : 0,
+               event->freq > 0 ? 1 : 0,
+               (event->attendee_list && 0 < event->attendee_list->count) ? 1 : 0,
+               has_alarm,
+               event->system_type,
+               event->updated,
+               event->freq,
+               is_allday,
+               id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() Failed");
+
+       int index = 1;
+
+       if (event->summary)
+               _cal_db_util_stmt_bind_text(stmt, index, event->summary);
+       index++;
+
+       if (event->description)
+               _cal_db_util_stmt_bind_text(stmt, index, event->description);
+       index++;
+
+       if (event->location)
+               _cal_db_util_stmt_bind_text(stmt, index, event->location);
+       index++;
+
+       if (event->categories)
+               _cal_db_util_stmt_bind_text(stmt, index, event->categories);
+       index++;
+
+       if (event->exdate)
+               _cal_db_util_stmt_bind_text(stmt, index, event->exdate);
+       index++;
+
+       if (event->uid)
+               _cal_db_util_stmt_bind_text(stmt, index, event->uid);
+       index++;
+
+       if (event->organizer_name)
+               _cal_db_util_stmt_bind_text(stmt, index, event->organizer_name);
+       index++;
+
+       if (event->organizer_email)
+               _cal_db_util_stmt_bind_text(stmt, index, event->organizer_email);
+       index++;
+
+       if (CALENDAR_TIME_LOCALTIME == event->start.type)
+       {
+               snprintf(dtstart_datetime, sizeof(dtstart_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               event->start.time.date.year,
+                               event->start.time.date.month,
+                               event->start.time.date.mday,
+                               event->start.time.date.hour,
+                               event->start.time.date.minute,
+                               event->start.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, index, dtstart_datetime);
+       }
+       index++;
+
+       if (event->start_tzid)
+               _cal_db_util_stmt_bind_text(stmt, index, event->start_tzid);
+       index++;
+
+       if (CALENDAR_TIME_LOCALTIME == event->end.type)
+       {
+               snprintf(dtend_datetime, sizeof(dtend_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               event->end.time.date.year,
+                               event->end.time.date.month,
+                               event->end.time.date.mday,
+                               event->end.time.date.hour,
+                               event->end.time.date.minute,
+                               event->end.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, index, dtend_datetime);
+       }
+       index++;
+
+       if (event->end_tzid)
+               _cal_db_util_stmt_bind_text(stmt, index, event->end_tzid);
+       index++;
+
+       if (event->recurrence_id)
+               _cal_db_util_stmt_bind_text(stmt, index, event->recurrence_id);
+       index++;
+       if (event->rdate)
+               _cal_db_util_stmt_bind_text(stmt, index, event->rdate);
+       index++;
+       if (event->sync_data1)
+               _cal_db_util_stmt_bind_text(stmt, index, event->sync_data1);
+       index++;
+       if (event->sync_data2)
+               _cal_db_util_stmt_bind_text(stmt, index, event->sync_data2);
+       index++;
+       if (event->sync_data3)
+               _cal_db_util_stmt_bind_text(stmt, index, event->sync_data3);
+       index++;
+       if (event->sync_data4)
+               _cal_db_util_stmt_bind_text(stmt, index, event->sync_data4);
+       index++;
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret) {
+               sqlite3_finalize(stmt);
+               ERR("sqlite3_step() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       sqlite3_finalize(stmt);
+
+       // update parent event changed ver in case this event is exception mod
+       // which is original_event_id > 0
+       _cal_db_event_update_original_event_version(event->original_event_id, input_ver);
+
+       _cal_db_rrule_set_default(record);
+       _cal_db_rrule_get_rrule_from_event(record, &rrule);
+       _cal_db_rrule_update_record(id, rrule);
+       CAL_FREE(rrule);
+
+       _cal_db_instance_discard_record(id);
+       _cal_db_instance_publish_record(record);
+
+       _cal_db_alarm_delete_with_id(id);
+       _cal_db_attendee_delete_with_id(id);
+       __cal_db_event_exception_delete_with_id(id);
+       _cal_db_extended_delete_with_id(id, CALENDAR_RECORD_TYPE_EVENT);
+
+       if (event->alarm_list && 0 < event->alarm_list->count) {
+               ret = _cal_db_alarm_insert_records(event->alarm_list, event->index);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_alarm_insert_records() failed(%x)", ret);
+       }
+
+       if (event->attendee_list && 0 < event->attendee_list->count) {
+               ret = _cal_db_attendee_insert_records(event->attendee_list, event->index);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_attendee_insert_records() failed(%x)", ret);
+       }
+
+       if (event->exception_list && 0 < event->exception_list->count) {
+               ret = _cal_db_event_insert_records(event->exception_list, id);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_event_insert_records() failed(%x)", ret);
+       }
+
+       if (event->extended_list && 0 < event->extended_list->count) {
+               ret = _cal_db_extended_insert_records(event->extended_list, id, CALENDAR_RECORD_TYPE_EVENT);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_extended_insert_records() Failed(%d)", ret);
+       }
+
+       _cal_db_util_notify(CAL_NOTI_TYPE_EVENT);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_replace_records(const calendar_list_h list, int ids[], int count)
+{
+       calendar_record_h record;
+       int i = 0;
+       int ret = 0;
+
+       if (NULL == list)
+       {
+               ERR("Invalid argument: list is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list first error");
+               return ret;
+       }
+
+       for (i = 0; i < count; i++)
+       {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE)
+               {
+                       if( __cal_db_event_replace_record(record, ids[i]) != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("db insert error");
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+               if (CALENDAR_ERROR_NO_DATA != calendar_list_next(list))
+               {
+                       break;
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_db_event_get_stmt(sqlite3_stmt *stmt,bool is_view_table,calendar_record_h record,
+               int *exception, int *extended)
+{
+       cal_event_s *event = NULL;
+       const unsigned char *temp;
+       int count = 0;
+       char *dtstart_datetime;
+       char *dtend_datetime;
+       char buf[8] = {0};
+
+       event = (cal_event_s*)(record);
+
+       event->index = sqlite3_column_int(stmt, count++);
+       sqlite3_column_int(stmt, count++);//event->cal_type = 1;/*sqlite3_column_int(stmt, count++);*/
+
+       temp = sqlite3_column_text(stmt, count++);
+       event->summary = SAFE_STRDUP(temp);
+       temp = sqlite3_column_text(stmt, count++);
+       event->description = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       event->location = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       event->categories = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       event->exdate = SAFE_STRDUP(temp);
+
+       event->event_status = sqlite3_column_int(stmt, count++);
+       event->priority = sqlite3_column_int(stmt, count++);
+       event->timezone = sqlite3_column_int(stmt, count++);
+       event->contact_id = sqlite3_column_int(stmt, count++);
+       event->busy_status = sqlite3_column_int(stmt, count++);
+       event->sensitivity = sqlite3_column_int(stmt, count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       event->uid = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       event->organizer_name = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       event->organizer_email = SAFE_STRDUP(temp);
+
+       event->meeting_status = sqlite3_column_int(stmt, count++);
+       event->calendar_id = sqlite3_column_int(stmt, count++);
+       event->original_event_id = sqlite3_column_int(stmt, count++);
+       event->latitude = sqlite3_column_double(stmt,count++);
+       event->longitude = sqlite3_column_double(stmt,count++);
+       event->email_id = sqlite3_column_int(stmt, count++);
+       event->created_time = sqlite3_column_int64(stmt, count++);
+
+       count++; // completed_time
+       count++; // progress
+       count++; // changed_ver
+       count++; // created_ver
+
+       event->is_deleted = sqlite3_column_int(stmt,count++);
+       event->start.type = sqlite3_column_int(stmt,count++);
+
+       if (event->start.type == CALENDAR_TIME_UTIME)
+       {
+               event->start.time.utime = sqlite3_column_int64(stmt,count++);
+               count++;  //dtstart_datetime
+       }
+       else
+       {
+               count++; // dtstart_utime
+               temp = sqlite3_column_text(stmt, count++);
+               if (temp) {
+                       dtstart_datetime = SAFE_STRDUP(temp);
+                       snprintf(buf, strlen("YYYY") + 1, "%s", dtstart_datetime);
+                       event->start.time.date.year =  atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 5);
+                       event->start.time.date.month = atoi(buf);
+                       snprintf(buf, strlen("DD") + 1, "%s", dtstart_datetime + 8);
+                       event->start.time.date.mday = atoi(buf);
+                       snprintf(buf, strlen("HH") + 1, "%s", dtstart_datetime + 11);
+                       event->start.time.date.hour = atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 14);
+                       event->start.time.date.minute = atoi(buf);
+                       snprintf(buf, strlen("SS") + 1, "%s", dtstart_datetime + 17);
+                       event->start.time.date.second = atoi(buf);
+                       if (dtstart_datetime) free(dtstart_datetime);
+               }
+       }
+
+       temp = sqlite3_column_text(stmt, count++);
+       event->start_tzid = SAFE_STRDUP(temp);
+
+       event->end.type = sqlite3_column_int(stmt, count++);
+       if (event->end.type == CALENDAR_TIME_UTIME)
+       {
+               event->end.time.utime = sqlite3_column_int64(stmt,count++);
+               sqlite3_column_text(stmt, count++);
+       }
+       else
+       {
+               sqlite3_column_int64(stmt, count++);//event->end.time.utime = sqlite3_column_int64(stmt, count++);
+               temp = sqlite3_column_text(stmt, count++);
+               if (temp) {
+                       dtend_datetime = SAFE_STRDUP(temp);
+                       snprintf(buf, strlen("YYYY") + 1, "%s", dtend_datetime);
+                       event->end.time.date.year =  atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 5);
+                       event->end.time.date.month = atoi(buf);
+                       snprintf(buf, strlen("DD") + 1, "%s", dtend_datetime + 8);
+                       event->end.time.date.mday = atoi(buf);
+                       snprintf(buf, strlen("HH") + 1, "%s", dtend_datetime + 11);
+                       event->end.time.date.hour = atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 14);
+                       event->end.time.date.minute = atoi(buf);
+                       snprintf(buf, strlen("SS") + 1, "%s", dtend_datetime + 17);
+                       event->end.time.date.second = atoi(buf);
+                       if (dtend_datetime) free(dtend_datetime);
+               }
+       }
+       temp = sqlite3_column_text(stmt, count++);
+       event->end_tzid = SAFE_STRDUP(temp);
+
+       event->last_mod = sqlite3_column_int64(stmt,count++);
+       sqlite3_column_int(stmt,count++);//event->rrule_id = sqlite3_column_int(stmt,count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       event->recurrence_id = SAFE_STRDUP(temp);
+       temp = sqlite3_column_text(stmt, count++);
+       event->rdate = SAFE_STRDUP(temp);
+       event->has_attendee = sqlite3_column_int(stmt,count++);
+       event->has_alarm = sqlite3_column_int(stmt,count++);
+       event->system_type = sqlite3_column_int(stmt,count++);
+       event->updated = sqlite3_column_int(stmt,count++);
+       temp = sqlite3_column_text(stmt, count++);
+       event->sync_data1 = SAFE_STRDUP(temp);
+       temp = sqlite3_column_text(stmt, count++);
+       event->sync_data2 = SAFE_STRDUP(temp);
+       temp = sqlite3_column_text(stmt, count++);
+       event->sync_data3 = SAFE_STRDUP(temp);
+       temp = sqlite3_column_text(stmt, count++);
+       event->sync_data4 = SAFE_STRDUP(temp);
+
+       //has_exception
+       if (exception != NULL)
+               *exception = sqlite3_column_int(stmt,count++);
+
+       //has_extended
+       if (extended != NULL)
+               *extended = sqlite3_column_int(stmt,count++);
+
+       event->freq = sqlite3_column_int(stmt, count++);
+       event->is_allday = sqlite3_column_int(stmt, count++);
+
+       if (is_view_table == true) {
+               if (event->freq <= 0) {
+                       //event->rrule_id = 0;
+                       //sqlite3_finalize(stmt);
+                       //return CALENDAR_ERROR_NONE;
+                       return ;
+               }
+
+               //event->rrule_id = 1;
+               event->range_type = sqlite3_column_int(stmt, count++);
+               event->until.type = sqlite3_column_int(stmt, count++);
+               event->until.time.utime = sqlite3_column_int64(stmt, count++);
+
+               temp = sqlite3_column_text(stmt, count++);
+               if (temp && CALENDAR_TIME_LOCALTIME == event->until.type)
+               {
+                       sscanf((const char *)temp, CAL_FORMAT_LOCAL_DATETIME,
+                                       &event->until.time.date.year,
+                                       &event->until.time.date.month,
+                                       &event->until.time.date.mday,
+                                       &event->until.time.date.hour,
+                                       &event->until.time.date.minute,
+                                       &event->until.time.date.second);
+               }
+
+               event->count = sqlite3_column_int(stmt, count++);
+               event->interval = sqlite3_column_int(stmt, count++);
+
+               temp = sqlite3_column_text(stmt, count++);
+               event->bysecond = SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               event->byminute = SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               event->byhour = SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               event->byday= SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               event->bymonthday= SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               event->byyearday= SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               event->byweekno= SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               event->bymonth= SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               event->bysetpos = SAFE_STRDUP(temp);
+
+               event->wkst = sqlite3_column_int(stmt, count++);
+
+               sqlite3_column_int(stmt, count++); //calendar deleted
+       }
+
+}
+
+static void __cal_db_event_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record)
+{
+       cal_event_s *event = NULL;
+       const unsigned char *temp;
+       char *dtstart_datetime;
+       char *dtend_datetime;
+       char buf[8] = {0};
+
+       event = (cal_event_s*)(record);
+
+       switch(property)
+       {
+       case CAL_PROPERTY_EVENT_ID:
+               event->index = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_CALENDAR_ID:
+               event->calendar_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_SUMMARY:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->summary = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_DESCRIPTION:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->description = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_LOCATION:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->location = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_CATEGORIES:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->categories = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_EXDATE:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->exdate = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_EVENT_STATUS:
+               event->event_status = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_PRIORITY:
+               event->priority = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_TIMEZONE:
+               event->timezone = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_CONTACT_ID:
+               event->contact_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_BUSY_STATUS:
+               event->busy_status = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_SENSITIVITY:
+               event->sensitivity = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_UID:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->uid = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_ORGANIZER_NAME:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->organizer_name = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_ORGANIZER_EMAIL:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->organizer_email = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_MEETING_STATUS:
+               event->meeting_status = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_ORIGINAL_EVENT_ID:
+               event->original_event_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_LATITUDE:
+               event->latitude = sqlite3_column_double(stmt,*stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_LONGITUDE:
+               event->longitude = sqlite3_column_double(stmt,*stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_EMAIL_ID:
+               event->email_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_CREATED_TIME:
+               event->created_time = sqlite3_column_int64(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_LAST_MODIFIED_TIME:
+               event->last_mod = sqlite3_column_int64(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_IS_DELETED:
+               event->is_deleted = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_FREQ:
+               event->freq = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_RANGE_TYPE:
+               event->range_type = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_UNTIL:
+               //!!
+               break;
+       case CAL_PROPERTY_EVENT_COUNT:
+               event->count = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_INTERVAL:
+               event->interval = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_BYSECOND:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->bysecond = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_BYMINUTE:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->byminute = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_BYHOUR:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->byhour = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_BYDAY:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->byday = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_BYMONTHDAY:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->bymonthday = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_BYYEARDAY:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->byyearday = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_BYWEEKNO:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->byweekno = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_BYMONTH:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->bymonth = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_BYSETPOS:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->bysetpos = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_WKST:
+               event->wkst = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_RECURRENCE_ID:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->recurrence_id = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_RDATE:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->rdate = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_HAS_ATTENDEE:
+               event->has_attendee = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_HAS_ALARM:
+               event->has_alarm = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA1:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->sync_data1 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA2:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->sync_data2 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA3:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->sync_data3 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_SYNC_DATA4:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->sync_data4 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_START:
+               event->start.type = sqlite3_column_int(stmt,*stmt_count);
+               if (event->start.type == CALENDAR_TIME_UTIME)
+               {
+                       *stmt_count = *stmt_count+1;
+                       event->start.time.utime = sqlite3_column_int64(stmt,*stmt_count);
+                       *stmt_count = *stmt_count+1;
+                       sqlite3_column_text(stmt, *stmt_count);  //dtstart_datetime
+               }
+               else
+               {
+                       *stmt_count = *stmt_count+1;
+                       sqlite3_column_int64(stmt,*stmt_count); //event->start.time.utime = sqlite3_column_int64(stmt,count++);
+                       *stmt_count = *stmt_count+1;
+                       temp = sqlite3_column_text(stmt, *stmt_count);
+                       if (temp) {
+                               dtstart_datetime = SAFE_STRDUP(temp);
+                               snprintf(buf, strlen("YYYY") + 1, "%s", dtstart_datetime);
+                               event->start.time.date.year =  atoi(buf);
+                               snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 5);
+                               event->start.time.date.month = atoi(buf);
+                               snprintf(buf, strlen("DD") + 1, "%s", dtstart_datetime + 8);
+                               event->start.time.date.mday = atoi(buf);
+                               snprintf(buf, strlen("HH") + 1, "%s", dtstart_datetime + 11);
+                               event->start.time.date.hour = atoi(buf);
+                               snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 14);
+                               event->start.time.date.minute = atoi(buf);
+                               snprintf(buf, strlen("SS") + 1, "%s", dtstart_datetime + 17);
+                               event->start.time.date.second = atoi(buf);
+                               if (dtstart_datetime) free(dtstart_datetime);
+                       }
+               }
+               break;
+       case CAL_PROPERTY_EVENT_START_TZID:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->start_tzid = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_END:
+               //!!
+               event->end.type = sqlite3_column_int(stmt, *stmt_count);
+               if (event->end.type == CALENDAR_TIME_UTIME)
+               {
+                       *stmt_count = *stmt_count+1;
+                       event->end.time.utime = sqlite3_column_int64(stmt,*stmt_count);
+                       *stmt_count = *stmt_count+1;
+                       sqlite3_column_text(stmt, *stmt_count);
+               }
+               else
+               {
+                       *stmt_count = *stmt_count+1;
+                       sqlite3_column_int64(stmt, *stmt_count);//event->end.time.utime = sqlite3_column_int64(stmt, count++);
+                       *stmt_count = *stmt_count+1;
+                       temp = sqlite3_column_text(stmt, *stmt_count);
+                       if (temp) {
+                               dtend_datetime = SAFE_STRDUP(temp);
+                               snprintf(buf, strlen("YYYY") + 1, "%s", dtend_datetime);
+                               event->end.time.date.year =  atoi(buf);
+                               snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 5);
+                               event->end.time.date.month = atoi(buf);
+                               snprintf(buf, strlen("DD") + 1, "%s", dtend_datetime + 8);
+                               event->end.time.date.mday = atoi(buf);
+                               snprintf(buf, strlen("HH") + 1, "%s", dtend_datetime + 11);
+                               event->end.time.date.hour = atoi(buf);
+                               snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 14);
+                               event->end.time.date.minute = atoi(buf);
+                               snprintf(buf, strlen("SS") + 1, "%s", dtend_datetime + 17);
+                               event->end.time.date.second = atoi(buf);
+                               if (dtend_datetime) free(dtend_datetime);
+                       }
+               }
+               break;
+       case CAL_PROPERTY_EVENT_END_TZID:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               event->end_tzid = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EVENT_CALENDAR_SYSTEM_TYPE:
+               event->system_type = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       default:
+               sqlite3_column_int(stmt, *stmt_count);
+               break;
+       }
+
+       *stmt_count = *stmt_count+1;
+}
+
+static void __cal_db_event_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record)
+{
+       int i=0;
+       int stmt_count = 0;
+
+       for(i=0;i<projection_count;i++)
+       {
+               __cal_db_event_get_property_stmt(stmt,projection[i],&stmt_count,record);
+       }
+}
+
+static bool __cal_db_event_check_calendar_book_type(calendar_record_h record)
+{
+       int store_type = 0;
+       cal_event_s *event = (cal_event_s *)record;
+       char query[CAL_DB_SQL_MAX_LEN];
+       sqlite3_stmt *stmt = NULL;
+
+       snprintf(query, sizeof(query), "SELECT store_type "
+                       "FROM %s WHERE id = %d ",
+                       CAL_TABLE_CALENDAR, event->calendar_id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("query[%s]", query);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return false;
+       }
+
+       if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               store_type = sqlite3_column_int(stmt, 0);
+       }
+       else {
+               sqlite3_finalize(stmt);
+               stmt = NULL;
+               DBG("Failed to get calendar: calendar_id(%d)", event->calendar_id);
+               return false;
+       }
+       sqlite3_finalize(stmt);
+
+       bool ret = false;
+       switch (store_type) {
+       case CALENDAR_BOOK_TYPE_NONE:
+       case CALENDAR_BOOK_TYPE_EVENT:
+               ret = true;
+               break;
+       case CALENDAR_BOOK_TYPE_TODO:
+       default:
+               ret = false;
+               break;
+       }
+       return ret;
+}
+
+static int __cal_db_event_delete_exception(int *exception_ids, int exception_len)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       int i;
+       for (i = 0; i < exception_len; i++) {
+               snprintf(query, sizeof(query), "DELETE FROM %s WHERE id=%d ",
+                               CAL_TABLE_SCHEDULE, exception_ids[i]);
+
+               dbret = _cal_db_util_query_exec(query);
+               if (dbret != CAL_DB_OK) {
+                       ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+                       switch (dbret)
+                       {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_update_dirty(calendar_record_h record, int is_dirty_in_time)
+{
+       int event_id = 0;
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_record_h original_record = NULL;
+
+       ret = calendar_record_get_int(record,_calendar_event.id, &event_id);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       CAL_DBG("id=%d",event_id);
+
+       ret = __cal_db_event_get_record(event_id, &original_record);
+       retvm_if (CALENDAR_ERROR_NONE != ret, ret, "__cal_db_event_get_record() is failed(%d)", ret);
+
+       cal_record_s *_record = NULL;
+       const cal_property_info_s* property_info = NULL;
+       int property_info_count = 0;
+       int i=0;
+
+       _record = (cal_record_s *)record;
+
+       property_info = _cal_view_get_property_info(_record->view_uri, &property_info_count);
+
+       for(i=0;i<property_info_count;i++)
+       {
+               if (false == _cal_record_check_property_flag(record, property_info[i].property_id , CAL_PROPERTY_FLAG_DIRTY))
+               {
+                       continue;
+               }
+
+               //CAL_DBG("%d",property_info[i].property_id);
+               if (property_info[i].property_id == CAL_PROPERTY_EVENT_EXDATE)
+               {
+                       int calendar_id = 0;
+                       int account_id = 0;
+                       calendar_book_sync_event_type_e sync_event_type = CALENDAR_BOOK_SYNC_EVENT_FOR_ME;
+
+                       char *record_exdate = NULL;
+                       ret = calendar_record_get_str_p(record,property_info[i]. property_id, &record_exdate);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+                       ret = calendar_record_get_int(original_record, CAL_PROPERTY_EVENT_CALENDAR_ID, &calendar_id);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+
+                       calendar_record_h record_calendar = NULL;
+                       ret = _cal_db_get_record(_calendar_book._uri, calendar_id, &record_calendar);
+                       ret |= calendar_record_get_int(record_calendar, _calendar_book.account_id, &account_id);
+                       ret |= calendar_record_get_int(record_calendar, _calendar_book.sync_event, (int *)&sync_event_type);
+                       DBG("calendar_id(%d), account_id(%d), sync_event(%d)", calendar_id, account_id, sync_event_type);
+                       calendar_record_destroy(record_calendar, true);
+
+                       char *original_exdate = NULL;
+                       ret = calendar_record_get_str_p(original_record,property_info[i].property_id,&original_exdate);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+                       if (sync_event_type == CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_REMAIN)
+                       {
+                               ret = __cal_db_event_exdate_insert_normal(event_id, original_exdate, record_exdate, NULL, NULL);
+                               warn_if (ret != CALENDAR_ERROR_NONE, "%s->%s",original_exdate,record_exdate);
+
+                       } else {
+                               int *exception_ids = NULL;
+                               int exception_len = 0;
+                               ret = __cal_db_event_exdate_insert_normal(event_id, original_exdate, record_exdate, &exception_ids, &exception_len);
+                               warn_if (ret != CALENDAR_ERROR_NONE, "%s->%s",original_exdate,record_exdate);
+                               ret = __cal_db_event_delete_exception(exception_ids, exception_len);
+                               warn_if (ret != CALENDAR_ERROR_NONE, "__cal_db_event_delete_record() is failed");
+                               free(exception_ids);
+                       }
+                       ret = _cal_record_set_str(original_record, property_info[i].property_id, record_exdate);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+               }
+               else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_INT) == true)
+               {
+                       int tmp=0;
+                       ret = calendar_record_get_int(record,property_info[i].property_id,&tmp);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+                       ret = _cal_record_set_int(original_record, property_info[i].property_id, tmp);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+               }
+               else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_STR) == true)
+               {
+                       char *tmp=NULL;
+                       ret = calendar_record_get_str_p(record,property_info[i].property_id,&tmp);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+                       ret = _cal_record_set_str(original_record, property_info[i].property_id, tmp);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+               }
+               else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_DOUBLE) == true)
+               {
+                       double tmp=0;
+                       ret = calendar_record_get_double(record,property_info[i].property_id,&tmp);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+                       ret = _cal_record_set_double(original_record, property_info[i].property_id, tmp);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+               }
+               else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_LLI) == true)
+               {
+                       long long int tmp=0;
+                       ret = calendar_record_get_lli(record,property_info[i].property_id,&tmp);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+                       ret = _cal_record_set_lli(original_record, property_info[i].property_id, tmp);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+               }
+               else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_CALTIME) == true)
+               {
+                       calendar_time_s tmp = {0,};
+                       ret = calendar_record_get_caltime(record,property_info[i].property_id,&tmp);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+                       ret = _cal_record_set_caltime(original_record, property_info[i].property_id, tmp);
+                       if (ret != CALENDAR_ERROR_NONE)
+                               continue;
+               }
+       }
+       // child replace
+       cal_event_s *tmp = (cal_event_s *)original_record;
+       cal_event_s *tmp_src = (cal_event_s *)record;
+
+       if (tmp->alarm_list)
+               calendar_list_destroy((calendar_list_h)tmp->alarm_list, true);
+       _cal_list_clone((calendar_list_h)tmp_src->alarm_list, (calendar_list_h *)&tmp->alarm_list);
+
+       if (tmp->attendee_list)
+               calendar_list_destroy((calendar_list_h)tmp->attendee_list, true);
+       _cal_list_clone((calendar_list_h)tmp_src->attendee_list, (calendar_list_h *)&tmp->attendee_list);
+
+       if (tmp->exception_list)
+               calendar_list_destroy((calendar_list_h)tmp->exception_list, true);
+       _cal_list_clone((calendar_list_h)tmp_src->exception_list, (calendar_list_h *)&tmp->exception_list);
+
+       if (tmp->extended_list)
+               calendar_list_destroy((calendar_list_h)tmp->extended_list, true);
+       _cal_list_clone((calendar_list_h)tmp_src->extended_list, (calendar_list_h *)&tmp->extended_list);
+
+       CAL_RECORD_RESET_COMMON((cal_record_s*)original_record);
+       ret = __update_record(original_record, is_dirty_in_time);
+       calendar_record_destroy(original_record, true);
+
+       return ret;
+}
+
+static int __cal_db_event_exception_get_records(int original_id, cal_list_s *list)
+{
+       int ret;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == list, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter: list is NULL");
+
+       snprintf(query, sizeof(query),
+                       "SELECT * FROM %s "
+                       "WHERE original_event_id = %d AND is_deleted = 0 ",
+                       CAL_TABLE_SCHEDULE,
+                       original_id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() failed");
+
+       calendar_record_h record = NULL;
+
+       while (_cal_db_util_stmt_step(stmt) == CAL_DB_ROW) {
+               int exception = 0, extended = 0;
+               ret = calendar_record_create(_calendar_event._uri, &record);
+               if (CALENDAR_ERROR_NONE != ret) {
+                       sqlite3_finalize(stmt);
+                       _cal_list_clear(list);
+                       return ret;
+               }
+
+               __cal_db_event_get_stmt(stmt, false, record, &exception, &extended);
+
+               cal_rrule_s *rrule = NULL;
+               cal_event_s *event = (cal_event_s *)record;
+               if (_cal_db_rrule_get_rrule(event->index, &rrule) == CALENDAR_ERROR_NONE )
+               {
+                       _cal_db_rrule_set_rrule_to_event(rrule, record);
+                       CAL_FREE(rrule);
+               }
+
+               if (event->has_alarm == 1)
+                       _cal_db_alarm_get_records(event->index, event->alarm_list);
+
+               if (event->has_attendee == 1)
+                       _cal_db_attendee_get_records(event->index, event->attendee_list);
+
+               if (exception == 1)
+                       __cal_db_event_exception_get_records(event->index, event->exception_list);
+
+               if (extended == 1)
+                       _cal_db_extended_get_records(event->index, CALENDAR_RECORD_TYPE_EVENT, event->extended_list);
+
+               event->has_alarm = 0;
+               if (event->alarm_list && 0 < event->alarm_list->count)
+                       event->has_alarm = 1;
+
+               event->has_attendee = 0;
+               if (event->attendee_list && 0 < event->attendee_list->count)
+                       event->has_attendee = 1;
+
+               calendar_list_add((calendar_list_h)list, record);
+       }
+       sqlite3_finalize(stmt);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_exception_delete_with_id(int original_id)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       DBG("delete exception mod with original event id(%d)", original_id);
+       snprintf(query, sizeof(query), "DELETE FROM %s WHERE original_event_id=%d ",
+                       CAL_TABLE_SCHEDULE, original_id);
+
+       dbret = _cal_db_util_query_exec(query);
+       if (dbret != CAL_DB_OK) {
+               ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_exception_get_ids(int original_id, GList **out_list)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+       GList *list = NULL;
+
+       retvm_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter: GList is NULL");
+
+       snprintf(query, sizeof(query),
+                       "SELECT id FROM %s "
+                       "WHERE original_event_id = %d AND is_deleted = 0 ",
+                       CAL_TABLE_SCHEDULE,
+                       original_id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while (_cal_db_util_stmt_step(stmt) == CAL_DB_ROW)
+       {
+               int id = 0;
+               id = sqlite3_column_int(stmt, 0);
+               list = g_list_append(list, GINT_TO_POINTER(id));
+
+       }
+       sqlite3_finalize(stmt);
+
+       *out_list = list;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_exception_update(cal_list_s *exception_list_s, int original_id, int calendar_id, int is_dirty_in_time, time_t time_diff, int old_type, int new_type)
+{
+       int count = 0;
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_record_h exception = NULL;
+       calendar_list_h exception_list = (calendar_list_h)exception_list_s;
+       GList *id_list = NULL;
+
+       __cal_db_event_exception_get_ids(original_id, &id_list);
+
+       if (exception_list) {
+               calendar_list_get_count(exception_list, &count);
+               calendar_list_first(exception_list);
+               while (CALENDAR_ERROR_NONE == calendar_list_get_current_record_p(exception_list, &exception)) {
+                       int exception_id = 0;
+                       ret = calendar_record_get_int(exception,_calendar_event.id, &exception_id);
+                       DBG("exception(%d)", exception_id);
+                       if (exception_id > 0 && exception_id != original_id) { // update
+                               bool bchanged = false;
+                               cal_record_s *_record = NULL;
+                               const cal_property_info_s* property_info = NULL;
+                               int property_info_count = 0;
+
+                               _record = (cal_record_s *)exception;
+
+                               property_info = _cal_view_get_property_info(_record->view_uri, &property_info_count);
+
+                               // check updated
+                               int i;
+                               for (i = 0; i < property_info_count; i++) {
+                                       if ( true == _cal_record_check_property_flag(exception, property_info[i].property_id , CAL_PROPERTY_FLAG_DIRTY)) {
+                                               bchanged = true;
+                                               break;
+                                       }
+                               }
+
+                               if (bchanged == true || DIRTY_IN_TIME == is_dirty_in_time) {
+                                       // update
+                                       __update_recurrence_id(exception, old_type, new_type, time_diff);
+                                       __cal_db_event_update_record(exception);
+                                       _cal_db_instance_discard_record(exception_id);
+                                       _cal_db_instance_publish_record(exception);
+
+                               } else {
+                                       _cal_db_instance_discard_record(exception_id);
+                                       _cal_db_instance_publish_record(exception);
+                                       DBG("exception don't changed. exception_id=[%d]",exception_id);
+                               }
+
+                               if (id_list)
+                                       id_list = g_list_remove(id_list, GINT_TO_POINTER(exception_id) );
+
+                       } else { // insert
+                               ret = _cal_record_set_int(exception,_calendar_event.calendar_book_id, calendar_id);
+                               if (ret != CALENDAR_ERROR_NONE) {
+                                       ERR("set fail");
+                                       if (id_list)
+                                               g_list_free(id_list);
+                                       return ret;
+                               }
+                               ret = _cal_db_event_insert_record(exception, original_id, NULL);
+                               if (ret != CALENDAR_ERROR_NONE) {
+                                       ERR("set fail");
+                                       if (id_list)
+                                               g_list_free(id_list);
+                                       return ret;
+                               }
+                       }
+                       calendar_list_next(exception_list);
+               }
+       }
+
+       if (id_list) {
+               GList * tmp_list = g_list_first(id_list);
+               while(tmp_list) {
+                       int tmp = GPOINTER_TO_INT(tmp_list->data);
+                       char query[CAL_DB_SQL_MAX_LEN] = {0};
+                       cal_db_util_error_e dbret = CAL_DB_OK;
+
+                       snprintf(query, sizeof(query), "DELETE FROM %s WHERE id=%d ", CAL_TABLE_SCHEDULE, tmp);
+
+                       dbret = _cal_db_util_query_exec(query);
+                       if (dbret != CAL_DB_OK) {
+                               ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+                       }
+                       tmp_list = g_list_next(tmp_list);
+               }
+               g_list_free(id_list);
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_get_deleted_data(int id, int* calendar_book_id, int* created_ver,
+               int* original_event_id, char** recurrence_id)
+{
+       char query[CAL_DB_SQL_MAX_LEN];
+       sqlite3_stmt *stmt = NULL;
+
+       snprintf(query, sizeof(query), "SELECT calendar_id, created_ver, "
+                       "original_event_id, recurrence_id "
+                       "FROM %s WHERE id = %d ",
+                       CAL_TABLE_SCHEDULE, id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("query[%s]", query);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       const unsigned char *tmp;
+       if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               *calendar_book_id = sqlite3_column_int(stmt, 0);
+               *created_ver = sqlite3_column_int(stmt, 1);
+               *original_event_id = sqlite3_column_int(stmt, 2);
+               tmp = sqlite3_column_text(stmt, 3);
+               *recurrence_id = SAFE_STRDUP(tmp);
+       }
+       else
+       {
+               sqlite3_finalize(stmt);
+               stmt = NULL;
+               DBG("Failed to get deleted_data: event_id(%d)", id);
+               return CALENDAR_ERROR_DB_RECORD_NOT_FOUND;
+       }
+
+       sqlite3_finalize(stmt);
+       stmt = NULL;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_event_exdate_insert_normal(int event_id, const char* original_exdate, const char* exdate, int **exception_ids, int *exception_len)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       gchar **patterns1 = NULL;
+       gchar **patterns2 = NULL;
+       int len1 = 0, len2 = 0, i = 0, j = 0;
+
+       int input_ver = _cal_db_util_get_next_ver();
+       if (exdate != NULL && strlen(exdate) > 0)
+       {
+               patterns1 = g_strsplit_set(exdate, " ,", -1);
+               len1 = g_strv_length(patterns1);
+       }
+       if (original_exdate != NULL && strlen(original_exdate) > 0)
+       {
+               patterns2 = g_strsplit_set(original_exdate, " ,", -1);
+               len2 = g_strv_length(patterns2);
+       }
+
+       int *ids = calloc(len1, sizeof(int));
+       retvm_if (NULL == ids, CALENDAR_ERROR_DB_FAILED, "calloc() is failed");
+
+       int exception_count = 0;
+       for(i = 0; i < len1; i++)
+       {
+               bool bFind = false;
+               cal_db_util_error_e dbret = CAL_DB_OK;
+               for(j = 0; j < len2; j++)
+               {
+                       if (g_strcmp0(patterns1[i], patterns2[j]) == 0)
+                       {
+                               bFind = true;
+                               break;
+                       }
+               }
+               if (bFind == false)
+               {
+                       char query[CAL_DB_SQL_MAX_LEN] = {0};
+                       long long int start_utime = 0;
+                       char datetime[16] = {0};
+                       if (strlen(patterns1[i]) > strlen("YYYYMMDD"))
+                       {
+                               //DBG("NORMAL instance");
+                               int y, mon, d, h, min, s;
+                               sscanf(patterns1[i], "%04d%02d%02dT%02d%02d%02dZ",
+                                               &y, &mon, &d, &h, &min, &s);
+                               start_utime = _cal_time_convert_itol(NULL, y, mon, d, h, min, s);
+
+                               //DBG("(%lld)", start_utime);
+                       }
+                       else
+                       {
+                               //DBG("ALLDAY instance");
+                               snprintf(datetime, sizeof(datetime),
+                                               "%s", patterns1[i]);
+
+                       }
+                       // insert DB
+                       snprintf(query, sizeof(query),
+                                       "INSERT INTO %s ("
+                                       "type, "
+                                       "created_ver, changed_ver, "
+                                       "calendar_id, "
+                                       "original_event_id, "
+                                       "recurrence_id, "
+                                       "is_deleted, "
+                                       "dtstart_type, "
+                                       "dtstart_utime, "
+                                       "dtstart_datetime, "
+                                       "dtstart_tzid, "
+                                       "dtend_type, "
+                                       "dtend_utime, "
+                                       "dtend_datetime, "
+                                       "dtend_tzid"
+                                       ") SELECT %d,"
+                                       "created_ver, %d, "
+                                       "calendar_id, "
+                                       "%d, "
+                                       "'%s', "
+                                       "1, "
+                                       "dtstart_type, "
+                                       "%lld, "
+                                       "'%s', "
+                                       "dtstart_tzid, "
+                                       "dtend_type, "
+                                       "%lld+(dtend_utime-dtstart_utime), "
+                                       "'%s', "
+                                       "dtend_tzid "
+                                       "FROM %s "
+                                       "WHERE id = %d; ",
+                               CAL_TABLE_SCHEDULE,     // INSERT INTO
+                               CAL_SCH_TYPE_EVENT,     // type
+                               input_ver,   // ver
+                               event_id,               // original_event_id
+                               patterns1[i],
+                               start_utime,
+                               datetime,
+                               start_utime,
+                               datetime,
+                               CAL_TABLE_SCHEDULE,
+                               event_id
+                                       );
+                       dbret = _cal_db_util_query_exec(query);
+                       if (dbret != CAL_DB_OK)
+                       {
+                               DBG("query[%s]", query);
+                               ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+                       }
+                       int event_id = _cal_db_util_last_insert_id();
+                       DBG("last id(%d)", event_id);
+                       ids[exception_count] = event_id;
+                       exception_count++;
+               }
+       }
+       if (exception_ids) {
+               *exception_ids = ids;
+       } else {
+               free(ids);
+       }
+       if (exception_len) *exception_len = exception_count;
+
+       g_strfreev(patterns1);
+       g_strfreev(patterns2);
+       return ret;
+}
diff --git a/native/cal_db_plugin_extended.c b/native/cal_db_plugin_extended.c
new file mode 100644 (file)
index 0000000..641e22a
--- /dev/null
@@ -0,0 +1,849 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_db_query.h"
+#include "cal_db_extended.h"
+
+static int __cal_db_extended_insert_record( calendar_record_h record, int* id );
+static int __cal_db_extended_get_record( int id, calendar_record_h* out_record );
+static int __cal_db_extended_update_record( calendar_record_h record );
+static int __cal_db_extended_delete_record( int id );
+static int __cal_db_extended_get_all_records( int offset, int limit, calendar_list_h* out_list );
+static int __cal_db_extended_get_records_with_query( calendar_query_h query, int offset, int limit, calendar_list_h* out_list );
+static int __cal_db_extended_insert_records(const calendar_list_h list, int** ids);
+static int __cal_db_extended_update_records(const calendar_list_h list);
+static int __cal_db_extended_delete_records(int ids[], int count);
+static int __cal_db_extended_get_count(int *out_count);
+static int __cal_db_extended_get_count_with_query(calendar_query_h query, int *out_count);
+static int __cal_db_extended_replace_record(calendar_record_h record, int id);
+static int __cal_db_extended_replace_records(const calendar_list_h list, int ids[], int count);
+
+/*
+ * static function
+ */
+static void __cal_db_extended_get_stmt(sqlite3_stmt *stmt,calendar_record_h record);
+static void __cal_db_extended_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int stmt_count, calendar_record_h record);
+static void __cal_db_extended_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record);
+static void __cal_db_extended_get_stmt(sqlite3_stmt *stmt,calendar_record_h record);
+static int __cal_db_extended_update_projection(calendar_record_h record);
+
+cal_db_plugin_cb_s _cal_db_extended_plugin_cb = {
+       .is_query_only=false,
+       .insert_record=__cal_db_extended_insert_record,
+       .get_record=__cal_db_extended_get_record,
+       .update_record=__cal_db_extended_update_record,
+       .delete_record=__cal_db_extended_delete_record,
+       .get_all_records=__cal_db_extended_get_all_records,
+       .get_records_with_query=__cal_db_extended_get_records_with_query,
+       .insert_records=__cal_db_extended_insert_records,
+       .update_records=__cal_db_extended_update_records,
+       .delete_records=__cal_db_extended_delete_records,
+       .get_count=__cal_db_extended_get_count,
+       .get_count_with_query=__cal_db_extended_get_count_with_query,
+       .replace_record = __cal_db_extended_replace_record,
+       .replace_records = __cal_db_extended_replace_records
+};
+
+static int __cal_db_extended_insert_record( calendar_record_h record, int* id )
+{
+       cal_extended_s* extended =  (cal_extended_s*)(record);
+       retv_if(NULL == extended, CALENDAR_ERROR_INVALID_PARAMETER);
+       retvm_if(extended->record_id <= 0, CALENDAR_ERROR_INVALID_PARAMETER, "record_id(%d)", extended->record_id);
+       return _cal_db_extended_insert_record(record, extended->record_id, extended->record_type, id);
+}
+
+static int __cal_db_extended_get_record( int id, calendar_record_h* out_record )
+{
+       char query[CAL_DB_SQL_MAX_LEN];
+       sqlite3_stmt *stmt = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int ret = 0;
+
+       ret = calendar_record_create( _calendar_extended_property._uri ,out_record);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("record create fail");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       snprintf(query, sizeof(query), "SELECT * FROM %s WHERE id=%d",
+                       CAL_TABLE_EXTENDED, id);
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_record_destroy(*out_record, true);
+               *out_record = NULL;
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_ROW != dbret)
+       {
+               ERR("_cal_db_util_stmt_step() failed(%d)", dbret);
+               sqlite3_finalize(stmt);
+               calendar_record_destroy(*out_record, true);
+               *out_record = NULL;
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       __cal_db_extended_get_stmt(stmt,*out_record);
+
+       sqlite3_finalize(stmt);
+       stmt = NULL;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_extended_update_record( calendar_record_h record )
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_extended_s* extended_info =  (cal_extended_s*)(record);
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       retv_if(NULL == extended_info, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (extended_info->common.properties_flags != NULL)
+       {
+               return __cal_db_extended_update_projection(record);
+       }
+
+       snprintf(query, sizeof(query), "UPDATE %s SET "
+                       "record_id=%d,"
+                       "record_type=%d,"
+                       "key=?,"
+                       "value=? "
+                       "WHERE id = %d",
+                       CAL_TABLE_EXTENDED,
+                       extended_info->record_id,
+                       extended_info->record_type,
+                       extended_info->id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "cal_q_cal_db_util_query_prepareuery_prepare() Failed");
+
+       if (extended_info->key)
+               _cal_db_util_stmt_bind_text(stmt, 1, extended_info->key);
+
+       if (extended_info->value)
+               _cal_db_util_stmt_bind_text(stmt, 2, extended_info->value);
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       sqlite3_finalize(stmt);
+       if (CAL_DB_DONE != dbret)
+       {
+               ERR("cal_stmt_step() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_extended_delete_record( int id )
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       snprintf(query, sizeof(query), "DELETE FROM %s WHERE id = %d",
+                       CAL_TABLE_EXTENDED, id);
+       dbret = _cal_db_util_query_exec(query);
+       if(CAL_DB_OK != dbret)
+       {
+               ERR("_cal_db_util_query_exec() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_extended_replace_record(calendar_record_h record, int id)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_extended_s* extended_info =  (cal_extended_s*)(record);
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       retv_if(NULL == extended_info, CALENDAR_ERROR_INVALID_PARAMETER);
+       extended_info->id = id;
+
+       if (extended_info->common.properties_flags != NULL)
+       {
+               return __cal_db_extended_update_projection(record);
+       }
+
+       snprintf(query, sizeof(query), "UPDATE %s SET "
+                       "record_id=%d,"
+                       "record_type=%d,"
+                       "key=?,"
+                       "value=? "
+                       "WHERE id = %d",
+                       CAL_TABLE_EXTENDED,
+                       extended_info->record_id,
+                       extended_info->record_type,
+                       id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "cal_q_cal_db_util_query_prepareuery_prepare() Failed");
+
+       if (extended_info->key)
+               _cal_db_util_stmt_bind_text(stmt, 1, extended_info->key);
+
+       if (extended_info->value)
+               _cal_db_util_stmt_bind_text(stmt, 2, extended_info->value);
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       sqlite3_finalize(stmt);
+       if (CAL_DB_DONE != dbret)
+       {
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_extended_get_all_records( int offset, int limit, calendar_list_h* out_list )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char offsetquery[CAL_DB_SQL_MAX_LEN] = {0};
+       char limitquery[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = calendar_list_create(out_list);
+
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       if (offset > 0)
+       {
+               snprintf(offsetquery, sizeof(offsetquery), "OFFSET %d", offset);
+       }
+       if (limit > 0)
+       {
+               snprintf(limitquery, sizeof(limitquery), "LIMIT %d", limit);
+       }
+       snprintf(query, sizeof(query), "SELECT * FROM %s %s %s", CAL_TABLE_EXTENDED,limitquery,offsetquery);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_list_destroy(*out_list, true);
+               *out_list = NULL;
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_extended_property._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+               __cal_db_extended_get_stmt(stmt,record);
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+       }
+
+       sqlite3_finalize(stmt);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_extended_get_records_with_query( calendar_query_h query, int offset, int limit, calendar_list_h* out_list )
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *projection = NULL;
+       char *order = NULL;
+       GSList *bind_text = NULL, *cursor = NULL;
+       char *query_str = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int i = 0;
+
+       que = (cal_query_s *)query;
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // make projection
+       ret = _cal_db_query_create_projection(query, &projection);
+
+       // query - projection
+       if (projection)
+       {
+               _cal_db_append_string(&query_str, "SELECT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, "FROM");
+               _cal_db_append_string(&query_str, CAL_TABLE_EXTENDED);
+               CAL_FREE(projection);
+       }
+       else
+       {
+               _cal_db_append_string(&query_str, "SELECT * FROM");
+               _cal_db_append_string(&query_str, CAL_TABLE_EXTENDED);
+       }
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE");
+               _cal_db_append_string(&query_str, condition);
+               CAL_FREE(condition);
+       }
+
+       // ORDER
+       ret = _cal_db_query_create_order(query, condition, &order);
+       if (order)
+       {
+               _cal_db_append_string(&query_str, order);
+               CAL_FREE(order);
+       }
+
+       char buf[32] = {0};
+       if (0 < limit)
+       {
+               snprintf(buf, sizeof(buf), "LIMIT %d", limit);
+               _cal_db_append_string(&query_str, buf);
+               if (0 < offset)
+               {
+                       snprintf(buf, sizeof(buf), "OFFSET %d", offset);
+                       _cal_db_append_string(&query_str, buf);
+               }
+       }
+
+       // query
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       CAL_DBG("%s",query_str);
+
+       // bind text
+       if (bind_text)
+       {
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+               {
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+               }
+       }
+
+       //
+       ret = calendar_list_create(out_list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("calendar_list_create() Failed");
+               sqlite3_finalize(stmt);
+               return ret;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_extended_property._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       CAL_FREE(query_str);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+               if (que->projection_count > 0)
+               {
+                       _cal_record_set_projection(record,
+                                       que->projection, que->projection_count, que->property_count);
+
+                       __cal_db_extended_get_projection_stmt(stmt,
+                                       que->projection, que->projection_count,
+                                       record);
+               }
+               else
+               {
+                       __cal_db_extended_get_stmt(stmt,record);
+               }
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       CAL_FREE(query_str);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+       }
+
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       CAL_FREE(query_str);
+       sqlite3_finalize(stmt);
+
+       return CALENDAR_ERROR_NONE;
+}
+static int __cal_db_extended_insert_records(const calendar_list_h list, int** ids)
+{
+       calendar_record_h record;
+       int ret = 0;
+       int count = 0;
+       int i=0;
+       int *id = NULL;
+
+       ret = calendar_list_get_count(list, &count);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list get error");
+               return ret;
+       }
+
+       id = calloc(1, sizeof(int)*count);
+
+       retvm_if(NULL == id, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc fail");
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list first error");
+               CAL_FREE(id);
+               return ret;
+       }
+       do
+       {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE)
+               {
+                       if( __cal_db_extended_insert_record(record, &id[i]) != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("db insert error");
+                               CAL_FREE(id);
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+               i++;
+       } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+
+       if(ids)
+       {
+               *ids = id;
+       }
+       else
+       {
+               CAL_FREE(id);
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_extended_update_records(const calendar_list_h list)
+{
+       calendar_record_h record;
+       int ret = 0;
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list first error");
+               return ret;
+       }
+       do
+       {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE)
+               {
+                       if( __cal_db_extended_update_record(record) != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("db insert error");
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+       } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_extended_delete_records(int ids[], int count)
+{
+       int i=0;
+       for(i=0;i<count;i++)
+       {
+               if (__cal_db_extended_delete_record(ids[i]) != CALENDAR_ERROR_NONE)
+               {
+                       ERR("delete failed");
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_extended_replace_records(const calendar_list_h list, int ids[], int count)
+{
+       calendar_record_h record;
+       int i;
+       int ret = 0;
+
+       if (NULL == list)
+       {
+               ERR("Invalid argument: list is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list first error");
+               return ret;
+       }
+
+       for (i = 0; i < count; i++)
+       {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE)
+               {
+                       if( __cal_db_extended_replace_record(record, ids[i]) != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("db insert error");
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+               if (CALENDAR_ERROR_NO_DATA != calendar_list_next(list))
+               {
+                       break;
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_extended_get_count(int *out_count)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       int count = 0;
+       int ret;
+
+       retvm_if(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       snprintf(query, sizeof(query), "SELECT count(*) FROM %s ", CAL_TABLE_EXTENDED);
+
+       ret = _cal_db_util_query_get_first_int_result(query, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               return ret;
+       }
+       CAL_DBG("%s=%d",query,count);
+
+       *out_count = count;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_extended_get_count_with_query(calendar_query_h query, int *out_count)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *query_str = NULL;
+       char *table_name;
+       int count = 0;
+       GSList *bind_text = NULL;
+
+       que = (cal_query_s *)query;
+
+       if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_EXTENDED))
+       {
+               table_name = SAFE_STRDUP(CAL_TABLE_EXTENDED);
+       }
+       else
+       {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // query - select from
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, table_name);
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE");
+               _cal_db_append_string(&query_str, condition);
+               CAL_FREE(condition);
+       }
+
+       // query
+       ret = _cal_db_util_query_get_first_int_result(query_str, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("%s=%d",query_str,count);
+
+       *out_count = count;
+
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_db_extended_get_stmt(sqlite3_stmt *stmt,calendar_record_h record)
+{
+       cal_extended_s* extended =  (cal_extended_s*)(record);
+       int count = 0;
+       const unsigned char *temp;
+
+       extended->id = sqlite3_column_int(stmt, count++);
+       extended->record_id = sqlite3_column_int(stmt, count++);
+       extended->record_type = sqlite3_column_int(stmt, count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       extended->key = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       extended->value = SAFE_STRDUP(temp);
+}
+
+static void __cal_db_extended_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int stmt_count, calendar_record_h record)
+{
+       cal_extended_s* extended =  (cal_extended_s*)(record);
+       const unsigned char *temp;
+
+       switch(property)
+       {
+       case CAL_PROPERTY_EXTENDED_ID:
+               extended->id = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_EXTENDED_RECORD_ID:
+               extended->record_id = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_EXTENDED_RECORD_TYPE:
+               extended->record_type = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_EXTENDED_KEY:
+               temp = sqlite3_column_text(stmt, stmt_count);
+               extended->key = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_EXTENDED_VALUE:
+               temp = sqlite3_column_text(stmt, stmt_count);
+               extended->value = SAFE_STRDUP(temp);
+               break;
+       default:
+               sqlite3_column_int(stmt, stmt_count);
+               break;
+       }
+
+       return;
+}
+
+static void __cal_db_extended_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record)
+{
+       int i=0;
+
+       for(i=0;i<projection_count;i++)
+       {
+               __cal_db_extended_get_property_stmt(stmt,projection[i],i,record);
+       }
+}
+
+static int __cal_db_extended_update_projection(calendar_record_h record)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_extended_s* extended =  (cal_extended_s*)(record);
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int ret = CALENDAR_ERROR_NONE;
+       char* set = NULL;
+       GSList *bind_text = NULL;
+       GSList *cursor = NULL;
+
+       ret = _cal_db_query_create_projection_update_set(record,&set,&bind_text);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       snprintf(query, sizeof(query), "UPDATE %s SET %s "
+                       "WHERE id = %d",
+                       CAL_TABLE_EXTENDED,set,
+                       extended->id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt) {
+               ERR("_cal_db_util_query_prepare() Failed");
+               CAL_FREE(set);
+               if(bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       // bind
+       if (bind_text)
+       {
+               int i = 0;
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+               {
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+               }
+       }
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret)
+       {
+               sqlite3_finalize(stmt);
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+
+               CAL_FREE(set);
+               if(bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       sqlite3_finalize(stmt);
+
+       CAL_FREE(set);
+       if(bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/native/cal_db_plugin_instance_allday.c b/native/cal_db_plugin_instance_allday.c
new file mode 100644 (file)
index 0000000..3bf94fd
--- /dev/null
@@ -0,0 +1,699 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_db_query.h"
+#include "cal_access_control.h"
+
+//static int __cal_db_instance_allday_get_record(int id, calendar_record_h* out_record);
+//static int __cal_db_instance_allday_update_record(calendar_record_h record);
+static int __cal_db_instance_allday_delete_record(int id);
+static int __cal_db_instance_allday_get_all_records(int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_instance_allday_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list);
+//static int __cal_db_instance_allday_insert_records(const calendar_list_h list);
+//static int __cal_db_instance_allday_update_records(const calendar_list_h list);
+//static int __cal_db_instance_allday_delete_records(int ids[], int count);
+static int __cal_db_instance_allday_get_count(int *out_count);
+static int __cal_db_instance_allday_get_count_with_query(calendar_query_h query, int *out_count);
+
+/*
+ * static function
+ */
+static void __cal_db_instance_allday_get_stmt(sqlite3_stmt *stmt,calendar_record_h record);
+static void __cal_db_instance_allday_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record);
+static void __cal_db_instance_allday_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record);
+
+cal_db_plugin_cb_s _cal_db_instance_allday_plugin_cb = {
+       .is_query_only = false,
+       .insert_record=NULL,
+       .get_record=NULL,
+       .update_record=NULL,
+       .delete_record=__cal_db_instance_allday_delete_record,
+       .get_all_records=__cal_db_instance_allday_get_all_records,
+       .get_records_with_query=__cal_db_instance_allday_get_records_with_query,
+       .insert_records=NULL,
+       .update_records=NULL,
+       .delete_records=NULL,
+       .get_count=__cal_db_instance_allday_get_count,
+       .get_count_with_query=__cal_db_instance_allday_get_count_with_query,
+       .replace_record=NULL,
+       .replace_records=NULL
+};
+
+static int __cal_db_instance_allday_delete_record(int id)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       retvm_if(id < 0, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid argument: id(%d) < 0", id);
+
+       snprintf(query, sizeof(query),
+                       "DELETE FROM %s "
+                       "WHERE event_id = %d ",
+                       CAL_TABLE_ALLDAY_INSTANCE,
+                       id);
+
+       dbret = _cal_db_util_query_exec(query);
+       if (CAL_DB_OK != dbret)
+       {
+               ERR("_cal_db_util_query_exec() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_allday_get_all_records(int offset, int limit, calendar_list_h* out_list)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char offsetquery[CAL_DB_SQL_MAX_LEN] = {0};
+       char limitquery[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = calendar_list_create(out_list);
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       if (offset > 0)
+       {
+               snprintf(offsetquery, sizeof(offsetquery), "OFFSET %d", offset);
+       }
+       if (limit > 0)
+       {
+               snprintf(limitquery, sizeof(limitquery), "LIMIT %d", limit);
+       }
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT * FROM");
+       _cal_db_append_string(&query_str, CAL_VIEW_TABLE_ALLDAY_INSTANCE);
+       _cal_db_append_string(&query_str, limitquery);
+       _cal_db_append_string(&query_str, offsetquery);
+
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_list_destroy(*out_list, true);
+               *out_list = NULL;
+               CAL_FREE(query_str);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_instance_localtime_calendar_book._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+
+               __cal_db_instance_allday_get_stmt(stmt, record);
+
+               ret = calendar_list_add(*out_list, record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_allday_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *projection = NULL;
+       GSList *bind_text = NULL, *cursor = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int i = 0;
+       char *table_name;
+
+       que = (cal_query_s *)query;
+
+       if (0 == strcmp(que->view_uri, CALENDAR_VIEW_INSTANCE_LOCALTIME_CALENDAR))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_ALLDAY_INSTANCE);
+       }
+       else if (0 == strcmp(que->view_uri, CALENDAR_VIEW_INSTANCE_LOCALTIME_CALENDAR_EXTENDED) )
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_ALLDAY_INSTANCE_EXTENDED);
+       }
+       else
+       {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+               //table_name = SAFE_STRDUP(CAL_TABLE_ALLDAY_INSTANCE);
+       }
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // make projection
+       ret = _cal_db_query_create_projection(query, &projection);
+
+       char *query_str = NULL;
+       // query - projection
+       if (projection)
+       {
+               _cal_db_append_string(&query_str, "SELECT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, "FROM");
+               _cal_db_append_string(&query_str, table_name);
+               CAL_FREE(projection);
+       }
+       else
+       {
+               _cal_db_append_string(&query_str, "SELECT * FROM");
+               _cal_db_append_string(&query_str, table_name);
+       }
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str,  "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+       }
+
+       // ORDER
+       char *order = NULL;
+       ret = _cal_db_query_create_order(query, condition, &order);
+       if (order)
+       {
+               _cal_db_append_string(&query_str, order);
+               CAL_FREE(order);
+       }
+       CAL_FREE(condition);
+
+       // limit, offset
+       char buf[32] = {0};
+       if (limit > 0)
+       {
+               snprintf(buf, sizeof(buf), "LIMIT %d", limit);
+               _cal_db_append_string(&query_str, buf);
+
+               if (offset > 0)
+               {
+                       snprintf(buf, sizeof(buf), "OFFSET %d", offset);
+                       _cal_db_append_string(&query_str, buf);
+               }
+       }
+
+       // query
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       CAL_DBG("%s",query_str);
+
+       // bind text
+       if (bind_text)
+       {
+               g_slist_length(bind_text);
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+               {
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+               }
+       }
+
+       //
+       ret = calendar_list_create(out_list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               ERR("calendar_list_create() Failed");
+               sqlite3_finalize(stmt);
+               CAL_FREE(query_str);
+               return ret;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(que->view_uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+               if (que->projection_count > 0)
+               {
+                       _cal_record_set_projection(record,
+                                       que->projection, que->projection_count, que->property_count);
+
+                       __cal_db_instance_allday_get_projection_stmt(stmt,
+                                       que->projection, que->projection_count,
+                                       record);
+               }
+               else
+               {
+                       __cal_db_instance_allday_get_stmt(stmt,record);
+               }
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_allday_get_count(int *out_count)
+{
+       retvm_if(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, CAL_TABLE_ALLDAY_INSTANCE);
+
+       int ret = 0;
+       int count = 0;
+       ret = _cal_db_util_query_get_first_int_result(query_str, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+       CAL_FREE(query_str);
+
+       *out_count = count;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_allday_get_count_with_query(calendar_query_h query, int *out_count)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *table_name;
+       int count = 0;
+       GSList *bind_text = NULL;
+
+       que = (cal_query_s *)query;
+
+       if (0 == strcmp(que->view_uri, CALENDAR_VIEW_INSTANCE_LOCALTIME_CALENDAR))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_ALLDAY_INSTANCE);
+       }
+       else if (0 == strcmp(que->view_uri, CALENDAR_VIEW_INSTANCE_LOCALTIME_CALENDAR_EXTENDED) )
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_ALLDAY_INSTANCE_EXTENDED);
+       }
+       else
+       {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+               //table_name = SAFE_STRDUP(CAL_TABLE_ALLDAY_INSTANCE);
+       }
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       char *query_str = NULL;
+       // query - select from
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, table_name);
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+               CAL_FREE(condition);
+       }
+
+       // query
+       ret = _cal_db_util_query_get_first_int_result(query_str, bind_text, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+
+       if (out_count) *out_count = count;
+
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_db_instance_allday_get_stmt(sqlite3_stmt *stmt,calendar_record_h record)
+{
+       cal_instance_allday_s* instance =  (cal_instance_allday_s*)(record);
+       const unsigned char *temp;
+       char *dtstart_datetime;
+       char *dtend_datetime;
+       char buf[8] = {0};
+       int count = 0;
+
+       instance->event_id = sqlite3_column_int(stmt, count++);
+       instance->start.type = sqlite3_column_int(stmt, count++);
+       sqlite3_column_int64(stmt, count++);//instance->start.time.date.utime = sqlite3_column_int64(stmt, count++);
+       temp = sqlite3_column_text(stmt, count++);
+       if (temp) {
+               dtstart_datetime = SAFE_STRDUP(temp);
+               snprintf(buf, strlen("YYYY") + 1, "%s", dtstart_datetime);
+               instance->start.time.date.year =  atoi(buf);
+               snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 5);
+               instance->start.time.date.month = atoi(buf);
+               snprintf(buf, strlen("DD") + 1, "%s", dtstart_datetime + 8);
+               instance->start.time.date.mday = atoi(buf);
+               snprintf(buf, strlen("HH") + 1, "%s", dtstart_datetime + 11);
+               instance->start.time.date.hour = atoi(buf);
+               snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 14);
+               instance->start.time.date.minute = atoi(buf);
+               snprintf(buf, strlen("SS") + 1, "%s", dtstart_datetime + 17);
+               instance->start.time.date.second = atoi(buf);
+               if (dtstart_datetime)
+                       free(dtstart_datetime);
+       }
+
+       instance->end.type = sqlite3_column_int(stmt, count++);
+       sqlite3_column_int64(stmt, count++);//instance->end.time.date.utime = sqlite3_column_int64(stmt, count++);
+       temp = sqlite3_column_text(stmt, count++);
+       if (temp) {
+               dtend_datetime = SAFE_STRDUP(temp);
+               snprintf(buf, strlen("YYYY") + 1, "%s", dtend_datetime);
+               instance->end.time.date.year =  atoi(buf);
+               snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 5);
+               instance->end.time.date.month = atoi(buf);
+               snprintf(buf, strlen("DD") + 1, "%s", dtend_datetime + 8);
+               instance->end.time.date.mday = atoi(buf);
+               snprintf(buf, strlen("HH") + 1, "%s", dtend_datetime + 11);
+               instance->end.time.date.hour = atoi(buf);
+               snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 14);
+               instance->end.time.date.minute = atoi(buf);
+               snprintf(buf, strlen("SS") + 1, "%s", dtend_datetime + 17);
+               instance->end.time.date.second = atoi(buf);
+               if (dtend_datetime)
+                       free(dtend_datetime);
+       }
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->summary = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->description = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->location = SAFE_STRDUP(temp);
+
+       instance->busy_status = sqlite3_column_int(stmt, count++);
+
+       instance->event_status = sqlite3_column_int(stmt, count++);
+
+       instance->priority = sqlite3_column_int(stmt, count++);
+
+       instance->sensitivity = sqlite3_column_int(stmt, count++);
+
+       instance->has_rrule = sqlite3_column_int(stmt, count++);
+       if (instance->has_rrule > 0)
+       {
+               instance->has_rrule = 1;
+       }
+
+       instance->latitude = sqlite3_column_double(stmt,count++);
+       instance->longitude = sqlite3_column_double(stmt,count++);
+       instance->has_alarm = sqlite3_column_int(stmt,count++);
+       instance->original_event_id = sqlite3_column_int(stmt, count++);
+       instance->calendar_id = sqlite3_column_int(stmt, count++);
+       instance->last_mod = sqlite3_column_int64(stmt, count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->sync_data1 = SAFE_STRDUP(temp);
+
+       instance->is_allday = sqlite3_column_int(stmt, count++);
+
+       return;
+}
+
+static void __cal_db_instance_allday_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record)
+{
+       cal_instance_allday_s* instance =  (cal_instance_allday_s*)(record);
+       const unsigned char *temp;
+       char *dtstart_datetime;
+       char *dtend_datetime;
+       char buf[8] = {0};
+
+       switch(property)
+       {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_START:
+               sqlite3_column_int(stmt,*stmt_count);
+               *stmt_count = *stmt_count+1;
+               sqlite3_column_int64(stmt,*stmt_count);
+               *stmt_count = *stmt_count+1;
+               instance->start.type = CALENDAR_TIME_LOCALTIME;//sqlite3_column_int(stmt, *stmt_count);
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               if (temp) {
+                       dtstart_datetime = SAFE_STRDUP(temp);
+                       snprintf(buf, strlen("YYYY") + 1, "%s", dtstart_datetime);
+                       instance->start.time.date.year =  atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 5);
+                       instance->start.time.date.month = atoi(buf);
+                       snprintf(buf, strlen("DD") + 1, "%s", dtstart_datetime + 8);
+                       instance->start.time.date.mday = atoi(buf);
+                       snprintf(buf, strlen("HH") + 1, "%s", dtstart_datetime + 11);
+                       instance->start.time.date.hour = atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 14);
+                       instance->start.time.date.minute = atoi(buf);
+                       snprintf(buf, strlen("SS") + 1, "%s", dtstart_datetime + 17);
+                       instance->start.time.date.second = atoi(buf);
+                       if (dtstart_datetime)
+                               free(dtstart_datetime);
+               }
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_END:
+               sqlite3_column_int(stmt,*stmt_count);
+               *stmt_count = *stmt_count+1;
+               sqlite3_column_int64(stmt,*stmt_count);
+               *stmt_count = *stmt_count+1;
+               instance->end.type = CALENDAR_TIME_LOCALTIME; //sqlite3_column_int(stmt, *stmt_count);
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               if (temp) {
+                       dtend_datetime = SAFE_STRDUP(temp);
+                       snprintf(buf, strlen("YYYY") + 1, "%s", dtend_datetime);
+                       instance->end.time.date.year =  atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 5);
+                       instance->end.time.date.month = atoi(buf);
+                       snprintf(buf, strlen("DD") + 1, "%s", dtend_datetime + 8);
+                       instance->end.time.date.mday = atoi(buf);
+                       snprintf(buf, strlen("HH") + 1, "%s", dtend_datetime + 11);
+                       instance->end.time.date.hour = atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 14);
+                       instance->end.time.date.minute = atoi(buf);
+                       snprintf(buf, strlen("SS") + 1, "%s", dtend_datetime + 17);
+                       instance->end.time.date.second = atoi(buf);
+                       if (dtend_datetime)
+                               free(dtend_datetime);
+               }
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_SUMMARY:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->summary = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_LOCATION:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->location = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_CALENDAR_ID:
+               instance->calendar_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_DESCRIPTION:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->description = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_BUSY_STATUS:
+               instance->busy_status = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EVENT_STATUS:
+               instance->event_status = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_PRIORITY:
+               instance->priority = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_SENSITIVITY:
+               instance->sensitivity = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_HAS_RRULE:
+               instance->has_rrule = sqlite3_column_int(stmt, *stmt_count);
+               if (instance->has_rrule > 0)
+               {
+                       instance->has_rrule = 1;
+               }
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_LATITUDE:
+               instance->latitude = sqlite3_column_double(stmt,*stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_LONGITUDE:
+               instance->longitude = sqlite3_column_double(stmt,*stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EVENT_ID:
+               instance->event_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_HAS_ALARM:
+               instance->has_alarm = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_ORIGINAL_EVENT_ID:
+               instance->original_event_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_LAST_MODIFIED_TIME:
+               instance->last_mod = sqlite3_column_int64(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_SYNC_DATA1:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->sync_data1 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_IS_ALLDAY:
+               instance->is_allday = sqlite3_column_int64(stmt, *stmt_count);
+               break;
+
+       default:
+               sqlite3_column_int(stmt, *stmt_count);
+               break;
+       }
+
+       *stmt_count = *stmt_count+1;
+
+       return;
+}
+
+static void __cal_db_instance_allday_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record)
+{
+       int i=0;
+       int stmt_count = 0;
+
+       for(i=0;i<projection_count;i++)
+       {
+               __cal_db_instance_allday_get_property_stmt(stmt,projection[i],&stmt_count,record);
+       }
+}
diff --git a/native/cal_db_plugin_instance_allday_extended.c b/native/cal_db_plugin_instance_allday_extended.c
new file mode 100755 (executable)
index 0000000..82a4f0a
--- /dev/null
@@ -0,0 +1,678 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_db_query.h"
+#include "cal_access_control.h"
+
+static int __cal_db_instance_allday_extended_get_all_records(int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_instance_allday_extended_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_instance_allday_extended_get_count(int *out_count);
+static int __cal_db_instance_allday_extended_get_count_with_query(calendar_query_h query, int *out_count);
+
+/*
+ * static function
+ */
+static void __cal_db_instance_allday_extended_get_stmt(sqlite3_stmt *stmt,calendar_record_h record);
+static void __cal_db_instance_allday_extended_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record);
+static void __cal_db_instance_allday_extended_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record);
+
+cal_db_plugin_cb_s _cal_db_instance_allday_extended_plugin_cb = {
+       .is_query_only = false,
+       .insert_record= NULL,
+       .get_record= NULL,
+       .update_record=NULL,
+       .delete_record=NULL,
+       .get_all_records=__cal_db_instance_allday_extended_get_all_records,
+       .get_records_with_query=__cal_db_instance_allday_extended_get_records_with_query,
+       .insert_records=NULL,
+       .update_records=NULL,
+       .delete_records=NULL,
+       .get_count=__cal_db_instance_allday_extended_get_count,
+       .get_count_with_query=__cal_db_instance_allday_extended_get_count_with_query,
+       .replace_record=NULL,
+       .replace_records=NULL
+};
+
+static int __cal_db_instance_allday_extended_get_all_records(int offset, int limit, calendar_list_h* out_list)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char offsetquery[CAL_DB_SQL_MAX_LEN] = {0};
+       char limitquery[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = calendar_list_create(out_list);
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       if (offset > 0)
+       {
+               snprintf(offsetquery, sizeof(offsetquery), "OFFSET %d", offset);
+       }
+       if (limit > 0)
+       {
+               snprintf(limitquery, sizeof(limitquery), "LIMIT %d", limit);
+       }
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT * FROM");
+       _cal_db_append_string(&query_str, CAL_VIEW_TABLE_ALLDAY_INSTANCE_EXTENDED);
+       _cal_db_append_string(&query_str, limitquery);
+       _cal_db_append_string(&query_str, offsetquery);
+
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_list_destroy(*out_list, true);
+               *out_list = NULL;
+               CAL_FREE(query_str);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_instance_localtime_calendar_book_extended._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+               __cal_db_instance_allday_extended_get_stmt(stmt,record);
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_allday_extended_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *projection = NULL;
+       GSList *bind_text = NULL, *cursor = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int i = 0;
+       char *table_name;
+
+       que = (cal_query_s *)query;
+
+       table_name = SAFE_STRDUP(CAL_VIEW_TABLE_ALLDAY_INSTANCE_EXTENDED);
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // make projection
+       ret = _cal_db_query_create_projection(query, &projection);
+
+       char *query_str = NULL;
+       // query - projection
+       if (projection)
+       {
+               _cal_db_append_string(&query_str, "SELECT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, "FROM");
+               _cal_db_append_string(&query_str, table_name);
+               CAL_FREE(projection);
+       }
+       else
+       {
+               _cal_db_append_string(&query_str, "SELECT * FROM");
+               _cal_db_append_string(&query_str, table_name);
+       }
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+       }
+
+       // ORDER
+       char *order = NULL;
+       ret = _cal_db_query_create_order(query, condition, &order);
+       if (order)
+       {
+               _cal_db_append_string(&query_str, order);
+               CAL_FREE(order);
+       }
+       CAL_FREE(condition);
+
+       // limit, offset
+       char buf[32] = {0};
+       if (limit > 0)
+       {
+               snprintf(buf, sizeof(buf), "LIMIT %d", limit);
+               _cal_db_append_string(&query_str, buf);
+
+               if (offset > 0)
+               {
+                       snprintf(buf, sizeof(buf), "OFFSET %d", offset);
+                       _cal_db_append_string(&query_str, buf);
+               }
+       }
+
+       // query
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               CAL_DBG("%s",query_str);
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       // bind text
+       if (bind_text)
+       {
+               g_slist_length(bind_text);
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+               {
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+               }
+       }
+
+       //
+       ret = calendar_list_create(out_list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               ERR("calendar_list_create() Failed");
+               sqlite3_finalize(stmt);
+               CAL_FREE(query_str);
+               return ret;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(que->view_uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+               if (que->projection_count > 0)
+               {
+                       _cal_record_set_projection(record,
+                                       que->projection, que->projection_count, que->property_count);
+
+                       __cal_db_instance_allday_extended_get_projection_stmt(stmt,
+                                       que->projection, que->projection_count,
+                                       record);
+               }
+               else
+               {
+                       __cal_db_instance_allday_extended_get_stmt(stmt,record);
+               }
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_allday_extended_get_count(int *out_count)
+{
+       retvm_if(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, CAL_VIEW_TABLE_ALLDAY_INSTANCE_EXTENDED);
+
+       int ret = 0;
+       int count = 0;
+       ret = _cal_db_util_query_get_first_int_result(query_str, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+       CAL_FREE(query_str);
+
+       *out_count = count;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_allday_extended_get_count_with_query(calendar_query_h query, int *out_count)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *table_name;
+       int count = 0;
+       GSList *bind_text = NULL;
+
+       que = (cal_query_s *)query;
+
+       table_name = SAFE_STRDUP(CAL_VIEW_TABLE_ALLDAY_INSTANCE_EXTENDED);
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       char *query_str = NULL;
+       // query - select from
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, table_name);
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+               CAL_FREE(condition);
+       }
+
+       // query
+       ret = _cal_db_util_query_get_first_int_result(query_str, bind_text, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+
+       if (out_count) *out_count = count;
+
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_db_instance_allday_extended_get_stmt(sqlite3_stmt *stmt,calendar_record_h record)
+{
+       cal_instance_allday_extended_s* instance =  (cal_instance_allday_extended_s*)(record);
+       const unsigned char *temp;
+       char *dtstart_datetime;
+       char *dtend_datetime;
+       char buf[8] = {0};
+       int count = 0;
+
+       instance->event_id = sqlite3_column_int(stmt, count++);
+       instance->start.type = sqlite3_column_int(stmt, count++);
+       sqlite3_column_int64(stmt, count++);//instance->start.time.date.utime = sqlite3_column_int64(stmt, count++);
+       temp = sqlite3_column_text(stmt, count++);
+       if (temp) {
+               dtstart_datetime = SAFE_STRDUP(temp);
+               snprintf(buf, strlen("YYYY") + 1, "%s", dtstart_datetime);
+               instance->start.time.date.year =  atoi(buf);
+               snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 5);
+               instance->start.time.date.month = atoi(buf);
+               snprintf(buf, strlen("DD") + 1, "%s", dtstart_datetime + 8);
+               instance->start.time.date.mday = atoi(buf);
+               snprintf(buf, strlen("HH") + 1, "%s", dtstart_datetime + 11);
+               instance->start.time.date.hour = atoi(buf);
+               snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 14);
+               instance->start.time.date.minute = atoi(buf);
+               snprintf(buf, strlen("SS") + 1, "%s", dtstart_datetime + 17);
+               instance->start.time.date.second = atoi(buf);
+               if (dtstart_datetime)
+                       free(dtstart_datetime);
+       }
+
+       instance->end.type = sqlite3_column_int(stmt, count++);
+       sqlite3_column_int64(stmt, count++);//instance->end.time.date.utime = sqlite3_column_int64(stmt, count++);
+       temp = sqlite3_column_text(stmt, count++);
+       if (temp) {
+               dtend_datetime = SAFE_STRDUP(temp);
+               snprintf(buf, strlen("YYYY") + 1, "%s", dtend_datetime);
+               instance->end.time.date.year =  atoi(buf);
+               snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 5);
+               instance->end.time.date.month = atoi(buf);
+               snprintf(buf, strlen("DD") + 1, "%s", dtend_datetime + 8);
+               instance->end.time.date.mday = atoi(buf);
+               snprintf(buf, strlen("HH") + 1, "%s", dtend_datetime + 11);
+               instance->end.time.date.hour = atoi(buf);
+               snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 14);
+               instance->end.time.date.minute = atoi(buf);
+               snprintf(buf, strlen("SS") + 1, "%s", dtend_datetime + 17);
+               instance->end.time.date.second = atoi(buf);
+               if (dtend_datetime)
+                       free(dtend_datetime);
+       }
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->summary = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->description = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->location = SAFE_STRDUP(temp);
+
+       instance->busy_status = sqlite3_column_int(stmt, count++);
+
+       instance->event_status = sqlite3_column_int(stmt, count++);
+
+       instance->priority = sqlite3_column_int(stmt, count++);
+
+       instance->sensitivity = sqlite3_column_int(stmt, count++);
+
+       instance->has_rrule = sqlite3_column_int(stmt, count++);
+       if (instance->has_rrule > 0)
+       {
+               instance->has_rrule = 1;
+       }
+
+       instance->latitude = sqlite3_column_double(stmt,count++);
+       instance->longitude = sqlite3_column_double(stmt,count++);
+       instance->has_alarm = sqlite3_column_int(stmt,count++);
+       instance->original_event_id = sqlite3_column_int(stmt, count++);
+       instance->calendar_id = sqlite3_column_int(stmt, count++);
+
+       instance->last_mod = sqlite3_column_int64(stmt, count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->sync_data1 = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->organizer_name = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->categories= SAFE_STRDUP(temp);
+
+       instance->has_attendee= sqlite3_column_int(stmt, count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->sync_data2 = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->sync_data3 = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->sync_data4 = SAFE_STRDUP(temp);
+
+       instance->is_allday = sqlite3_column_int(stmt, count++);
+
+       return;
+}
+
+static void __cal_db_instance_allday_extended_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record)
+{
+       cal_instance_allday_extended_s* instance =  (cal_instance_allday_extended_s*)(record);
+       const unsigned char *temp;
+       char *dtstart_datetime;
+       char *dtend_datetime;
+       char buf[8] = {0};
+
+       switch(property)
+       {
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_START:
+               sqlite3_column_int(stmt,*stmt_count);
+               *stmt_count = *stmt_count+1;
+               sqlite3_column_int64(stmt,*stmt_count);
+               *stmt_count = *stmt_count+1;
+               instance->start.type = CALENDAR_TIME_LOCALTIME;//sqlite3_column_int(stmt, *stmt_count);
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               if (temp) {
+                       dtstart_datetime = SAFE_STRDUP(temp);
+                       snprintf(buf, strlen("YYYY") + 1, "%s", dtstart_datetime);
+                       instance->start.time.date.year =  atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 5);
+                       instance->start.time.date.month = atoi(buf);
+                       snprintf(buf, strlen("DD") + 1, "%s", dtstart_datetime + 8);
+                       instance->start.time.date.mday = atoi(buf);
+                       snprintf(buf, strlen("HH") + 1, "%s", dtstart_datetime + 11);
+                       instance->start.time.date.hour = atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 14);
+                       instance->start.time.date.minute = atoi(buf);
+                       snprintf(buf, strlen("SS") + 1, "%s", dtstart_datetime + 17);
+                       instance->start.time.date.second = atoi(buf);
+                       if (dtstart_datetime)
+                               free(dtstart_datetime);
+               }
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_END:
+               sqlite3_column_int(stmt,*stmt_count);
+               *stmt_count = *stmt_count+1;
+               sqlite3_column_int64(stmt,*stmt_count);
+               *stmt_count = *stmt_count+1;
+               instance->end.type = CALENDAR_TIME_LOCALTIME; //sqlite3_column_int(stmt, *stmt_count);
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               if (temp) {
+                       dtend_datetime = SAFE_STRDUP(temp);
+                       snprintf(buf, strlen("YYYY") + 1, "%s", dtend_datetime);
+                       instance->end.time.date.year =  atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 5);
+                       instance->end.time.date.month = atoi(buf);
+                       snprintf(buf, strlen("DD") + 1, "%s", dtend_datetime + 8);
+                       instance->end.time.date.mday = atoi(buf);
+                       snprintf(buf, strlen("HH") + 1, "%s", dtend_datetime + 11);
+                       instance->end.time.date.hour = atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 14);
+                       instance->end.time.date.minute = atoi(buf);
+                       snprintf(buf, strlen("SS") + 1, "%s", dtend_datetime + 17);
+                       instance->end.time.date.second = atoi(buf);
+                       if (dtend_datetime)
+                               free(dtend_datetime);
+               }
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SUMMARY:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->summary = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LOCATION:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->location = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_CALENDAR_ID:
+               instance->calendar_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_DESCRIPTION:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->description = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_BUSY_STATUS:
+               instance->busy_status = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_EVENT_STATUS:
+               instance->event_status = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_PRIORITY:
+               instance->priority = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SENSITIVITY:
+               instance->sensitivity = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_RRULE:
+               instance->has_rrule = sqlite3_column_int(stmt, *stmt_count);
+               if (instance->has_rrule > 0)
+               {
+                       instance->has_rrule = 1;
+               }
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LATITUDE:
+               instance->latitude = sqlite3_column_double(stmt,*stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LONGITUDE:
+               instance->longitude = sqlite3_column_double(stmt,*stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_EVENT_ID:
+               instance->event_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_ALARM:
+               instance->has_alarm = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_ORIGINAL_EVENT_ID:
+               instance->original_event_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_LAST_MODIFIED_TIME:
+               instance->last_mod = sqlite3_column_int64(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA1:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->sync_data1 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_ORGANIZER_NAME:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->organizer_name= SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_CATEGORIES:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->categories= SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_HAS_ATTENDEE:
+               instance->has_attendee= sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA2:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->sync_data2= SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA3:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->sync_data3 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_SYNC_DATA4:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->sync_data4= SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_ALLDAY_EXTENDED_IS_ALLDAY:
+               instance->is_allday = sqlite3_column_int(stmt, *stmt_count);
+               break;
+
+       default:
+               sqlite3_column_int(stmt, *stmt_count);
+               break;
+       }
+
+       *stmt_count = *stmt_count+1;
+
+       return;
+}
+
+static void __cal_db_instance_allday_extended_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record)
+{
+       int i=0;
+       int stmt_count = 0;
+
+       for(i=0;i<projection_count;i++)
+       {
+               __cal_db_instance_allday_extended_get_property_stmt(stmt,projection[i],&stmt_count,record);
+       }
+}
diff --git a/native/cal_db_plugin_instance_normal.c b/native/cal_db_plugin_instance_normal.c
new file mode 100644 (file)
index 0000000..45ae780
--- /dev/null
@@ -0,0 +1,615 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_db_query.h"
+#include "cal_access_control.h"
+
+//static int __cal_db_instance_normal_get_record(int id, calendar_record_h* out_record);
+//static int __cal_db_instance_normal_update_record(calendar_record_h record);
+static int __cal_db_instance_normal_delete_record(int id);
+static int __cal_db_instance_normal_get_all_records(int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_instance_normal_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list);
+//static int __cal_db_instance_normal_insert_records(const calendar_list_h list);
+//static int __cal_db_instance_normal_update_records(const calendar_list_h list);
+//static int __cal_db_instance_normal_delete_records(int ids[], int count);
+static int __cal_db_instance_normal_get_count(int *out_count);
+static int __cal_db_instance_normal_get_count_with_query(calendar_query_h query, int *out_count);
+/*
+ * static function
+ */
+static void __cal_db_instance_normal_get_stmt(sqlite3_stmt *stmt,calendar_record_h record);
+static void __cal_db_instance_normal_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record);
+static void __cal_db_instance_normal_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record);
+
+cal_db_plugin_cb_s _cal_db_instance_normal_plugin_cb = {
+       .is_query_only = false,
+       .insert_record=NULL,
+       .get_record=NULL,
+       .update_record=NULL,
+       .delete_record=__cal_db_instance_normal_delete_record,
+       .get_all_records=__cal_db_instance_normal_get_all_records,
+       .get_records_with_query=__cal_db_instance_normal_get_records_with_query,
+       .insert_records=NULL,
+       .update_records=NULL,
+       .delete_records=NULL,
+       .get_count=__cal_db_instance_normal_get_count,
+       .get_count_with_query=__cal_db_instance_normal_get_count_with_query,
+       .replace_record=NULL,
+       .replace_records=NULL
+};
+
+static int __cal_db_instance_normal_delete_record(int id)
+{
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+
+       retvm_if(id < 0, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid argument: id(%d) < 0", id);
+
+       snprintf(query, sizeof(query),
+                       "DELETE FROM %s "
+                       "WHERE event_id = %d ",
+                       CAL_TABLE_NORMAL_INSTANCE,
+                       id);
+
+       dbret = _cal_db_util_query_exec(query);
+       if (dbret != CAL_DB_OK)
+       {
+               ERR("_cal_db_util_query_exec() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_normal_get_all_records(int offset, int limit, calendar_list_h* out_list)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char offsetquery[CAL_DB_SQL_MAX_LEN] = {0};
+       char limitquery[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = calendar_list_create(out_list);
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       if (offset > 0)
+       {
+               snprintf(offsetquery, sizeof(offsetquery), "OFFSET %d", offset);
+       }
+       if (limit > 0)
+       {
+               snprintf(limitquery, sizeof(limitquery), "LIMIT %d", limit);
+       }
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT * FROM");
+       _cal_db_append_string(&query_str, CAL_VIEW_TABLE_NORMAL_INSTANCE);
+       _cal_db_append_string(&query_str, limitquery);
+       _cal_db_append_string(&query_str, offsetquery);
+
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_list_destroy(*out_list, true);
+               *out_list = NULL;
+               CAL_FREE(query_str);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_instance_utime_calendar_book._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+               __cal_db_instance_normal_get_stmt(stmt, record);
+
+               ret = calendar_list_add(*out_list, record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_normal_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *projection = NULL;
+       GSList *bind_text = NULL, *cursor = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int i = 0;
+       char *table_name;
+
+       que = (cal_query_s *)query;
+
+       if (0 == strcmp(que->view_uri, CALENDAR_VIEW_INSTANCE_UTIME_CALENDAR))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_NORMAL_INSTANCE);
+       }
+       else if (0 == strcmp(que->view_uri, CALENDAR_VIEW_INSTANCE_UTIME_CALENDAR_EXTENDED))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_NORMAL_INSTANCE_EXTENDED);
+       }
+       else
+       {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+               //table_name = SAFE_STRDUP(CAL_TABLE_NORMAL_INSTANCE);
+       }
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // make projection
+       ret = _cal_db_query_create_projection(query, &projection);
+
+       char *query_str = NULL;
+       // query - projection
+       if (projection)
+       {
+               _cal_db_append_string(&query_str, "SELECT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, "FROM");
+               _cal_db_append_string(&query_str, table_name);
+               CAL_FREE(projection);
+       }
+       else
+       {
+               _cal_db_append_string(&query_str, "SELECT * FROM");
+               _cal_db_append_string(&query_str, table_name);
+       }
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+       }
+
+       // ORDER
+       char *order = NULL;
+       ret = _cal_db_query_create_order(query, condition, &order);
+       if (order)
+       {
+               _cal_db_append_string(&query_str, order);
+               CAL_FREE(order);
+       }
+       CAL_FREE(condition);
+
+       // limit, offset
+       char buf[32] = {0};
+       if (limit > 0)
+       {
+               snprintf(buf, sizeof(buf), "LIMIT %d", limit);
+               _cal_db_append_string(&query_str, buf);
+
+               if (offset > 0)
+               {
+                       snprintf(buf, sizeof(buf), "OFFSET %d", offset);
+                       _cal_db_append_string(&query_str, buf);
+               }
+       }
+
+       // query
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       CAL_DBG("%s",query_str);
+
+       // bind text
+       if (bind_text)
+       {
+               g_slist_length(bind_text);
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+               {
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+               }
+       }
+
+       //
+       ret = calendar_list_create(out_list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               ERR("calendar_list_create() Failed");
+               sqlite3_finalize(stmt);
+               CAL_FREE(query_str);
+               return ret;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(que->view_uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+               if (que->projection_count > 0)
+               {
+                       _cal_record_set_projection(record,
+                                       que->projection, que->projection_count, que->property_count);
+
+                       __cal_db_instance_normal_get_projection_stmt(stmt,
+                                       que->projection, que->projection_count,
+                                       record);
+               }
+               else
+               {
+                       __cal_db_instance_normal_get_stmt(stmt,record);
+               }
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_normal_get_count(int *out_count)
+{
+       retvm_if(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, CAL_TABLE_NORMAL_INSTANCE);
+
+       int ret = 0;
+       int count = 0;
+       ret = _cal_db_util_query_get_first_int_result(query_str, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+       CAL_FREE(query_str);
+
+       *out_count = count;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_normal_get_count_with_query(calendar_query_h query, int *out_count)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *table_name;
+       int count = 0;
+       GSList *bind_text = NULL;
+
+       que = (cal_query_s *)query;
+
+       if (0 == strcmp(que->view_uri, CALENDAR_VIEW_INSTANCE_UTIME_CALENDAR))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_NORMAL_INSTANCE);
+       }
+       else if (0 == strcmp(que->view_uri, CALENDAR_VIEW_INSTANCE_UTIME_CALENDAR_EXTENDED))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_NORMAL_INSTANCE_EXTENDED);
+       }
+       else
+       {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+               //table_name = SAFE_STRDUP(CAL_TABLE_NORMAL_INSTANCE);
+       }
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       char *query_str = NULL;
+       // query - select from
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, table_name);
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str,  "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+               CAL_FREE(condition);
+       }
+
+       // query
+       ret = _cal_db_util_query_get_first_int_result(query_str, bind_text, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+
+       if (out_count) *out_count = count;
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_db_instance_normal_get_stmt(sqlite3_stmt *stmt, calendar_record_h record)
+{
+       cal_instance_normal_s* instance =  (cal_instance_normal_s*)(record);
+       const unsigned char *temp;
+       int count = 0;
+
+       instance->event_id = sqlite3_column_int(stmt, count++);
+       instance->start.type = sqlite3_column_int(stmt, count++);
+       instance->start.time.utime = sqlite3_column_int64(stmt, count++);
+       sqlite3_column_text(stmt, count++);  //datetime
+       instance->end.type = sqlite3_column_int(stmt, count++);
+       instance->end.time.utime = sqlite3_column_int64(stmt, count++);
+       sqlite3_column_text(stmt, count++);  //datetime
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->summary = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->description = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->location = SAFE_STRDUP(temp);
+
+       instance->busy_status = sqlite3_column_int(stmt, count++);
+
+       instance->event_status = sqlite3_column_int(stmt, count++);
+
+       instance->priority = sqlite3_column_int(stmt, count++);
+
+       instance->sensitivity = sqlite3_column_int(stmt, count++);
+
+       instance->has_rrule = sqlite3_column_int(stmt, count++);
+       if (instance->has_rrule > 0)
+       {
+               instance->has_rrule = 1;
+       }
+
+       instance->latitude = sqlite3_column_double(stmt,count++);
+       instance->longitude = sqlite3_column_double(stmt,count++);
+       instance->has_alarm = sqlite3_column_int(stmt,count++);
+       instance->original_event_id = sqlite3_column_int(stmt, count++);
+       instance->calendar_id = sqlite3_column_int(stmt, count++);
+       instance->last_mod = sqlite3_column_int64(stmt, count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->sync_data1 = SAFE_STRDUP(temp);
+
+       return;
+}
+
+static void __cal_db_instance_normal_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record)
+{
+       cal_instance_normal_s* instance =  (cal_instance_normal_s*)(record);
+       const unsigned char *temp;
+
+       switch(property)
+       {
+       case CAL_PROPERTY_INSTANCE_NORMAL_START:
+               sqlite3_column_int(stmt,*stmt_count);
+               *stmt_count = *stmt_count+1;
+               instance->start.type = CALENDAR_TIME_UTIME;//sqlite3_column_int(stmt, *stmt_count);
+               instance->start.time.utime = sqlite3_column_int64(stmt, *stmt_count);
+               *stmt_count = *stmt_count+1;
+               sqlite3_column_text(stmt, *stmt_count);  // dtstart_datetime
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_END:
+               sqlite3_column_int(stmt,*stmt_count);
+               *stmt_count = *stmt_count+1;
+               instance->end.type = CALENDAR_TIME_UTIME;//sqlite3_column_int(stmt, *stmt_count);
+               instance->end.time.utime = sqlite3_column_int64(stmt, *stmt_count);
+               *stmt_count = *stmt_count+1;
+               sqlite3_column_text(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_SUMMARY:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->summary = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_LOCATION:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->location = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_CALENDAR_ID:
+               instance->calendar_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_DESCRIPTION:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->description = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_BUSY_STATUS:
+               instance->busy_status = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EVENT_STATUS:
+               instance->event_status = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_PRIORITY:
+               instance->priority = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_SENSITIVITY:
+               instance->sensitivity = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_HAS_RRULE:
+               instance->has_rrule = sqlite3_column_int(stmt, *stmt_count);
+               if (instance->has_rrule > 0)
+               {
+                       instance->has_rrule = 1;
+               }
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_LATITUDE:
+               instance->latitude = sqlite3_column_double(stmt,*stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_LONGITUDE:
+               instance->longitude = sqlite3_column_double(stmt,*stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EVENT_ID:
+               instance->event_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_HAS_ALARM:
+               instance->has_alarm = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_ORIGINAL_EVENT_ID:
+               instance->original_event_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_LAST_MODIFIED_TIME:
+               instance->last_mod = sqlite3_column_int64(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_SYNC_DATA1:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->sync_data1 = SAFE_STRDUP(temp);
+               break;
+       default:
+               sqlite3_column_int(stmt, *stmt_count);
+               break;
+       }
+
+       *stmt_count = *stmt_count+1;
+
+       return;
+}
+
+static void __cal_db_instance_normal_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record)
+{
+       int i=0;
+       int stmt_count = 0;
+
+       for(i=0;i<projection_count;i++)
+       {
+               __cal_db_instance_normal_get_property_stmt(stmt,projection[i],&stmt_count,record);
+       }
+}
diff --git a/native/cal_db_plugin_instance_normal_extended.c b/native/cal_db_plugin_instance_normal_extended.c
new file mode 100755 (executable)
index 0000000..4c6cdaf
--- /dev/null
@@ -0,0 +1,593 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_db_query.h"
+#include "cal_access_control.h"
+
+static int __cal_db_instance_normal_extended_get_all_records(int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_instance_normal_extended_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_instance_normal_extended_get_count(int *out_count);
+static int __cal_db_instance_normal_extended_get_count_with_query(calendar_query_h query, int *out_count);
+/*
+ * static function
+ */
+static void __cal_db_instance_normal_extended_get_stmt(sqlite3_stmt *stmt,calendar_record_h record);
+static void __cal_db_instance_normal_extended_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record);
+static void __cal_db_instance_normal_extended_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record);
+
+cal_db_plugin_cb_s _cal_db_instance_normal_extended_plugin_cb = {
+       .is_query_only = false,
+       .insert_record=NULL,
+       .get_record=NULL,
+       .update_record=NULL,
+       .delete_record=NULL,
+       .get_all_records=__cal_db_instance_normal_extended_get_all_records,
+       .get_records_with_query=__cal_db_instance_normal_extended_get_records_with_query,
+       .insert_records=NULL,
+       .update_records=NULL,
+       .delete_records=NULL,
+       .get_count=__cal_db_instance_normal_extended_get_count,
+       .get_count_with_query=__cal_db_instance_normal_extended_get_count_with_query,
+       .replace_record=NULL,
+       .replace_records=NULL
+};
+
+static int __cal_db_instance_normal_extended_get_all_records(int offset, int limit, calendar_list_h* out_list)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char offsetquery[CAL_DB_SQL_MAX_LEN] = {0};
+       char limitquery[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = calendar_list_create(out_list);
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       if (offset > 0)
+       {
+               snprintf(offsetquery, sizeof(offsetquery), "OFFSET %d", offset);
+       }
+       if (limit > 0)
+       {
+               snprintf(limitquery, sizeof(limitquery), "LIMIT %d", limit);
+       }
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT * FROM");
+       _cal_db_append_string(&query_str, CAL_VIEW_TABLE_NORMAL_INSTANCE_EXTENDED);
+       _cal_db_append_string(&query_str, limitquery);
+       _cal_db_append_string(&query_str, offsetquery);
+
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_list_destroy(*out_list, true);
+               *out_list = NULL;
+               CAL_FREE(query_str);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_instance_utime_calendar_book_extended._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+               __cal_db_instance_normal_extended_get_stmt(stmt,record);
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_normal_extended_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *projection = NULL;
+       GSList *bind_text = NULL, *cursor = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int i = 0;
+       char *table_name;
+
+       que = (cal_query_s *)query;
+
+       table_name = SAFE_STRDUP(CAL_VIEW_TABLE_NORMAL_INSTANCE_EXTENDED);
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // make projection
+       ret = _cal_db_query_create_projection(query, &projection);
+
+       char *query_str = NULL;
+       // query - projection
+       if (projection)
+       {
+               _cal_db_append_string(&query_str, "SELECT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, "FROM");
+               _cal_db_append_string(&query_str, table_name);
+               CAL_FREE(projection);
+       }
+       else
+       {
+               _cal_db_append_string(&query_str, "SELECT * FROM");
+               _cal_db_append_string(&query_str, table_name);
+       }
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+       }
+
+       // ORDER
+       char *order = NULL;
+       ret = _cal_db_query_create_order(query, condition, &order);
+       if (order)
+       {
+               _cal_db_append_string(&query_str, order);
+               CAL_FREE(order);
+       }
+       CAL_FREE(condition);
+
+       // limit, offset
+       char buf[32] = {0};
+       if (limit > 0)
+       {
+               snprintf(buf, sizeof(buf), "LIMIT %d", limit);
+               _cal_db_append_string(&query_str, buf);
+
+               if (offset > 0)
+               {
+                       snprintf(buf, sizeof(buf), "OFFSET %d", offset);
+                       _cal_db_append_string(&query_str, buf);
+               }
+       }
+
+       // query
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               CAL_DBG("%s",query_str);
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       // bind text
+       if (bind_text)
+       {
+               g_slist_length(bind_text);
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+               {
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+               }
+       }
+
+       //
+       ret = calendar_list_create(out_list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               ERR("calendar_list_create() Failed");
+               sqlite3_finalize(stmt);
+               CAL_FREE(query_str);
+               return ret;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(que->view_uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+
+               if (que->projection_count > 0)
+               {
+                       _cal_record_set_projection(record,
+                                       que->projection, que->projection_count, que->property_count);
+
+                       __cal_db_instance_normal_extended_get_projection_stmt(stmt,
+                                       que->projection, que->projection_count, record);
+               }
+               else
+               {
+                       __cal_db_instance_normal_extended_get_stmt(stmt,record);
+               }
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_normal_extended_get_count(int *out_count)
+{
+       retvm_if(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, CAL_VIEW_TABLE_NORMAL_INSTANCE_EXTENDED);
+
+       int ret = 0;
+       int count = 0;
+       ret = _cal_db_util_query_get_first_int_result(query_str, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+       CAL_FREE(query_str);
+
+       *out_count = count;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_instance_normal_extended_get_count_with_query(calendar_query_h query, int *out_count)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *table_name;
+       int count = 0;
+       GSList *bind_text = NULL;
+
+       que = (cal_query_s *)query;
+       table_name = SAFE_STRDUP(CAL_VIEW_TABLE_NORMAL_INSTANCE_EXTENDED);
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       char *query_str = NULL;
+       // query - select from
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, table_name);
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+               CAL_FREE(condition);
+       }
+
+       // query
+       ret = _cal_db_util_query_get_first_int_result(query_str, bind_text, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+
+       if (out_count) *out_count = count;
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_db_instance_normal_extended_get_stmt(sqlite3_stmt *stmt,calendar_record_h record)
+{
+       cal_instance_normal_extended_s* instance =  (cal_instance_normal_extended_s*)(record);
+       const unsigned char *temp;
+       int count = 0;
+
+       instance->event_id = sqlite3_column_int(stmt, count++);
+       instance->start.type = sqlite3_column_int(stmt, count++);
+       instance->start.time.utime = sqlite3_column_int64(stmt, count++);
+       sqlite3_column_text(stmt, count++);  //datetime
+       instance->end.type = sqlite3_column_int(stmt, count++);
+       instance->end.time.utime = sqlite3_column_int64(stmt, count++);
+       sqlite3_column_text(stmt, count++);  //datetime
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->summary = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->description = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->location = SAFE_STRDUP(temp);
+
+       instance->busy_status = sqlite3_column_int(stmt, count++);
+
+       instance->event_status = sqlite3_column_int(stmt, count++);
+
+       instance->priority = sqlite3_column_int(stmt, count++);
+
+       instance->sensitivity = sqlite3_column_int(stmt, count++);
+
+       instance->has_rrule = sqlite3_column_int(stmt, count++);
+       if (instance->has_rrule > 0)
+       {
+               instance->has_rrule = 1;
+       }
+
+       instance->latitude = sqlite3_column_double(stmt,count++);
+       instance->longitude = sqlite3_column_double(stmt,count++);
+       instance->has_alarm = sqlite3_column_int(stmt,count++);
+       instance->original_event_id = sqlite3_column_int(stmt, count++);
+       instance->calendar_id = sqlite3_column_int(stmt, count++);
+       instance->last_mod = sqlite3_column_int64(stmt, count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->sync_data1 = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->organizer_name = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->categories= SAFE_STRDUP(temp);
+
+       instance->has_attendee= sqlite3_column_int(stmt, count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->sync_data2 = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->sync_data3 = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       instance->sync_data4 = SAFE_STRDUP(temp);
+
+       return;
+}
+
+static void __cal_db_instance_normal_extended_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record)
+{
+       cal_instance_normal_extended_s* instance =  (cal_instance_normal_extended_s*)(record);
+       const unsigned char *temp;
+
+       switch(property)
+       {
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_START:
+               sqlite3_column_int(stmt,*stmt_count);
+               *stmt_count = *stmt_count+1;
+               instance->start.type = CALENDAR_TIME_UTIME;//sqlite3_column_int(stmt, *stmt_count);
+               instance->start.time.utime = sqlite3_column_int64(stmt, *stmt_count);
+               *stmt_count = *stmt_count+1;
+               sqlite3_column_text(stmt, *stmt_count);  // dtstart_datetime
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_END:
+               sqlite3_column_int(stmt,*stmt_count);
+               *stmt_count = *stmt_count+1;
+               instance->end.type = CALENDAR_TIME_UTIME;//sqlite3_column_int(stmt, *stmt_count);
+               instance->end.time.utime = sqlite3_column_int64(stmt, *stmt_count);
+               *stmt_count = *stmt_count+1;
+               sqlite3_column_text(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SUMMARY:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->summary = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LOCATION:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->location = SAFE_STRDUP(temp);
+               break;
+       case  CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_CALENDAR_ID:
+               instance->calendar_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_DESCRIPTION:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->description = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_BUSY_STATUS:
+               instance->busy_status = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_EVENT_STATUS:
+               instance->event_status = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_PRIORITY:
+               instance->priority = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SENSITIVITY:
+               instance->sensitivity = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_RRULE:
+               instance->has_rrule = sqlite3_column_int(stmt, *stmt_count);
+               if (instance->has_rrule > 0)
+               {
+                       instance->has_rrule = 1;
+               }
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LATITUDE:
+               instance->latitude = sqlite3_column_double(stmt,*stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LONGITUDE:
+               instance->longitude = sqlite3_column_double(stmt,*stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_EVENT_ID:
+               instance->event_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_ALARM:
+               instance->has_alarm = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_ORIGINAL_EVENT_ID:
+               instance->original_event_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_LAST_MODIFIED_TIME:
+               instance->last_mod = sqlite3_column_int64(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA1:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->sync_data1 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_ORGANIZER_NAME:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->organizer_name= SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_CATEGORIES:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->categories= SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_HAS_ATTENDEE:
+               instance->has_attendee= sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA2:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->sync_data2= SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA3:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->sync_data3 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_INSTANCE_NORMAL_EXTENDED_SYNC_DATA4:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               instance->sync_data4= SAFE_STRDUP(temp);
+               break;
+       default:
+               sqlite3_column_int(stmt, *stmt_count);
+               break;
+       }
+
+       *stmt_count = *stmt_count+1;
+
+       return;
+}
+
+static void __cal_db_instance_normal_extended_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record)
+{
+       int i=0;
+       int stmt_count = 0;
+
+       for(i=0;i<projection_count;i++)
+       {
+               __cal_db_instance_normal_extended_get_property_stmt(stmt,projection[i],&stmt_count,record);
+       }
+}
diff --git a/native/cal_db_plugin_search.c b/native/cal_db_plugin_search.c
new file mode 100644 (file)
index 0000000..3296209
--- /dev/null
@@ -0,0 +1,519 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+
+#include "cal_db.h"
+#include "cal_db_util.h"
+#include "cal_db_query.h"
+#include "cal_access_control.h"
+
+/*
+ * db plugin function
+ */
+static int __cal_db_search_get_records_with_query( calendar_query_h query, int offset, int limit, calendar_list_h* out_list );
+static int __cal_db_search_get_count_with_query(calendar_query_h query, int *out_count);
+
+/*
+ * static function
+ */
+static void __cal_db_search_get_stmt(sqlite3_stmt *stmt,calendar_query_h query,
+               calendar_record_h record);
+static void __cal_db_search_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record);
+static void __cal_db_search_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record);
+static int __cal_db_search_make_projection(calendar_query_h query, char **projection);
+
+
+cal_db_plugin_cb_s _cal_db_search_plugin_cb = {
+       .is_query_only=true,
+       .insert_record=NULL,
+       .get_record=NULL,
+       .update_record=NULL,
+       .delete_record=NULL,
+       .get_all_records=NULL,
+       .get_records_with_query=__cal_db_search_get_records_with_query,
+       .insert_records=NULL,
+       .update_records=NULL,
+       .delete_records=NULL,
+       .get_count=NULL,
+       .get_count_with_query=__cal_db_search_get_count_with_query,
+       .replace_record=NULL,
+       .replace_records=NULL
+};
+
+static int __cal_db_search_get_records_with_query( calendar_query_h query, int offset, int limit, calendar_list_h* out_list )
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *projection = NULL;
+       GSList *bind_text = NULL, *cursor = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int i = 0;
+       char *table_name = NULL;
+
+       que = (cal_query_s *)query;
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query,
+                               &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // make projection
+       if (que->projection_count > 0)
+       {
+               _cal_db_query_create_projection(query, &projection);
+       }
+       else
+       {
+               __cal_db_search_make_projection(query, &projection);
+       }
+
+       char *query_str = NULL;
+       if (que->distinct == true)
+       {
+               _cal_db_append_string(&query_str, "SELECT DISTINCT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, "FROM");
+               _cal_db_append_string(&query_str, table_name);
+       }
+       else
+       {
+               _cal_db_append_string(&query_str, "SELECT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, "FROM");
+               _cal_db_append_string(&query_str, table_name);
+       }
+       CAL_FREE(projection);
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+       }
+
+       // ORDER
+       char *order = NULL;
+       ret = _cal_db_query_create_order(query, condition, &order);
+       if (order)
+       {
+               _cal_db_append_string(&query_str, order);
+               CAL_FREE(order);
+       }
+       CAL_FREE(condition);
+
+       // limit, offset
+       char buf[32] = {0};
+       if (limit > 0)
+       {
+               snprintf(buf, sizeof(buf), "LIMIT %d", limit);
+               _cal_db_append_string(&query_str, buf);
+
+               if (offset > 0)
+               {
+                       snprintf(buf, sizeof(buf), "OFFSET %d", offset);
+                       _cal_db_append_string(&query_str, buf);
+               }
+       }
+
+       // query
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       CAL_DBG("%s",query_str);
+
+       // bind text
+       if (bind_text)
+       {
+               g_slist_length(bind_text);
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+               {
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+               }
+       }
+
+       //
+       ret = calendar_list_create(out_list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               ERR("calendar_list_create() Failed");
+               sqlite3_finalize(stmt);
+               CAL_FREE(query_str);
+               return ret;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(que->view_uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+               if (que->projection_count > 0)
+               {
+                       __cal_db_search_get_projection_stmt(stmt,que->projection,que->projection_count,
+                                       record);
+               }
+               else
+               {
+                       __cal_db_search_get_stmt(stmt, query,record);
+               }
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_search_get_count_with_query(calendar_query_h query, int *out_count)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *projection = NULL;
+       char *table_name;
+       int count = 0;
+       GSList *bind_text = NULL;
+
+       que = (cal_query_s *)query;
+
+       if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_EVENT_CALENDAR))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_EVENT_CALENDAR);
+               projection = SAFE_STRDUP("id");
+       }
+       else if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_TODO_CALENDAR))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_TODO_CALENDAR);
+               projection = SAFE_STRDUP("id");
+       }
+       else if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_EVENT_CALENDAR_ATTENDEE))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_EVENT_CALENDAR_ATTENDEE);
+               projection = SAFE_STRDUP("id");
+       }
+       else if (0 == strcmp(que->view_uri, CALENDAR_VIEW_INSTANCE_UTIME_CALENDAR))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_NORMAL_INSTANCE);
+               projection = SAFE_STRDUP("event_id");
+       }
+       else if (0 == strcmp(que->view_uri, CALENDAR_VIEW_INSTANCE_LOCALTIME_CALENDAR))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_ALLDAY_INSTANCE);
+               projection = SAFE_STRDUP("event_id");
+       }
+       else
+       {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       CAL_FREE(projection);
+                       return ret;
+               }
+       }
+
+       char *query_str = NULL;
+
+       // query - select from
+       if (que->distinct == true)
+       {
+               _cal_db_append_string(&query_str, "SELECT count(DISTINCT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, ") FROM");
+               _cal_db_append_string(&query_str, table_name);
+       }
+       else
+       {
+               _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+               _cal_db_append_string(&query_str, table_name);
+       }
+       CAL_FREE(projection);
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+               CAL_FREE(condition);
+       }
+
+       // query
+       ret = _cal_db_util_query_get_first_int_result(query_str, bind_text, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+
+       if (out_count) *out_count = count;
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_db_search_get_stmt(sqlite3_stmt *stmt,calendar_query_h query,
+               calendar_record_h record)
+{
+       int i=0;
+       int stmt_count = 0;
+       cal_query_s *query_s = NULL;
+       cal_property_info_s *properties = NULL;
+
+       query_s = (cal_query_s *)query;
+
+       for (i=0;i<query_s->property_count;i++)
+       {
+               properties = &(query_s->properties[i]);
+
+               if ( CAL_PROPERTY_CHECK_FLAGS(properties->property_id, CAL_PROPERTY_FLAGS_FILTER) == true)
+               {
+                       break;
+               }
+
+               __cal_db_search_get_property_stmt(stmt, properties->property_id, &stmt_count,record);
+       }
+       return ;
+}
+
+static void __cal_db_search_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record)
+{
+       int ret = 0;
+       const unsigned char *temp;
+       char *dtstart_datetime;
+       char buf[8] = {0};
+       int int_tmp = 0;
+       double d_tmp = 0;
+       long long int lli_tmp = 0;
+
+       if (CAL_PROPERTY_CHECK_DATA_TYPE(property,CAL_PROPERTY_DATA_TYPE_INT) == true)
+       {
+               int_tmp = sqlite3_column_int(stmt, *stmt_count);
+               _cal_record_set_int(record,property,int_tmp);
+       }
+       else if (CAL_PROPERTY_CHECK_DATA_TYPE(property,CAL_PROPERTY_DATA_TYPE_STR) == true)
+       {
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               _cal_record_set_str(record,property,(const char*)temp);
+       }
+       else if (CAL_PROPERTY_CHECK_DATA_TYPE(property,CAL_PROPERTY_DATA_TYPE_DOUBLE) == true)
+       {
+               d_tmp = sqlite3_column_double(stmt,*stmt_count);
+               _cal_record_set_double(record,property,d_tmp);
+       }
+       else if (CAL_PROPERTY_CHECK_DATA_TYPE(property,CAL_PROPERTY_DATA_TYPE_LLI) == true)
+       {
+               lli_tmp = sqlite3_column_int64(stmt, *stmt_count);
+               _cal_record_set_lli(record,property,lli_tmp);
+       }
+       else if (CAL_PROPERTY_CHECK_DATA_TYPE(property,CAL_PROPERTY_DATA_TYPE_CALTIME) == true)
+       {
+               calendar_time_s caltime_tmp;
+               caltime_tmp.type = sqlite3_column_int(stmt,*stmt_count);
+               if (caltime_tmp.type == CALENDAR_TIME_UTIME)
+               {
+                       *stmt_count = *stmt_count+1;
+                       caltime_tmp.time.utime = sqlite3_column_int64(stmt,*stmt_count);
+                       *stmt_count = *stmt_count+1;
+                       sqlite3_column_text(stmt, *stmt_count);
+               }
+               else
+               {
+                       *stmt_count = *stmt_count+1;
+                       sqlite3_column_int64(stmt,*stmt_count); //event->start.time.utime = sqlite3_column_int64(stmt,count++);
+                       *stmt_count = *stmt_count+1;
+                       temp = sqlite3_column_text(stmt, *stmt_count);
+                       if (temp) {
+                               dtstart_datetime = SAFE_STRDUP(temp);
+                               snprintf(buf, strlen("YYYY") + 1, "%s", dtstart_datetime);
+                               caltime_tmp.time.date.year =  atoi(buf);
+                               snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 5);
+                               caltime_tmp.time.date.month = atoi(buf);
+                               snprintf(buf, strlen("DD") + 1, "%s", dtstart_datetime + 8);
+                               caltime_tmp.time.date.mday = atoi(buf);
+                               snprintf(buf, strlen("HH") + 1, "%s", dtstart_datetime + 11);
+                               caltime_tmp.time.date.hour = atoi(buf);
+                               snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 14);
+                               caltime_tmp.time.date.minute = atoi(buf);
+                               snprintf(buf, strlen("SS") + 1, "%s", dtstart_datetime + 17);
+                               caltime_tmp.time.date.second = atoi(buf);
+                               if (dtstart_datetime) free(dtstart_datetime);
+                       }
+               }
+               ret = _cal_record_set_caltime(record,property,caltime_tmp);
+               warn_if (CALENDAR_ERROR_NONE != ret, "Failed to _cal_record_set_caltime()");
+       }
+       else
+       {
+               sqlite3_column_int(stmt, *stmt_count);
+       }
+
+       *stmt_count = *stmt_count+1;
+}
+static void __cal_db_search_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record)
+{
+       int i=0;
+       int stmt_count = 0;
+
+       for(i=0;i<projection_count;i++)
+       {
+               __cal_db_search_get_property_stmt(stmt,projection[i],&stmt_count,record);
+       }
+}
+
+static int __cal_db_search_make_projection(calendar_query_h query, char **projection)
+{
+       int i = 0;
+       int len = 0;
+       const char *field_name;
+       char out_projection[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_query_s *query_s = NULL;
+       cal_property_info_s *properties = NULL;
+
+       retv_if(NULL == query, CALENDAR_ERROR_INVALID_PARAMETER);
+       query_s = (cal_query_s *)query;
+
+       properties = &(query_s->properties[0]);
+       field_name = properties->fields;
+       if (field_name)
+               len += snprintf(out_projection+len, sizeof(out_projection)-len, "%s", field_name);
+
+       if (len >= sizeof(out_projection))
+       {
+               ERR("buf len max");
+               return CALENDAR_ERROR_SYSTEM;
+       }
+
+       for (i=1;i<query_s->property_count;i++)
+       {
+               properties = &(query_s->properties[i]);
+               field_name = properties->fields;
+
+               if ( CAL_PROPERTY_CHECK_FLAGS(properties->property_id, CAL_PROPERTY_FLAGS_FILTER) == true)
+               {
+                       break;
+               }
+
+               if (field_name)
+               {
+                       len += snprintf(out_projection+len, sizeof(out_projection)-len, ", %s", field_name);
+                       if (len >= sizeof(out_projection))
+                       {
+                               ERR("buf len max");
+                               return CALENDAR_ERROR_SYSTEM;
+                       }
+               }
+       }
+
+       *projection = strdup(out_projection);
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/native/cal_db_plugin_timezone.c b/native/cal_db_plugin_timezone.c
new file mode 100644 (file)
index 0000000..fc51271
--- /dev/null
@@ -0,0 +1,1088 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "calendar_db.h"  //calendar_db_get_record
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_db_query.h"
+
+static int __cal_db_timezone_insert_record( calendar_record_h record, int* id );
+static int __cal_db_timezone_get_record( int id, calendar_record_h* out_record );
+static int __cal_db_timezone_update_record( calendar_record_h record );
+static int __cal_db_timezone_delete_record( int id );
+static int __cal_db_timezone_get_all_records( int offset, int limit, calendar_list_h* out_list );
+static int __cal_db_timezone_get_records_with_query( calendar_query_h query, int offset, int limit, calendar_list_h* out_list );
+static int __cal_db_timezone_insert_records(const calendar_list_h list, int** ids);
+static int __cal_db_timezone_update_records(const calendar_list_h list);
+static int __cal_db_timezone_delete_records(int ids[], int count);
+static int __cal_db_timezone_get_count(int *out_count);
+static int __cal_db_timezone_get_count_with_query(calendar_query_h query, int *out_count);
+static int __cal_db_timezone_replace_record(calendar_record_h record, int id);
+static int __cal_db_timezone_replace_records(const calendar_list_h list, int ids[], int count);
+
+/*
+ * static function
+ */
+static void __cal_db_timezone_get_stmt(sqlite3_stmt *stmt,calendar_record_h record);
+static void __cal_db_timezone_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int stmt_count, calendar_record_h record);
+static void __cal_db_timezone_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record);
+static void __cal_db_timezone_get_stmt(sqlite3_stmt *stmt,calendar_record_h record);
+static int __cal_db_timezone_update_projection(calendar_record_h record);
+
+cal_db_plugin_cb_s _cal_db_timezone_plugin_cb = {
+       .is_query_only=false,
+       .insert_record=__cal_db_timezone_insert_record,
+       .get_record=__cal_db_timezone_get_record,
+       .update_record=__cal_db_timezone_update_record,
+       .delete_record=__cal_db_timezone_delete_record,
+       .get_all_records=__cal_db_timezone_get_all_records,
+       .get_records_with_query=__cal_db_timezone_get_records_with_query,
+       .insert_records=__cal_db_timezone_insert_records,
+       .update_records=__cal_db_timezone_update_records,
+       .delete_records=__cal_db_timezone_delete_records,
+       .get_count=__cal_db_timezone_get_count,
+       .get_count_with_query=__cal_db_timezone_get_count_with_query,
+       .replace_record = __cal_db_timezone_replace_record,
+       .replace_records = __cal_db_timezone_replace_records
+};
+
+static int __cal_db_timezone_insert_record( calendar_record_h record, int* id )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       int index;
+       int calendar_book_id = 0;
+       char query[CAL_DB_SQL_MAX_LEN];
+       sqlite3_stmt *stmt;
+       cal_timezone_s* timezone =  (cal_timezone_s*)(record);
+       calendar_record_h record_calendar = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       retv_if(NULL == timezone, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       ret = calendar_record_get_int(record,
+                       _calendar_timezone.calendar_book_id, &calendar_book_id);
+       DBG("calendar_book_id(%d)", calendar_book_id);
+
+       ret = _cal_db_get_record(_calendar_book._uri,
+                       calendar_book_id, &record_calendar);
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_INVALID_PARAMETER, "calendar_book_id is invalid");
+       calendar_record_destroy(record_calendar, true);
+
+       // start >>>>> check if we already have
+       /*
+               if (timezone->standard_name == NULL || strlen(timezone->standard_name) == 0)
+               {
+               ERR("No timezone starndard name");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+        */
+       if (timezone->standard_name)
+       {
+               snprintf(query, sizeof(query), "SELECT count(*), id FROM %s "
+                               "WHERE standard_name = ? ",
+                               CAL_TABLE_TIMEZONE);
+
+               stmt = _cal_db_util_query_prepare(query);
+               if (NULL == stmt)
+               {
+                       ERR("_cal_db_util_query_prepare() failed");
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+               _cal_db_util_stmt_bind_text(stmt, 1, timezone->standard_name);
+
+               dbret = _cal_db_util_stmt_step(stmt);
+               if (CAL_DB_ROW != dbret)
+               {
+                       ERR("_cal_db_util_stmt_step() failed");
+                       sqlite3_finalize(stmt);
+                       switch (dbret)
+                       {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+
+               index = 0;
+               int count = sqlite3_column_int(stmt, index++);
+               int timezone_id = sqlite3_column_int(stmt, index++);
+               sqlite3_finalize(stmt);
+
+               if (count > 0)
+               {
+                       DBG("Already exist which tzid name[%s] id(%d)", timezone->standard_name, timezone_id);
+                       *id = timezone_id;
+                       return CALENDAR_ERROR_NONE;
+               }
+               // end <<<<< check if we already have
+
+               DBG("Not registered timezone in the table, so insert timezone.");
+       }
+
+       // if we don't have
+       snprintf(query, sizeof(query), "INSERT INTO %s(tz_offset_from_gmt ,standard_name, "
+                       "std_start_month ,std_start_position_of_week ,std_start_day, "
+                       "std_start_hour ,standard_bias ,day_light_name ,day_light_start_month, "
+                       "day_light_start_position_of_week ,day_light_start_day, "
+                       "day_light_start_hour ,day_light_bias, calendar_id) "
+                       "VALUES(%d,?,%d,%d,%d,%d,%d,?,%d,%d,%d,%d,%d,%d)",
+                       CAL_TABLE_TIMEZONE,
+                       timezone->tz_offset_from_gmt,
+                       timezone->std_start_month,
+                       timezone->std_start_position_of_week,
+                       timezone->std_start_day,
+                       timezone->std_start_hour,
+                       timezone->standard_bias,
+                       timezone->day_light_start_month,
+                       timezone->day_light_start_position_of_week,
+                       timezone->day_light_start_day,
+                       timezone->day_light_start_hour,
+                       timezone->day_light_bias,
+                       timezone->calendar_id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() Failed");
+
+       if (timezone->standard_name)
+               _cal_db_util_stmt_bind_text(stmt, 1, timezone->standard_name);
+
+       if (timezone->day_light_name)
+               _cal_db_util_stmt_bind_text(stmt, 2, timezone->day_light_name);
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret)
+       {
+               sqlite3_finalize(stmt);
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       index = _cal_db_util_last_insert_id();
+       sqlite3_finalize(stmt);
+
+       //_cal_record_set_int(record, _calendar_timezone.id,index);
+       if (id)
+       {
+               *id = index;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_timezone_get_record( int id, calendar_record_h* out_record )
+{
+       char query[CAL_DB_SQL_MAX_LEN];
+       sqlite3_stmt *stmt = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int ret = 0;
+
+       ret = calendar_record_create( _calendar_timezone._uri ,out_record);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("record create fail");
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       snprintf(query, sizeof(query), "SELECT * FROM %s WHERE id = %d AND "
+                       "calendar_id IN (select id from %s where deleted = 0)",
+                       CAL_TABLE_TIMEZONE, id,
+                       CAL_TABLE_CALENDAR);
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_record_destroy(*out_record, true);
+               *out_record = NULL;
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_ROW != dbret)
+       {
+               ERR("_cal_db_util_stmt_step() failed(%d)", dbret);
+               sqlite3_finalize(stmt);
+               calendar_record_destroy(*out_record, true);
+               *out_record = NULL;
+               switch (dbret)
+               {
+               case CAL_DB_DONE:
+                       return CALENDAR_ERROR_DB_RECORD_NOT_FOUND;
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       __cal_db_timezone_get_stmt(stmt,*out_record);
+
+       sqlite3_finalize(stmt);
+       stmt = NULL;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_timezone_update_record( calendar_record_h record )
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_timezone_s* timezone_info =  (cal_timezone_s*)(record);
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       retv_if(NULL == timezone_info, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       if (timezone_info->common.properties_flags != NULL)
+       {
+               return __cal_db_timezone_update_projection(record);
+       }
+
+       snprintf(query, sizeof(query), "UPDATE %s SET "
+                       "tz_offset_from_gmt=%d,"
+                       "standard_name=?,"
+                       "std_start_month=%d,"
+                       "std_start_position_of_week=%d,"
+                       "std_start_day=%d,"
+                       "std_start_hour=%d,"
+                       "standard_bias=%d,"
+                       "day_light_name=?,"
+                       "day_light_start_month=%d,"
+                       "day_light_start_position_of_week=%d,"
+                       "day_light_start_day=%d,"
+                       "day_light_start_hour=%d,"
+                       "day_light_bias=%d, "
+                       "calendar_id=%d "
+                       "WHERE id = %d",
+                       CAL_TABLE_TIMEZONE,
+                       timezone_info->tz_offset_from_gmt,
+                       timezone_info->std_start_month,
+                       timezone_info->std_start_position_of_week,
+                       timezone_info->std_start_day,
+                       timezone_info->std_start_hour,
+                       timezone_info->standard_bias,
+                       timezone_info->day_light_start_month,
+                       timezone_info->day_light_start_position_of_week,
+                       timezone_info->day_light_start_day,
+                       timezone_info->day_light_start_hour,
+                       timezone_info->day_light_bias,
+                       timezone_info->calendar_id,
+                       timezone_info->index);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "cal_q_cal_db_util_query_prepareuery_prepare() Failed");
+
+       if (timezone_info->standard_name)
+               _cal_db_util_stmt_bind_text(stmt, 1, timezone_info->standard_name);
+
+       if (timezone_info->day_light_name)
+               _cal_db_util_stmt_bind_text(stmt, 2, timezone_info->day_light_name);
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret)
+       {
+               sqlite3_finalize(stmt);
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       sqlite3_finalize(stmt);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_timezone_delete_record( int id )
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       snprintf(query, sizeof(query), "DELETE FROM %s WHERE id = %d",
+                       CAL_TABLE_TIMEZONE, id);
+       dbret = _cal_db_util_query_exec(query);
+       if(CAL_DB_OK != dbret)
+       {
+               ERR("_cal_db_util_query_exec() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_timezone_replace_record(calendar_record_h record, int id)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_timezone_s* timezone_info =  (cal_timezone_s*)(record);
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       retv_if(NULL == timezone_info, CALENDAR_ERROR_INVALID_PARAMETER);
+       timezone_info->index = id;
+
+       if (timezone_info->common.properties_flags != NULL)
+       {
+               return __cal_db_timezone_update_projection(record);
+       }
+
+       snprintf(query, sizeof(query), "UPDATE %s SET "
+                       "tz_offset_from_gmt=%d,"
+                       "standard_name=?,"
+                       "std_start_month=%d,"
+                       "std_start_position_of_week=%d,"
+                       "std_start_day=%d,"
+                       "std_start_hour=%d,"
+                       "standard_bias=%d,"
+                       "day_light_name=?,"
+                       "day_light_start_month=%d,"
+                       "day_light_start_position_of_week=%d,"
+                       "day_light_start_day=%d,"
+                       "day_light_start_hour=%d,"
+                       "day_light_bias=%d, "
+                       "calendar_id=%d "
+                       "WHERE id = %d",
+                       CAL_TABLE_TIMEZONE,
+                       timezone_info->tz_offset_from_gmt,
+                       timezone_info->std_start_month,
+                       timezone_info->std_start_position_of_week,
+                       timezone_info->std_start_day,
+                       timezone_info->std_start_hour,
+                       timezone_info->standard_bias,
+                       timezone_info->day_light_start_month,
+                       timezone_info->day_light_start_position_of_week,
+                       timezone_info->day_light_start_day,
+                       timezone_info->day_light_start_hour,
+                       timezone_info->day_light_bias,
+                       timezone_info->calendar_id,
+                       id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "cal_q_cal_db_util_query_prepareuery_prepare() Failed");
+
+       if (timezone_info->standard_name)
+               _cal_db_util_stmt_bind_text(stmt, 1, timezone_info->standard_name);
+
+       if (timezone_info->day_light_name)
+               _cal_db_util_stmt_bind_text(stmt, 2, timezone_info->day_light_name);
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       sqlite3_finalize(stmt);
+       if (CAL_DB_DONE != dbret)
+       {
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_timezone_get_all_records( int offset, int limit, calendar_list_h* out_list )
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char offsetquery[CAL_DB_SQL_MAX_LEN] = {0};
+       char limitquery[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = calendar_list_create(out_list);
+
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       if (offset > 0)
+       {
+               snprintf(offsetquery, sizeof(offsetquery), "OFFSET %d", offset);
+       }
+       if (limit > 0)
+       {
+               snprintf(limitquery, sizeof(limitquery), "LIMIT %d", limit);
+       }
+       snprintf(query, sizeof(query), "SELECT * FROM %s where "
+                       "calendar_id IN (select id from %s where deleted = 0) "
+                       "%s %s",
+                       CAL_TABLE_TIMEZONE,
+                       CAL_TABLE_CALENDAR,
+                       limitquery,
+                       offsetquery);
+
+       stmt = _cal_db_util_query_prepare(query);
+
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_list_destroy(*out_list, true);
+               *out_list = NULL;
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_timezone._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+               __cal_db_timezone_get_stmt(stmt,record);
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+       }
+
+       sqlite3_finalize(stmt);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_timezone_get_records_with_query( calendar_query_h query, int offset, int limit, calendar_list_h* out_list )
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *projection = NULL;
+       char *order = NULL;
+       GSList *bind_text = NULL, *cursor = NULL;
+       char *query_str = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int i = 0;
+
+       que = (cal_query_s *)query;
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // make projection
+       ret = _cal_db_query_create_projection(query, &projection);
+
+       // query - projection
+       if (projection)
+       {
+               _cal_db_append_string(&query_str, "SELECT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, "FROM");
+               _cal_db_append_string(&query_str, CAL_TABLE_TIMEZONE);
+               CAL_FREE(projection);
+       }
+       else
+       {
+               _cal_db_append_string(&query_str, "SELECT * FROM");
+               _cal_db_append_string(&query_str, CAL_TABLE_TIMEZONE);
+       }
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE");
+               _cal_db_append_string(&query_str, condition);
+               CAL_FREE(condition);
+               _cal_db_append_string(&query_str, "AND calendar_id IN (select id from");
+               _cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
+               _cal_db_append_string(&query_str, "where deleted = 0)");
+       }
+       else
+       {
+               _cal_db_append_string(&query_str, "WHERE calendar_id IN (select id from");
+               _cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
+               _cal_db_append_string(&query_str, "where deleted = 0)");
+       }
+
+       // ORDER
+       ret = _cal_db_query_create_order(query, condition, &order);
+       if (order)
+       {
+               _cal_db_append_string(&query_str, order);
+               CAL_FREE(order);
+       }
+
+       char buf[32] = {0};
+       if (0 < limit)
+       {
+               snprintf(buf, sizeof(buf), "LIMIT %d", limit);
+               _cal_db_append_string(&query_str, buf);
+               if (0 < offset)
+               {
+                       snprintf(buf, sizeof(buf), "OFFSET %d", offset);
+                       _cal_db_append_string(&query_str, buf);
+               }
+       }
+
+       // query
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       // bind text
+       if (bind_text)
+       {
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+               {
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+               }
+       }
+
+       //
+       ret = calendar_list_create(out_list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("calendar_list_create() Failed");
+               sqlite3_finalize(stmt);
+               return ret;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_timezone._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       CAL_FREE(query_str);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+               if (que->projection_count > 0)
+               {
+                       _cal_record_set_projection(record,
+                                       que->projection, que->projection_count, que->property_count);
+
+                       __cal_db_timezone_get_projection_stmt(stmt,
+                                       que->projection, que->projection_count,
+                                       record);
+               }
+               else
+               {
+                       __cal_db_timezone_get_stmt(stmt,record);
+               }
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       CAL_FREE(query_str);
+                       sqlite3_finalize(stmt);
+                       return ret;
+               }
+       }
+
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       CAL_FREE(query_str);
+       sqlite3_finalize(stmt);
+
+       return CALENDAR_ERROR_NONE;
+}
+static int __cal_db_timezone_insert_records(const calendar_list_h list, int** ids)
+{
+       calendar_record_h record;
+       int ret = 0;
+       int count = 0;
+       int i=0;
+       int *id = NULL;
+
+       ret = calendar_list_get_count(list, &count);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list get error");
+               return ret;
+       }
+
+       id = calloc(1, sizeof(int)*count);
+
+       retvm_if(NULL == id, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc fail");
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list first error");
+               CAL_FREE(id);
+               return ret;
+       }
+       do
+       {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE)
+               {
+                       if( __cal_db_timezone_insert_record(record, &id[i]) != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("db insert error");
+                               CAL_FREE(id);
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+               i++;
+       } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+
+       if(ids)
+       {
+               *ids = id;
+       }
+       else
+       {
+               CAL_FREE(id);
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_timezone_update_records(const calendar_list_h list)
+{
+       calendar_record_h record;
+       int ret = 0;
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list first error");
+               return ret;
+       }
+       do
+       {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE)
+               {
+                       if( __cal_db_timezone_update_record(record) != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("db insert error");
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+       } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_timezone_delete_records(int ids[], int count)
+{
+       int i = 0;
+
+       for(i = 0; i < count; i++)
+       {
+               if (__cal_db_timezone_delete_record(ids[i]) != CALENDAR_ERROR_NONE)
+               {
+                       ERR("delete failed");
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_timezone_replace_records(const calendar_list_h list, int ids[], int count)
+{
+       calendar_record_h record;
+       int i;
+       int ret = 0;
+
+       if (NULL == list)
+       {
+               ERR("Invalid argument: list is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list first error");
+               return ret;
+       }
+
+       for (i = 0; i < count; i++)
+       {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE)
+               {
+                       if( __cal_db_timezone_replace_record(record, ids[i]) != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("db insert error");
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+               if (CALENDAR_ERROR_NO_DATA != calendar_list_next(list))
+               {
+                       break;
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_timezone_get_count(int *out_count)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       int count = 0;
+       int ret;
+
+       retvm_if(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       snprintf(query, sizeof(query), "SELECT count(*) FROM %s where "
+                       "calendar_id IN (select id from %s where deleted = 0)",
+                       CAL_TABLE_TIMEZONE,
+                       CAL_TABLE_CALENDAR);
+
+       ret = _cal_db_util_query_get_first_int_result(query, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               return ret;
+       }
+       CAL_DBG("%s=%d",query,count);
+
+       *out_count = count;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_timezone_get_count_with_query(calendar_query_h query, int *out_count)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *query_str = NULL;
+       char *table_name;
+       int count = 0;
+       GSList *bind_text = NULL;
+
+       que = (cal_query_s *)query;
+
+       if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_TIMEZONE))
+       {
+               table_name = SAFE_STRDUP(CAL_TABLE_TIMEZONE);
+       }
+       else
+       {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // query - select from
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, table_name);
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, "AND calendar_id IN (select id from");
+               _cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
+               _cal_db_append_string(&query_str, "where deleted = 0)");
+               CAL_FREE(condition);
+       }
+       else
+       {
+               _cal_db_append_string(&query_str, "WHERE calendar_id IN (select id from");
+               _cal_db_append_string(&query_str, CAL_TABLE_CALENDAR);
+               _cal_db_append_string(&query_str, "where deleted = 0)");
+       }
+
+       // query
+       ret = _cal_db_util_query_get_first_int_result(query_str, bind_text, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("%s=%d",query_str,count);
+
+       *out_count = count;
+
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_db_timezone_get_stmt(sqlite3_stmt *stmt,calendar_record_h record)
+{
+       cal_timezone_s* timezone =  (cal_timezone_s*)(record);
+       int count = 0;
+       const unsigned char *temp;
+
+       timezone->index = sqlite3_column_int(stmt, count++);
+       timezone->tz_offset_from_gmt = sqlite3_column_int(stmt, count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       timezone->standard_name = SAFE_STRDUP(temp);
+
+       timezone->std_start_month = sqlite3_column_int(stmt, count++);
+       timezone->std_start_position_of_week = sqlite3_column_int(stmt, count++);
+       timezone->std_start_day = sqlite3_column_int(stmt, count++);
+       timezone->std_start_hour = sqlite3_column_int(stmt, count++);
+       timezone->standard_bias = sqlite3_column_int(stmt, count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       timezone->day_light_name = SAFE_STRDUP(temp);
+
+       timezone->day_light_start_month = sqlite3_column_int(stmt, count++);
+       timezone->day_light_start_position_of_week = sqlite3_column_int(stmt, count++);
+       timezone->day_light_start_day = sqlite3_column_int(stmt, count++);
+       timezone->day_light_start_hour = sqlite3_column_int(stmt, count++);
+       timezone->day_light_bias = sqlite3_column_int(stmt, count++);
+
+       timezone->calendar_id = sqlite3_column_int(stmt, count++);
+}
+
+static void __cal_db_timezone_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int stmt_count, calendar_record_h record)
+{
+       cal_timezone_s* timezone =  (cal_timezone_s*)(record);
+       const unsigned char *temp;
+
+       switch(property)
+       {
+       case CAL_PROPERTY_TIMEZONE_ID:
+               timezone->index = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_TIMEZONE_TZ_OFFSET_FROM_GMT:
+               timezone->tz_offset_from_gmt = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_TIMEZONE_STANDARD_NAME:
+               temp = sqlite3_column_text(stmt, stmt_count);
+               timezone->standard_name = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TIMEZONE_STD_START_MONTH:
+               timezone->std_start_month = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_TIMEZONE_STD_START_POSITION_OF_WEEK:
+               timezone->std_start_position_of_week = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_TIMEZONE_STD_START_DAY:
+               timezone->std_start_day = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_TIMEZONE_STD_START_HOUR:
+               timezone->std_start_hour = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_TIMEZONE_STANDARD_BIAS:
+               timezone->standard_bias = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
+               temp = sqlite3_column_text(stmt, stmt_count);
+               timezone->day_light_name = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_MONTH:
+               timezone->day_light_start_month = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_POSITION_OF_WEEK:
+               timezone->day_light_start_position_of_week = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_DAY:
+               timezone->day_light_start_day = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_HOUR:
+               timezone->day_light_start_hour = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_BIAS:
+               timezone->day_light_bias = sqlite3_column_int(stmt, stmt_count);
+               break;
+       case CAL_PROPERTY_TIMEZONE_CALENDAR_ID:
+               timezone->calendar_id = sqlite3_column_int(stmt, stmt_count);
+               break;
+       default:
+               sqlite3_column_int(stmt, stmt_count);
+               break;
+       }
+
+       return;
+}
+
+static void __cal_db_timezone_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record)
+{
+       int i=0;
+
+       for(i=0;i<projection_count;i++)
+       {
+               __cal_db_timezone_get_property_stmt(stmt,projection[i],i,record);
+       }
+}
+
+static int __cal_db_timezone_update_projection(calendar_record_h record)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_timezone_s* timezone =  (cal_timezone_s*)(record);
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int ret = CALENDAR_ERROR_NONE;
+       char* set = NULL;
+       GSList *bind_text = NULL;
+       GSList *cursor = NULL;
+
+       ret = _cal_db_query_create_projection_update_set(record,&set,&bind_text);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       snprintf(query, sizeof(query), "UPDATE %s SET %s "
+                       "WHERE id = %d",
+                       CAL_TABLE_TIMEZONE,set,
+                       timezone->index);
+
+       CAL_DBG("%s",query);
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt) {
+               ERR("_cal_db_util_query_prepare() Failed");
+               CAL_FREE(set);
+               if(bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       // bind
+       if (bind_text)
+       {
+               int i = 0;
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+               {
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+               }
+       }
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret)
+       {
+               sqlite3_finalize(stmt);
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+
+               CAL_FREE(set);
+               if(bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       sqlite3_finalize(stmt);
+
+       CAL_FREE(set);
+       if(bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/native/cal_db_plugin_todo.c b/native/cal_db_plugin_todo.c
new file mode 100644 (file)
index 0000000..c2ff238
--- /dev/null
@@ -0,0 +1,2158 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "calendar_db.h"
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+#include "cal_list.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_db_query.h"
+#include "cal_db_rrule.h"
+#include "cal_db_alarm.h"
+#include "cal_db_attendee.h"
+#include "cal_db_extended.h"
+#include "cal_access_control.h"
+
+static int __cal_db_todo_insert_record(calendar_record_h record, int* id);
+static int __cal_db_todo_get_record(int id, calendar_record_h* out_record);
+static int __cal_db_todo_update_record(calendar_record_h record);
+static int __cal_db_todo_delete_record(int id);
+static int __cal_db_todo_get_all_records(int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_todo_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list);
+static int __cal_db_todo_insert_records(const calendar_list_h list, int** ids);
+static int __cal_db_todo_update_records(const calendar_list_h list);
+static int __cal_db_todo_delete_records(int ids[], int count);
+static int __cal_db_todo_get_count(int *out_count);
+static int __cal_db_todo_get_count_with_query(calendar_query_h query, int *out_count);
+static int __cal_db_todo_replace_record(calendar_record_h record, int id);
+static int __cal_db_todo_replace_records(const calendar_list_h list, int ids[], int count);
+
+/*
+ * static function
+ */
+static void __cal_db_todo_get_stmt(sqlite3_stmt *stmt,bool is_view_table,calendar_record_h record, int *extended);
+static void __cal_db_todo_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record);
+static void __cal_db_todo_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record);
+static int __cal_db_todo_update_dirty(calendar_record_h record);
+static int __cal_db_todo_get_deleted_data(int id, int* calendar_book_id, int* created_ver);
+static bool __cal_db_todo_check_calendar_book_type(calendar_record_h record);
+
+cal_db_plugin_cb_s _cal_db_todo_plugin_cb = {
+       .is_query_only = false,
+       .insert_record = __cal_db_todo_insert_record,
+       .get_record = __cal_db_todo_get_record,
+       .update_record = __cal_db_todo_update_record,
+       .delete_record = __cal_db_todo_delete_record,
+       .get_all_records = __cal_db_todo_get_all_records,
+       .get_records_with_query = __cal_db_todo_get_records_with_query,
+       .insert_records = __cal_db_todo_insert_records,
+       .update_records = __cal_db_todo_update_records,
+       .delete_records = __cal_db_todo_delete_records,
+       .get_count=__cal_db_todo_get_count,
+       .get_count_with_query=__cal_db_todo_get_count_with_query,
+       .replace_record = __cal_db_todo_replace_record,
+       .replace_records = __cal_db_todo_replace_records
+};
+
+static int __cal_db_todo_insert_record(calendar_record_h record, int* id)
+{
+       int ret = -1;
+       int index = -1;
+       int input_ver;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char dtstart_datetime[32] = {0};
+       char dtend_datetime[32] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_todo_s* todo =  (cal_todo_s*)(record);
+       cal_rrule_s *rrule = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int tmp = 0;
+       int calendar_book_id = 0;
+       calendar_record_h record_calendar = NULL;
+       int has_alarm = 0;
+
+       retv_if(NULL == todo, CALENDAR_ERROR_INVALID_PARAMETER);
+       retv_if(false == __cal_db_todo_check_calendar_book_type(record), CALENDAR_ERROR_INVALID_PARAMETER);
+
+       // access control
+       if (_cal_access_control_have_write_permission(todo->calendar_id) == false)
+       {
+               ERR("_cal_access_control_have_write_permission() failed");
+               return CALENDAR_ERROR_PERMISSION_DENIED;
+       }
+
+       ret = calendar_record_get_int(record,
+                       _calendar_todo.calendar_book_id, &calendar_book_id);
+       DBG("calendar_book_id(%d)", calendar_book_id);
+
+       ret = _cal_db_get_record(_calendar_book._uri,
+                       calendar_book_id, &record_calendar);
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_INVALID_PARAMETER, "calendar_book_id is invalid");
+
+       calendar_record_destroy(record_calendar, true);
+
+       has_alarm = _cal_db_alarm_has_alarm(todo->alarm_list);
+       input_ver = _cal_db_util_get_next_ver();
+       int is_allday = 0;
+       if (CALENDAR_TIME_LOCALTIME == todo->start.type
+                       && (0 == todo->start.time.date.hour)
+                       && (0 == todo->start.time.date.minute)
+                       && (0 == todo->start.time.date.second)
+                       && (0 == todo->due.time.date.hour)
+                       && (0 == todo->due.time.date.minute)
+                       && (0 == todo->due.time.date.second)) {
+               is_allday = 1;
+       }
+
+       ret = snprintf(query, sizeof(query),
+                       "INSERT INTO %s ("
+                       "type, "
+                       "created_ver, changed_ver, "
+                       "summary, description, location, categories,  "
+                       "task_status, priority, "
+                       "sensitivity, uid, "
+                       "calendar_id, "
+                       "latitude, longitude, "
+                       "created_time, completed_time, progress, "
+                       "dtstart_type, dtstart_utime, dtstart_datetime, dtstart_tzid, "
+                       "dtend_type, dtend_utime, dtend_datetime, dtend_tzid, "
+                       "last_mod, rrule_id, "
+                       "has_alarm, updated, "
+                       "sync_data1, sync_data2, sync_data3, sync_data4, "
+                       "organizer_name, organizer_email, "
+                       "has_attendee, has_extended, "
+                       "freq, is_allday "
+                       ") VALUES ( "
+                       "%d, "
+                       "%d, %d, "
+                       "?, ?, ?, ?, "
+                       "%d, %d, "
+                       "%d, ?, "
+                       "%d, "
+                       "%lf, %lf, "
+                       "strftime('%%s', 'now'), %lld, %d, "
+                       "%d, %lld, ?, ?, "
+                       "%d, %lld, ?, ?, "
+                       "strftime('%%s', 'now'), %d, "
+                       "%d, %ld, "
+                       "?, ?, ?, ?, "
+                       "?, ?, "
+                       "%d, %d, "
+                       "%d, %d "
+                       ") ",
+               CAL_TABLE_SCHEDULE,
+               CAL_SCH_TYPE_TODO, /*event->cal_type,*/
+               input_ver, input_ver,
+               todo->todo_status, todo->priority,
+               todo->sensitivity,
+               todo->calendar_id,
+               todo->latitude, todo->longitude,
+               todo->completed_time, todo->progress,
+               todo->start.type, todo->start.type == CALENDAR_TIME_UTIME ? todo->start.time.utime : 0,
+               todo->due.type, todo->due.type == CALENDAR_TIME_UTIME ? todo->due.time.utime : 0,
+               todo->freq > 0 ? 1 : 0,
+               has_alarm,
+               todo->updated,
+               (todo->attendee_list && 0 < todo->attendee_list->count) ? 1 : 0,
+               (todo->extended_list && 0 < todo->extended_list->count) ? 1 : 0,
+               todo->freq, is_allday);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               SEC_DBG("[%s]", query);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       int count = 1;
+
+       if (todo->summary)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->summary);
+       count++;
+
+       if (todo->description)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->description);
+       count++;
+
+       if (todo->location)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->location);
+       count++;
+
+       if (todo->categories)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->categories);
+       count++;
+
+       if (todo->uid)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->uid);
+       count++;
+
+       if (CALENDAR_TIME_LOCALTIME == todo->start.type)
+       {
+               snprintf(dtstart_datetime, sizeof(dtstart_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               todo->start.time.date.year,
+                               todo->start.time.date.month,
+                               todo->start.time.date.mday,
+                               todo->start.time.date.hour,
+                               todo->start.time.date.minute,
+                               todo->start.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, count, dtstart_datetime);
+       }
+       count++;
+
+       if (todo->start_tzid)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->start_tzid);
+       count++;
+
+       if (CALENDAR_TIME_LOCALTIME == todo->due.type)
+       {
+               snprintf(dtend_datetime, sizeof(dtend_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               todo->due.time.date.year,
+                               todo->due.time.date.month,
+                               todo->due.time.date.mday,
+                               todo->due.time.date.hour,
+                               todo->due.time.date.minute,
+                               todo->due.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, count, dtend_datetime);
+       }
+       count++;
+
+       if (todo->due_tzid)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->due_tzid);
+       count++;
+
+       if (todo->sync_data1)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->sync_data1);
+       count++;
+       if (todo->sync_data2)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->sync_data2);
+       count++;
+       if (todo->sync_data3)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->sync_data3);
+       count++;
+       if (todo->sync_data4)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->sync_data4);
+       count++;
+       if (todo->organizer_name)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->organizer_name);
+       count++;
+       if (todo->organizer_email)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->organizer_email);
+       count++;
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret)
+       {
+               sqlite3_finalize(stmt);
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       index = _cal_db_util_last_insert_id();
+       sqlite3_finalize(stmt);
+
+       calendar_record_get_int(record, _calendar_todo.id, &tmp);
+       _cal_record_set_int(record, _calendar_todo.id, index);
+       if (id)
+       {
+               *id = index;
+       }
+
+       _cal_db_rrule_get_rrule_from_todo(record, &rrule);
+       _cal_db_rrule_insert_record(index, rrule);
+
+       if (todo->alarm_list && 0 < todo->alarm_list->count) {
+               ret = _cal_db_alarm_insert_records(todo->alarm_list, index);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_alarm_insert_records() failed(%x)", ret);
+       }
+
+       if (todo->attendee_list && 0 < todo->attendee_list->count) {
+               ret = _cal_db_attendee_insert_records(todo->attendee_list, index);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_attendee_insert_records() failed(%x)", ret);
+       }
+
+       if (todo->extended_list && 0 < todo->extended_list->count) {
+               DBG("insert extended");
+               ret = _cal_db_extended_insert_records(todo->extended_list, index, CALENDAR_RECORD_TYPE_TODO);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_extended_insert_records() Failed(%x)", ret);
+       }
+       else {
+               DBG("No extended");
+       }
+
+       CAL_FREE(rrule);
+       _cal_db_util_notify(CAL_NOTI_TYPE_TODO);
+
+       _cal_record_set_int(record, _calendar_todo.id, tmp);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_todo_get_record(int id, calendar_record_h* out_record)
+{
+       char query[CAL_DB_SQL_MAX_LEN];
+       int rc = 0;
+       cal_todo_s *todo = NULL;
+       cal_rrule_s *rrule = NULL;
+       sqlite3_stmt *stmt = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int extended = 0;
+       calendar_record_h record_calendar;
+       calendar_book_sync_event_type_e sync_event_type = CALENDAR_BOOK_SYNC_EVENT_FOR_ME;
+       int ret = 0;
+
+       rc = calendar_record_create( _calendar_todo._uri ,out_record);
+       if (rc != CALENDAR_ERROR_NONE)
+       {
+               ERR("calendar_record_create(%d)", rc);
+               return CALENDAR_ERROR_OUT_OF_MEMORY;
+       }
+
+       todo =  (cal_todo_s*)(*out_record);
+
+       snprintf(query, sizeof(query), "SELECT * FROM %s "
+                       "WHERE id=%d AND (type = %d OR type = %d) AND calendar_id IN "
+                       "(select id from %s where deleted = 0)",
+                       CAL_TABLE_SCHEDULE,
+                       id, CALENDAR_BOOK_TYPE_TODO, CALENDAR_BOOK_TYPE_NONE,
+                       CAL_TABLE_CALENDAR);
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_record_destroy(*out_record, true);
+               *out_record = NULL;
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (dbret != CAL_DB_ROW)
+       {
+               ERR("Failed to step stmt(%d)[%s]", dbret, query);
+               sqlite3_finalize(stmt);
+               calendar_record_destroy(*out_record, true);
+               *out_record = NULL;
+               switch (dbret)
+               {
+               case CAL_DB_DONE:
+                       ERR("Failed to find record(%d)", dbret);
+                       return CALENDAR_ERROR_DB_RECORD_NOT_FOUND;
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       __cal_db_todo_get_stmt(stmt,false,*out_record, &extended);
+       sqlite3_finalize(stmt);
+       stmt = NULL;
+
+       //check
+       ret = _cal_db_get_record(_calendar_book._uri,
+                       todo->calendar_id, &record_calendar);
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               ret = calendar_record_get_int(record_calendar,
+                               _calendar_book.sync_event, (int *)&sync_event_type);
+               calendar_record_destroy(record_calendar, true);
+       }
+       if (todo->is_deleted == 1
+                       && sync_event_type != CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_REMAIN
+               )
+       {
+               calendar_record_destroy(*out_record, true);
+               *out_record = NULL;
+               return CALENDAR_ERROR_DB_RECORD_NOT_FOUND;
+       }
+
+       if (_cal_db_rrule_get_rrule(todo->index, &rrule) == CALENDAR_ERROR_NONE)
+       {
+               _cal_db_rrule_set_rrule_to_todo(rrule, *out_record);
+               CAL_FREE(rrule);
+       }
+
+       if (todo->has_alarm == 1)
+               _cal_db_alarm_get_records(todo->index, todo->alarm_list);
+
+       if (todo->has_attendee == 1)
+               _cal_db_attendee_get_records(todo->index, todo->attendee_list);
+
+       if (extended == 1)
+               _cal_db_extended_get_records(todo->index, CALENDAR_RECORD_TYPE_TODO, todo->extended_list);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_todo_update_record(calendar_record_h record)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char dtstart_datetime[32] = {0};
+       char dtend_datetime[32] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_todo_s* todo =  (cal_todo_s*)(record);
+       cal_rrule_s *rrule = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int has_alarm = 0;
+
+       retv_if(NULL == todo, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       // access control
+       if (_cal_access_control_have_write_permission(todo->calendar_id) == false)
+       {
+               ERR("_cal_access_control_have_write_permission() failed");
+               return CALENDAR_ERROR_PERMISSION_DENIED;
+       }
+
+       //if (CAL_SYNC_STATUS_UPDATED != todo->sync_status)
+       //  todo->sync_status = CAL_SYNC_STATUS_UPDATED;
+       if (todo->common.properties_flags != NULL)
+       {
+               return __cal_db_todo_update_dirty(record);
+       }
+
+       has_alarm = _cal_db_alarm_has_alarm(todo->alarm_list);
+       int is_allday = 0;
+       if (CALENDAR_TIME_LOCALTIME == todo->start.type
+                       && (0 == todo->start.time.date.hour)
+                       && (0 == todo->start.time.date.minute)
+                       && (0 == todo->start.time.date.second)
+                       && (0 == todo->due.time.date.hour)
+                       && (0 == todo->due.time.date.minute)
+                       && (0 == todo->due.time.date.second)) {
+               is_allday = 1;
+       }
+
+       snprintf(query, sizeof(query), "UPDATE %s SET "
+                       "changed_ver = %d,"
+                       "type = %d,"
+                       "summary = ?,"
+                       "description = ?,"
+                       "location = ?,"
+                       "categories = ?,"
+                       "task_status = %d,"
+                       "priority = %d,"
+                       "sensitivity = %d, "
+                       "uid = ?, "
+                       "calendar_id = %d, "
+                       "latitude = %lf,"
+                       "longitude = %lf,"
+                       "completed_time = %lld,"
+                       "progress = %d, "
+                       "dtstart_type = %d, "
+                       "dtstart_utime = %lld, "
+                       "dtstart_datetime = ?, "
+                       "dtstart_tzid = ?, "
+                       "dtend_type = %d, "
+                       "dtend_utime = %lld, "
+                       "dtend_datetime = ?, "
+                       "dtend_tzid = ?, "
+                       "last_mod = strftime('%%s', 'now'), "
+                       "has_alarm = %d, "
+                       "updated = %ld, "
+                       "sync_data1 = ?, "
+                       "sync_data2 = ?, "
+                       "sync_data3 = ?, "
+                       "sync_data4 = ?, "
+                       "organizer_name = ?, "
+                       "organizer_email = ?, "
+                       "has_attendee = %d,"
+                       "has_extended = %d, "
+                       "is_allday = %d "
+                       "WHERE id = %d;",
+               CAL_TABLE_SCHEDULE,
+               _cal_db_util_get_next_ver(),
+               CAL_SCH_TYPE_TODO,/*todo->cal_type,*/
+               todo->todo_status,
+               todo->priority,
+               todo->sensitivity,
+               todo->calendar_id,
+               todo->latitude,
+               todo->longitude,
+               todo->completed_time,
+               todo->progress,
+               todo->start.type,
+               todo->start.type == CALENDAR_TIME_UTIME ? todo->start.time.utime : 0,
+               todo->due.type,
+               todo->due.type == CALENDAR_TIME_UTIME ? todo->due.time.utime : 0,
+               has_alarm,
+               todo->updated,
+               (todo->attendee_list && 0 < todo->attendee_list->count) ? 1 : 0,
+               (todo->extended_list && 0 < todo->extended_list->count) ? 1 : 0,
+               is_allday,
+               todo->index);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() Failed");
+
+       int count = 1;
+
+       if (todo->summary)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->summary);
+       count++;
+
+       if (todo->description)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->description);
+       count++;
+
+       if (todo->location)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->location);
+       count++;
+
+       if (todo->categories)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->categories);
+       count++;
+
+       if (todo->uid)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->uid);
+       count++;
+
+       if (CALENDAR_TIME_LOCALTIME == todo->start.type)
+       {
+               snprintf(dtstart_datetime, sizeof(dtstart_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               todo->start.time.date.year,
+                               todo->start.time.date.month,
+                               todo->start.time.date.mday,
+                               todo->start.time.date.hour,
+                               todo->start.time.date.minute,
+                               todo->start.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, count, dtstart_datetime);
+       }
+       count++;
+
+       if (todo->start_tzid)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->start_tzid);
+       count++;
+
+       if (CALENDAR_TIME_LOCALTIME == todo->due.type)
+       {
+               snprintf(dtend_datetime, sizeof(dtend_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               todo->due.time.date.year,
+                               todo->due.time.date.month,
+                               todo->due.time.date.mday,
+                               todo->due.time.date.hour,
+                               todo->due.time.date.minute,
+                               todo->due.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, count, dtend_datetime);
+       }
+       count++;
+
+       if (todo->due_tzid)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->due_tzid);
+       count++;
+
+       if (todo->sync_data1)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->sync_data1);
+       count++;
+       if (todo->sync_data2)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->sync_data2);
+       count++;
+       if (todo->sync_data3)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->sync_data3);
+       count++;
+       if (todo->sync_data4)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->sync_data4);
+       count++;
+       if (todo->organizer_name)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->organizer_name);
+       count++;
+       if (todo->organizer_email)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->organizer_email);
+       count++;
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret) {
+               sqlite3_finalize(stmt);
+               ERR("sqlite3_step() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       sqlite3_finalize(stmt);
+
+       _cal_db_rrule_get_rrule_from_todo(record, &rrule);
+       _cal_db_rrule_update_record(todo->index, rrule);
+       CAL_FREE(rrule);
+
+       //_cal_db_instance_publish_record(record);
+
+       _cal_db_alarm_delete_with_id(todo->index);
+       _cal_db_attendee_delete_with_id(todo->index);
+       _cal_db_extended_delete_with_id(todo->index, CALENDAR_RECORD_TYPE_TODO);
+
+       if (todo->alarm_list && 0 < todo->alarm_list->count) {
+               ret = _cal_db_alarm_insert_records(todo->alarm_list, todo->index);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_alarm_insert_records() Failed(%d)", ret);
+       }
+
+       if (todo->attendee_list && 0 < todo->attendee_list->count) {
+               ret = _cal_db_attendee_insert_records(todo->attendee_list, todo->index);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_attendee_insert_records() Failed(%d)", ret);
+       }
+
+
+       if (todo->extended_list && 0 < todo->extended_list->count) {
+               DBG("insert extended");
+               ret = _cal_db_extended_insert_records(todo->extended_list, todo->index, CALENDAR_RECORD_TYPE_TODO);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_extended_insert_records() Failed(%d)", ret);
+       }
+
+       _cal_db_util_notify(CAL_NOTI_TYPE_TODO);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_todo_delete_record(int id)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int calendar_book_id;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       int created_ver = 0;
+       calendar_book_sync_event_type_e sync_event_type = CALENDAR_BOOK_SYNC_EVENT_FOR_ME;
+
+       retvm_if(id < 0, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid argument: id < 0");
+
+       ret = __cal_db_todo_get_deleted_data(id, &calendar_book_id, &created_ver);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               DBG("__cal_db_event_get_deleted_data() failed");
+               return ret;
+       }
+
+       //access control
+       if (_cal_access_control_have_write_permission(calendar_book_id) == false)
+       {
+               ERR("fail");
+               return CALENDAR_ERROR_PERMISSION_DENIED;
+       }
+
+       snprintf(query, sizeof(query), "SELECT sync_event FROM %s WHERE id = %d ",
+                       CAL_TABLE_CALENDAR, calendar_book_id);
+       ret = _cal_db_util_query_get_first_int_result(query, NULL, (int *)&sync_event_type);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               return ret;
+       }
+       DBG("sync_event_type(%d)", sync_event_type);
+
+       if (sync_event_type == CALENDAR_BOOK_SYNC_EVENT_FOR_EVERY_AND_REMAIN)
+       {
+               DBG("set is_delete");
+               snprintf(query, sizeof(query),
+                               "UPDATE %s "
+                               "SET is_deleted = 1, "
+                               "changed_ver = %d, "
+                               "last_mod = strftime('%%s','now') "
+                               "WHERE id = %d ",
+                               CAL_TABLE_SCHEDULE,
+                               _cal_db_util_get_next_ver(),
+                               id);
+
+               dbret = _cal_db_util_query_exec(query);
+               if (dbret != CAL_DB_OK)
+               {
+                       ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+                       switch (dbret)
+                       {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+
+               DBG("attendee, alarm and rrule will be deleted by trigger after sync clean");
+       }
+       else
+       {
+               _cal_db_util_get_next_ver();
+
+               DBG("delete event");
+               snprintf(query, sizeof(query),
+                               "DELETE FROM %s "
+                               "WHERE id = %d ",
+                               CAL_TABLE_SCHEDULE,
+                               id);
+
+               dbret = _cal_db_util_query_exec(query);
+               if (CAL_DB_OK != dbret)
+               {
+                       DBG("query[%s]", query);
+                       ERR("_cal_db_util_query_exec() Failed");
+                       switch (dbret)
+                       {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+
+               DBG("attendee, alarm and rrule is deleted by trigger");
+       }
+       _cal_db_util_notify(CAL_NOTI_TYPE_TODO);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_todo_replace_record(calendar_record_h record, int id)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char dtstart_datetime[32] = {0};
+       char dtend_datetime[32] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_todo_s* todo =  (cal_todo_s*)(record);
+       cal_rrule_s *rrule = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       int has_alarm = 0;
+
+       retv_if(NULL == todo, CALENDAR_ERROR_INVALID_PARAMETER);
+       todo->index = id;
+
+       // access control
+       if (_cal_access_control_have_write_permission(todo->calendar_id) == false)
+       {
+               ERR("_cal_access_control_have_write_permission() failed");
+               return CALENDAR_ERROR_PERMISSION_DENIED;
+       }
+
+       //if (CAL_SYNC_STATUS_UPDATED != todo->sync_status)
+       //  todo->sync_status = CAL_SYNC_STATUS_UPDATED;
+       if (todo->common.properties_flags != NULL)
+       {
+               return __cal_db_todo_update_dirty(record);
+       }
+       int is_allday = 0;
+       if (CALENDAR_TIME_LOCALTIME == todo->start.type
+                       && (0 == todo->start.time.date.hour)
+                       && (0 == todo->start.time.date.minute)
+                       && (0 == todo->start.time.date.second)
+                       && (0 == todo->due.time.date.hour)
+                       && (0 == todo->due.time.date.minute)
+                       && (0 == todo->due.time.date.second)) {
+               is_allday = 1;
+       }
+
+       has_alarm = _cal_db_alarm_has_alarm(todo->alarm_list);
+       snprintf(query, sizeof(query), "UPDATE %s SET "
+                       "changed_ver = %d,"
+                       "type = %d,"
+                       "summary = ?,"
+                       "description = ?,"
+                       "location = ?,"
+                       "categories = ?,"
+                       "task_status = %d,"
+                       "priority = %d,"
+                       "sensitivity = %d, "
+                       "uid = ?, "
+                       "calendar_id = %d, "
+                       "latitude = %lf,"
+                       "longitude = %lf,"
+                       "completed_time = %lld,"
+                       "progress = %d, "
+                       "dtstart_type = %d, "
+                       "dtstart_utime = %lld, "
+                       "dtstart_datetime = ?, "
+                       "dtstart_tzid = ?, "
+                       "dtend_type = %d, "
+                       "dtend_utime = %lld, "
+                       "dtend_datetime = ?, "
+                       "dtend_tzid = ?, "
+                       "last_mod = strftime('%%s', 'now'), "
+                       "has_alarm = %d, "
+                       "updated = %ld, "
+                       "sync_data1 = ?, "
+                       "sync_data2 = ?, "
+                       "sync_data3 = ?, "
+                       "sync_data4 = ?, "
+                       "organizer_name = ?, "
+                       "organizer_email = ?, "
+                       "has_attendee = %d,"
+                       "has_extended = %d, "
+                       "is_allday = %d "
+                       "WHERE id = %d;",
+               CAL_TABLE_SCHEDULE,
+               _cal_db_util_get_next_ver(),
+               CAL_SCH_TYPE_TODO,/*todo->cal_type,*/
+               todo->todo_status,
+               todo->priority,
+               todo->sensitivity,
+               todo->calendar_id,
+               todo->latitude,
+               todo->longitude,
+               todo->completed_time,
+               todo->progress,
+               todo->start.type,
+               todo->start.type == CALENDAR_TIME_UTIME ? todo->start.time.utime : 0,
+               todo->due.type,
+               todo->due.type == CALENDAR_TIME_UTIME ? todo->due.time.utime : 0,
+               has_alarm,
+               todo->updated,
+               (todo->attendee_list && 0 < todo->attendee_list->count) ? 1 : 0,
+               (todo->extended_list && 0 < todo->extended_list->count) ? 1 : 0,
+               is_allday,
+               id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() Failed");
+
+       int count = 1;
+
+       if (todo->summary)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->summary);
+       count++;
+
+       if (todo->description)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->description);
+       count++;
+
+       if (todo->location)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->location);
+       count++;
+
+       if (todo->categories)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->categories);
+       count++;
+
+       if (todo->uid)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->uid);
+       count++;
+
+       if (CALENDAR_TIME_LOCALTIME == todo->start.type)
+       {
+               snprintf(dtstart_datetime, sizeof(dtstart_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               todo->start.time.date.year,
+                               todo->start.time.date.month,
+                               todo->start.time.date.mday,
+                               todo->start.time.date.hour,
+                               todo->start.time.date.minute,
+                               todo->start.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, count, dtstart_datetime);
+       }
+       count++;
+
+       if (todo->start_tzid)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->start_tzid);
+       count++;
+
+       if (CALENDAR_TIME_LOCALTIME == todo->due.type)
+       {
+               snprintf(dtend_datetime, sizeof(dtend_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               todo->due.time.date.year,
+                               todo->due.time.date.month,
+                               todo->due.time.date.mday,
+                               todo->due.time.date.hour,
+                               todo->due.time.date.minute,
+                               todo->due.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, count, dtend_datetime);
+       }
+       count++;
+
+       if (todo->due_tzid)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->due_tzid);
+       count++;
+
+       if (todo->sync_data1)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->sync_data1);
+       count++;
+       if (todo->sync_data2)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->sync_data2);
+       count++;
+       if (todo->sync_data3)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->sync_data3);
+       count++;
+       if (todo->sync_data4)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->sync_data4);
+       count++;
+       if (todo->organizer_name)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->organizer_name);
+       count++;
+       if (todo->organizer_email)
+               _cal_db_util_stmt_bind_text(stmt, count, todo->organizer_email);
+       count++;
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE != dbret) {
+               sqlite3_finalize(stmt);
+               ERR("sqlite3_step() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       sqlite3_finalize(stmt);
+
+       _cal_db_rrule_get_rrule_from_todo(record, &rrule);
+       _cal_db_rrule_update_record(id, rrule);
+       CAL_FREE(rrule);
+
+       //_cal_db_instance_publish_record(record);
+
+       _cal_db_alarm_delete_with_id(id);
+       _cal_db_attendee_delete_with_id(id);
+       _cal_db_extended_delete_with_id(id, CALENDAR_RECORD_TYPE_TODO);
+
+       if (todo->alarm_list && 0 < todo->alarm_list->count) {
+               ret = _cal_db_alarm_insert_records(todo->alarm_list, id);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_alarm_insert_records() failed(%x)", ret);
+       }
+
+       if (todo->attendee_list && 0 < todo->attendee_list->count) {
+               ret = _cal_db_attendee_insert_records(todo->attendee_list, id);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_attendee_insert_records() failed(%x)", ret);
+       }
+
+       if (todo->extended_list && 0 < todo->extended_list->count) {
+               DBG("insert extended");
+               ret = _cal_db_extended_insert_records(todo->extended_list, id, CALENDAR_RECORD_TYPE_TODO);
+               warn_if(CALENDAR_ERROR_NONE != ret, "_cal_db_extended_insert_records() Failed(%d)", ret);
+       }
+
+       _cal_db_util_notify(CAL_NOTI_TYPE_TODO);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_todo_get_all_records(int offset, int limit, calendar_list_h* out_list)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char offsetquery[CAL_DB_SQL_MAX_LEN] = {0};
+       char limitquery[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == out_list, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       ret = calendar_list_create(out_list);
+       retvm_if(CALENDAR_ERROR_NONE != ret, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       if (offset > 0)
+       {
+               snprintf(offsetquery, sizeof(offsetquery), "OFFSET %d", offset);
+       }
+       if (limit > 0)
+       {
+               snprintf(limitquery, sizeof(limitquery), "LIMIT %d", limit);
+       }
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT * FROM");
+       _cal_db_append_string(&query_str, CAL_VIEW_TABLE_TODO);
+       _cal_db_append_string(&query_str, limitquery);
+       _cal_db_append_string(&query_str, offsetquery);
+
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               calendar_list_destroy(*out_list, true);
+               *out_list = NULL;
+               CAL_FREE(query_str);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               int extended = 0;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_todo._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+               __cal_db_todo_get_stmt(stmt,true,record, &extended);
+
+               // child
+               int has_attendee = 0, has_alarm = 0;
+               int record_id = 0;
+               cal_todo_s* ptodo = (cal_todo_s*) record;
+               calendar_record_get_int(record, _calendar_todo.id, &record_id);
+               if(calendar_record_get_int(record, _calendar_todo.has_attendee,&has_attendee) == CALENDAR_ERROR_NONE)
+               {
+                       if( has_attendee == 1)
+                       {
+                               _cal_db_attendee_get_records(record_id, ptodo->attendee_list);
+                       }
+               }
+               if(calendar_record_get_int(record, _calendar_todo.has_alarm,&has_alarm) == CALENDAR_ERROR_NONE)
+               {
+                       if( has_alarm == 1)
+                       {
+                               _cal_db_alarm_get_records(record_id, ptodo->alarm_list);
+                       }
+               }
+
+               if (extended == 1)
+                       _cal_db_extended_get_records(record_id, CALENDAR_RECORD_TYPE_TODO, ptodo->extended_list);
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_todo_get_records_with_query(calendar_query_h query, int offset, int limit, calendar_list_h* out_list)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *projection = NULL;
+       GSList *bind_text = NULL, *cursor = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int i = 0;
+       char *table_name;
+
+       que = (cal_query_s *)query;
+
+       if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_TODO))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_TODO);
+       }
+       else if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_TODO_CALENDAR))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_TODO_CALENDAR);
+       }
+       else
+       {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+               //table_name = SAFE_STRDUP(CAL_TABLE_NORMAL_INSTANCE);
+       }
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       // make projection
+       ret = _cal_db_query_create_projection(query, &projection);
+
+       char *query_str = NULL;
+
+       // query - projection
+       if (projection)
+       {
+               _cal_db_append_string(&query_str, "SELECT");
+               _cal_db_append_string(&query_str, projection);
+               _cal_db_append_string(&query_str, "FROM");
+               _cal_db_append_string(&query_str, table_name);
+               CAL_FREE(projection);
+       }
+       else
+       {
+               _cal_db_append_string(&query_str, "SELECT * FROM");
+               _cal_db_append_string(&query_str, table_name);
+       }
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str, "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+       }
+
+       // ORDER
+       char *order = NULL;
+       ret = _cal_db_query_create_order(query, condition, &order);
+       if (order)
+       {
+               _cal_db_append_string(&query_str, order);
+               CAL_FREE(order);
+       }
+       CAL_FREE(condition);
+
+       // limit, offset
+       char buf[32] = {0};
+       if (limit > 0)
+       {
+               snprintf(buf, sizeof(buf), "LIMIT %d", limit);
+               _cal_db_append_string(&query_str, buf);
+
+               if (offset > 0)
+               {
+                       snprintf(buf, sizeof(buf), "OFFSET %d", offset);
+                       _cal_db_append_string(&query_str, buf);
+               }
+       }
+
+       // query
+       stmt = _cal_db_util_query_prepare(query_str);
+       if (NULL == stmt)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       CAL_DBG("%s",query_str);
+
+       // bind text
+       if (bind_text)
+       {
+               g_slist_length(bind_text);
+               for (cursor=bind_text, i=1; cursor;cursor=cursor->next, i++)
+               {
+                       _cal_db_util_stmt_bind_text(stmt, i, cursor->data);
+               }
+       }
+
+       //
+       ret = calendar_list_create(out_list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               ERR("calendar_list_create() Failed");
+               sqlite3_finalize(stmt);
+               CAL_FREE(query_str);
+               return ret;
+       }
+
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               calendar_record_h record;
+               int extended = 1;
+               int attendee = 1, alarm = 1;
+               // stmt -> record
+               ret = calendar_record_create(_calendar_todo._uri,&record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+               if (que->projection_count > 0)
+               {
+                       _cal_record_set_projection(record,
+                                       que->projection, que->projection_count, que->property_count);
+
+                       __cal_db_todo_get_projection_stmt(stmt,
+                                       que->projection, que->projection_count,
+                                       record);
+               }
+               else
+               {
+                       cal_todo_s *todo = NULL;
+                       __cal_db_todo_get_stmt(stmt,true,record, &extended);
+                       todo = (cal_todo_s*)(record);
+                       if (todo)
+                       {
+                               attendee = todo->has_attendee;
+                               alarm = todo->has_alarm;
+                       }
+               }
+
+               // child
+               if (_cal_db_query_find_projection_property(query,CAL_PROPERTY_TODO_CALENDAR_ALARM) == true && alarm ==1)
+               {
+                       cal_todo_s* todo = (cal_todo_s*) record;
+                       _cal_db_alarm_get_records(todo->index, todo->alarm_list);
+               }
+               if (_cal_db_query_find_projection_property(query,CAL_PROPERTY_TODO_CALENDAR_ATTENDEE) == true && attendee==1)
+               {
+                       cal_todo_s* todo = (cal_todo_s*) record;
+                       _cal_db_attendee_get_records(todo->index, todo->attendee_list);
+               }
+               if (_cal_db_query_find_projection_property(query,CAL_PROPERTY_TODO_EXTENDED) == true && extended == 1)
+               {
+                       cal_todo_s* todo = (cal_todo_s*) record;
+                       _cal_db_extended_get_records(todo->index, CALENDAR_RECORD_TYPE_TODO, todo->extended_list);
+               }
+
+               ret = calendar_list_add(*out_list,record);
+               if( ret != CALENDAR_ERROR_NONE )
+               {
+                       calendar_list_destroy(*out_list, true);
+                       *out_list = NULL;
+                       calendar_record_destroy(record, true);
+
+                       if (bind_text)
+                       {
+                               g_slist_free_full(bind_text, free);
+                               bind_text = NULL;
+                       }
+                       sqlite3_finalize(stmt);
+                       CAL_FREE(query_str);
+                       return ret;
+               }
+       }
+
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+
+       sqlite3_finalize(stmt);
+       CAL_FREE(query_str);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_todo_insert_records(const calendar_list_h list, int** ids)
+{
+       calendar_record_h record;
+       int ret = 0;
+       int count = 0;
+       int i=0;
+       int *id = NULL;
+
+       ret = calendar_list_get_count(list, &count);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list get error");
+               return ret;
+       }
+
+       id = calloc(1, sizeof(int)*count);
+
+       retvm_if(NULL == id, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc fail");
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list first error");
+               CAL_FREE(id);
+               return ret;
+       }
+       do
+       {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE)
+               {
+                       if( __cal_db_todo_insert_record(record, &id[i]) != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("db insert error");
+                               CAL_FREE(id);
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+               i++;
+       } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+
+       if(ids)
+       {
+               *ids = id;
+       }
+       else
+       {
+               CAL_FREE(id);
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_todo_update_records(const calendar_list_h list)
+{
+       calendar_record_h record;
+       int ret = 0;
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list first error");
+               return ret;
+       }
+       do
+       {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE)
+               {
+                       if( __cal_db_todo_update_record(record) != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("db insert error");
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+       } while(calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_todo_delete_records(int ids[], int count)
+{
+       int i=0;
+       for(i=0;i<count;i++)
+       {
+               if (__cal_db_todo_delete_record(ids[i]) != CALENDAR_ERROR_NONE)
+               {
+                       ERR("delete failed");
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_todo_get_count(int *out_count)
+{
+       retvm_if(NULL == out_count, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+       char *query_str = NULL;
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, CAL_VIEW_TABLE_TODO);
+
+       int ret = 0;
+       int count = 0;
+       ret = _cal_db_util_query_get_first_int_result(query_str, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+       CAL_FREE(query_str);
+
+       *out_count = count;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_todo_replace_records(const calendar_list_h list, int ids[], int count)
+{
+       calendar_record_h record;
+       int i = 0;
+       int ret = 0;
+
+       if (NULL == list)
+       {
+               ERR("Invalid argument: list is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = calendar_list_first(list);
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("list first error");
+               return ret;
+       }
+
+       for (i = 0; i < count; i++)
+       {
+               if( calendar_list_get_current_record_p(list, &record) == CALENDAR_ERROR_NONE)
+               {
+                       if( __cal_db_todo_replace_record(record, ids[i]) != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("db insert error");
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+               if (CALENDAR_ERROR_NO_DATA != calendar_list_next(list))
+               {
+                       break;
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+
+static int __cal_db_todo_get_count_with_query(calendar_query_h query, int *out_count)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       char *condition = NULL;
+       char *table_name;
+       int count = 0;
+       GSList *bind_text = NULL;
+
+       que = (cal_query_s *)query;
+
+       if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_TODO))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_TODO);
+       }
+       else if ( 0 == strcmp(que->view_uri, CALENDAR_VIEW_TODO_CALENDAR))
+       {
+               table_name = SAFE_STRDUP(CAL_VIEW_TABLE_TODO_CALENDAR);
+       }
+       else
+       {
+               ERR("uri(%s) not support get records with query",que->view_uri);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       // make filter
+       if (que->filter)
+       {
+               ret = _cal_db_query_create_condition(query, &condition, &bind_text);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       CAL_FREE(table_name);
+                       ERR("filter create fail");
+                       return ret;
+               }
+       }
+
+       char *query_str = NULL;
+       // query - select from
+       _cal_db_append_string(&query_str, "SELECT count(*) FROM");
+       _cal_db_append_string(&query_str, table_name);
+       CAL_FREE(table_name);
+
+       // query - condition
+       if (condition)
+       {
+               _cal_db_append_string(&query_str,  "WHERE (");
+               _cal_db_append_string(&query_str, condition);
+               _cal_db_append_string(&query_str, ")");
+               CAL_FREE(condition);
+       }
+
+       // query
+       ret = _cal_db_util_query_get_first_int_result(query_str, bind_text, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               if (bind_text)
+               {
+                       g_slist_free_full(bind_text, free);
+                       bind_text = NULL;
+               }
+               CAL_FREE(query_str);
+               return ret;
+       }
+       CAL_DBG("count(%d) str[%s]", count, query_str);
+
+       if (out_count) *out_count = count;
+       if (bind_text)
+       {
+               g_slist_free_full(bind_text, free);
+               bind_text = NULL;
+       }
+
+       CAL_FREE(query_str);
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_db_todo_get_stmt(sqlite3_stmt *stmt,bool is_view_table,calendar_record_h record, int *extended)
+{
+       cal_todo_s *todo = NULL;
+       const unsigned char *temp;
+       int count = 0;
+       char *dtstart_datetime;
+       char *dtend_datetime;
+       char buf[8] = {0};
+
+       todo = (cal_todo_s*)(record);
+
+       todo->index = sqlite3_column_int(stmt, count++);
+       sqlite3_column_int(stmt, count++);//todo->cal_type = 1;/*sqlite3_column_int(stmt, count++);*/
+
+       temp = sqlite3_column_text(stmt, count++);
+       todo->summary = SAFE_STRDUP(temp);
+       temp = sqlite3_column_text(stmt, count++);
+       todo->description = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       todo->location = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       todo->categories = SAFE_STRDUP(temp);
+
+       sqlite3_column_text(stmt, count++);
+       //todo->exdate = SAFE_STRDUP(temp);
+
+       todo->todo_status = sqlite3_column_int(stmt, count++);
+       todo->priority = sqlite3_column_int(stmt, count++);
+       sqlite3_column_int(stmt, count++);//todo->timezone = sqlite3_column_int(stmt, count++);
+       sqlite3_column_int(stmt, count++);//todo->contact_id = sqlite3_column_int(stmt, count++);
+       sqlite3_column_int(stmt, count++);//todo->busy_status = sqlite3_column_int(stmt, count++);
+       todo->sensitivity = sqlite3_column_int(stmt, count++);
+
+       temp = sqlite3_column_text(stmt, count++);
+       todo->uid = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       todo->organizer_name = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, count++);
+       todo->organizer_email = SAFE_STRDUP(temp);
+
+       sqlite3_column_int(stmt, count++);//todo->meeting_status = sqlite3_column_int(stmt, count++);
+
+       todo->calendar_id = sqlite3_column_int(stmt, count++);
+
+       sqlite3_column_int(stmt, count++);//todo->original_todo_id = sqlite3_column_int(stmt, count++);
+
+       todo->latitude = sqlite3_column_double(stmt,count++);
+       todo->longitude = sqlite3_column_double(stmt,count++);
+       sqlite3_column_int(stmt, count++);//todo->email_id = sqlite3_column_int(stmt, count++);
+
+       todo->created_time = sqlite3_column_int64(stmt, count++);
+
+       todo->completed_time = sqlite3_column_int64(stmt, count++);
+
+       todo->progress = sqlite3_column_int(stmt,count++);
+
+       sqlite3_column_int(stmt,count++);   //__version
+       sqlite3_column_int(stmt,count++);   //__version
+       todo->is_deleted = sqlite3_column_int(stmt,count++);
+
+       todo->start.type = sqlite3_column_int(stmt,count++);
+
+       if (todo->start.type == CALENDAR_TIME_UTIME)
+       {
+               todo->start.time.utime = sqlite3_column_int64(stmt,count++);
+               sqlite3_column_text(stmt, count++); // dtstart_datetime
+       }
+       else
+       {
+               sqlite3_column_int64(stmt,count++); //todo->start.time.utime = sqlite3_column_int64(stmt,count++);
+               temp = sqlite3_column_text(stmt, count++);
+               if (temp) {
+                       dtstart_datetime = SAFE_STRDUP(temp);
+                       snprintf(buf, strlen("YYYY") + 1, "%s", dtstart_datetime);
+                       todo->start.time.date.year =  atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 5);
+                       todo->start.time.date.month = atoi(buf);
+                       snprintf(buf, strlen("DD") + 1, "%s", dtstart_datetime + 8);
+                       todo->start.time.date.mday = atoi(buf);
+                       snprintf(buf, strlen("HH") + 1, "%s", dtstart_datetime + 11);
+                       todo->start.time.date.hour = atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 14);
+                       todo->start.time.date.minute = atoi(buf);
+                       snprintf(buf, strlen("SS") + 1, "%s", dtstart_datetime + 17);
+                       todo->start.time.date.second = atoi(buf);
+                       if (dtstart_datetime) free(dtstart_datetime);
+               }
+       }
+
+       temp = sqlite3_column_text(stmt, count++);
+       todo->start_tzid = SAFE_STRDUP(temp);
+       todo->due.type = sqlite3_column_int(stmt, count++);
+       if (todo->due.type == CALENDAR_TIME_UTIME)
+       {
+               todo->due.time.utime = sqlite3_column_int64(stmt,count++);
+               sqlite3_column_text(stmt, count++); // dtdue_datetime
+       }
+       else
+       {
+               sqlite3_column_int64(stmt, count++);//todo->due.time.utime = sqlite3_column_int64(stmt, count++);
+               temp = sqlite3_column_text(stmt, count++);
+               if (temp) {
+                       dtend_datetime = SAFE_STRDUP(temp);
+                       snprintf(buf, strlen("YYYY") + 1, "%s", dtend_datetime);
+                       todo->due.time.date.year =  atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 5);
+                       todo->due.time.date.month = atoi(buf);
+                       snprintf(buf, strlen("DD") + 1, "%s", dtend_datetime + 8);
+                       todo->due.time.date.mday = atoi(buf);
+                       snprintf(buf, strlen("HH") + 1, "%s", dtend_datetime + 11);
+                       todo->due.time.date.hour = atoi(buf);
+                       snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 14);
+                       todo->due.time.date.minute = atoi(buf);
+                       snprintf(buf, strlen("SS") + 1, "%s", dtend_datetime + 17);
+                       todo->due.time.date.second = atoi(buf);
+                       if (dtend_datetime) free(dtend_datetime);
+               }
+       }
+       temp = sqlite3_column_text(stmt, count++);
+       todo->due_tzid = SAFE_STRDUP(temp);
+
+       todo->last_mod = sqlite3_column_int64(stmt,count++);
+       sqlite3_column_int(stmt,count++);//todo->rrule_id = sqlite3_column_int(stmt,count++);
+
+       sqlite3_column_text(stmt, count++);
+       //todo->recurrence_id = SAFE_STRDUP(temp);
+       sqlite3_column_text(stmt, count++);
+       //todo->rdate = SAFE_STRDUP(temp);
+       todo->has_attendee = sqlite3_column_int(stmt,count++);
+       todo->has_alarm = sqlite3_column_int(stmt,count++);
+       sqlite3_column_int(stmt,count++); // system_type...
+       todo->updated = sqlite3_column_int(stmt,count++);
+       temp = sqlite3_column_text(stmt, count++);
+       todo->sync_data1 = SAFE_STRDUP(temp);
+       temp = sqlite3_column_text(stmt, count++);
+       todo->sync_data2 = SAFE_STRDUP(temp);
+       temp = sqlite3_column_text(stmt, count++);
+       todo->sync_data3 = SAFE_STRDUP(temp);
+       temp = sqlite3_column_text(stmt, count++);
+       todo->sync_data4 = SAFE_STRDUP(temp);
+
+       //has_exception
+       sqlite3_column_int(stmt,count++);
+
+       //has_extended
+       if (extended != NULL)
+               *extended = sqlite3_column_int(stmt,count++);
+
+       todo->freq = sqlite3_column_int(stmt, count++);
+       todo->is_allday = sqlite3_column_int(stmt, count++);
+
+       if (is_view_table == true)
+       {
+               if (todo->freq <= 0) {
+                       //todo->rrule_id = 0;
+                       //sqlite3_finalize(stmt);
+                       //return CALENDAR_ERROR_NONE;
+                       return ;
+               }
+
+               //todo->rrule_id = 1;
+               todo->range_type = sqlite3_column_int(stmt, count++);
+               todo->until.type = sqlite3_column_int(stmt, count++);
+               todo->until.time.utime = sqlite3_column_int64(stmt, count++);
+
+               temp = sqlite3_column_text(stmt, count++);
+               if (temp && CALENDAR_TIME_LOCALTIME == todo->until.type)
+               {
+                       sscanf((const char *)temp, CAL_FORMAT_LOCAL_DATETIME,
+                                       &todo->until.time.date.year,
+                                       &todo->until.time.date.month,
+                                       &todo->until.time.date.mday,
+                                       &todo->until.time.date.hour,
+                                       &todo->until.time.date.minute,
+                                       &todo->until.time.date.second);
+               }
+
+               todo->count = sqlite3_column_int(stmt, count++);
+               todo->interval = sqlite3_column_int(stmt, count++);
+
+               temp = sqlite3_column_text(stmt, count++);
+               todo->bysecond = SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               todo->byminute = SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               todo->byhour = SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               todo->byday= SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               todo->bymonthday= SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               todo->byyearday= SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               todo->byweekno= SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               todo->bymonth= SAFE_STRDUP(temp);
+
+               temp = sqlite3_column_text(stmt, count++);
+               todo->bysetpos = SAFE_STRDUP(temp);
+
+               todo->wkst = sqlite3_column_int(stmt, count++);
+
+               sqlite3_column_int(stmt, count++); //calendar deleted
+       }
+}
+
+static void __cal_db_todo_get_property_stmt(sqlite3_stmt *stmt,
+               unsigned int property, int *stmt_count, calendar_record_h record)
+{
+       cal_todo_s *todo = NULL;
+       const unsigned char *temp;
+       char *dtstart_datetime;
+       char *dtend_datetime;
+       char buf[8] = {0};
+
+       todo = (cal_todo_s*)(record);
+
+       switch(property)
+       {
+       case CAL_PROPERTY_TODO_ID:
+               todo->index = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_CALENDAR_ID:
+               todo->calendar_id = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_SUMMARY:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->summary = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_DESCRIPTION:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->description = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_LOCATION:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->location = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_CATEGORIES:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->categories = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_TODO_STATUS:
+               todo->todo_status = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_PRIORITY:
+               todo->priority = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_SENSITIVITY:
+               todo->sensitivity = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_UID:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->uid = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_LATITUDE:
+               todo->latitude = sqlite3_column_double(stmt,*stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_LONGITUDE:
+               todo->longitude = sqlite3_column_double(stmt,*stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_PROGRESS:
+               todo->progress = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_COMPLETED_TIME:
+               todo->completed_time = sqlite3_column_int64(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_CREATED_TIME:
+               todo->created_time = sqlite3_column_int64(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_LAST_MODIFIED_TIME:
+               todo->last_mod = sqlite3_column_int64(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_IS_DELETED:
+               todo->is_deleted = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_FREQ:
+               todo->freq = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_RANGE_TYPE:
+               todo->range_type = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_UNTIL:
+               //!!
+               break;
+       case CAL_PROPERTY_TODO_COUNT:
+               todo->count = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_INTERVAL:
+               todo->interval = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_BYSECOND:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->bysecond = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_BYMINUTE:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->byminute = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_BYHOUR:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->byhour = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_BYDAY:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->byday = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_BYMONTHDAY:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->bymonthday = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_BYYEARDAY:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->byyearday = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_BYWEEKNO:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->byweekno = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_BYMONTH:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->bymonth = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_BYSETPOS:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->bysetpos = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_WKST:
+               todo->wkst = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_HAS_ALARM:
+               todo->has_alarm = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA1:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->sync_data1 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA2:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->sync_data2 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA3:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->sync_data3 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_SYNC_DATA4:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->sync_data4 = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_START:
+               //!!
+               todo->start.type = sqlite3_column_int(stmt,*stmt_count);
+               if (todo->start.type == CALENDAR_TIME_UTIME)
+               {
+                       *stmt_count = *stmt_count+1;
+                       todo->start.time.utime = sqlite3_column_int64(stmt,*stmt_count);
+                       *stmt_count = *stmt_count+1;
+                       sqlite3_column_text(stmt, *stmt_count);
+               }
+               else
+               {
+                       *stmt_count = *stmt_count+1;
+                       sqlite3_column_int64(stmt,*stmt_count); //todo->start.time.utime = sqlite3_column_int64(stmt,count++);
+                       *stmt_count = *stmt_count+1;
+                       temp = sqlite3_column_text(stmt, *stmt_count);
+                       if (temp) {
+                               dtstart_datetime = SAFE_STRDUP(temp);
+                               snprintf(buf, strlen("YYYY") + 1, "%s", dtstart_datetime);
+                               todo->start.time.date.year =  atoi(buf);
+                               snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 5);
+                               todo->start.time.date.month = atoi(buf);
+                               snprintf(buf, strlen("DD") + 1, "%s", dtstart_datetime + 8);
+                               todo->start.time.date.mday = atoi(buf);
+                               snprintf(buf, strlen("HH") + 1, "%s", dtstart_datetime + 11);
+                               todo->start.time.date.hour = atoi(buf);
+                               snprintf(buf, strlen("MM") + 1, "%s", dtstart_datetime + 14);
+                               todo->start.time.date.minute = atoi(buf);
+                               snprintf(buf, strlen("SS") + 1, "%s", dtstart_datetime + 17);
+                               todo->start.time.date.second = atoi(buf);
+                               if (dtstart_datetime) free(dtstart_datetime);
+                       }
+               }
+               break;
+       case CAL_PROPERTY_TODO_START_TZID:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->start_tzid = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_DUE:
+               //!!
+               todo->due.type = sqlite3_column_int(stmt, *stmt_count);
+               if (todo->due.type == CALENDAR_TIME_UTIME)
+               {
+                       *stmt_count = *stmt_count+1;
+                       todo->due.time.utime = sqlite3_column_int64(stmt,*stmt_count);
+                       *stmt_count = *stmt_count+1;
+                       sqlite3_column_text(stmt, *stmt_count);
+               }
+               else
+               {
+                       *stmt_count = *stmt_count+1;
+                       sqlite3_column_int64(stmt, *stmt_count);//todo->due.time.utime = sqlite3_column_int64(stmt, count++);
+                       *stmt_count = *stmt_count+1;
+                       temp = sqlite3_column_text(stmt, *stmt_count);
+                       if (temp) {
+                               dtend_datetime = SAFE_STRDUP(temp);
+                               snprintf(buf, strlen("YYYY") + 1, "%s", dtend_datetime);
+                               todo->due.time.date.year =  atoi(buf);
+                               snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 5);
+                               todo->due.time.date.month = atoi(buf);
+                               snprintf(buf, strlen("DD") + 1, "%s", dtend_datetime + 8);
+                               todo->due.time.date.mday = atoi(buf);
+                               snprintf(buf, strlen("HH") + 1, "%s", dtend_datetime + 11);
+                               todo->due.time.date.hour = atoi(buf);
+                               snprintf(buf, strlen("MM") + 1, "%s", dtend_datetime + 14);
+                               todo->due.time.date.minute = atoi(buf);
+                               snprintf(buf, strlen("SS") + 1, "%s", dtend_datetime + 17);
+                               todo->due.time.date.second = atoi(buf);
+                               if (dtend_datetime) free(dtend_datetime);
+                       }
+               }
+               break;
+       case CAL_PROPERTY_TODO_DUE_TZID:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->due_tzid = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_ORGANIZER_NAME:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->organizer_name = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_ORGANIZER_EMAIL:
+               temp = sqlite3_column_text(stmt, *stmt_count);
+               todo->organizer_email = SAFE_STRDUP(temp);
+               break;
+       case CAL_PROPERTY_TODO_HAS_ATTENDEE:
+               todo->has_attendee = sqlite3_column_int(stmt, *stmt_count);
+               break;
+       default:
+               sqlite3_column_int(stmt, *stmt_count);
+               break;
+       }
+
+       *stmt_count = *stmt_count+1;
+}
+
+static void __cal_db_todo_get_projection_stmt(sqlite3_stmt *stmt,
+               const unsigned int *projection, const int projection_count,
+               calendar_record_h record)
+{
+       int i=0;
+       int stmt_count = 0;
+
+       for(i=0;i<projection_count;i++)
+       {
+               __cal_db_todo_get_property_stmt(stmt,projection[i],&stmt_count,record);
+       }
+}
+
+static bool __cal_db_todo_check_calendar_book_type(calendar_record_h record)
+{
+       int store_type = 0;
+       cal_todo_s *todo = (cal_todo_s *)record;
+       char query[CAL_DB_SQL_MAX_LEN];
+       sqlite3_stmt *stmt = NULL;
+
+       snprintf(query, sizeof(query), "SELECT store_type "
+                       "FROM %s WHERE id = %d ",
+                       CAL_TABLE_CALENDAR, todo->calendar_id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("query[%s]", query);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return false;
+       }
+
+       if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               store_type = sqlite3_column_int(stmt, 0);
+       }
+       else {
+               sqlite3_finalize(stmt);
+               stmt = NULL;
+               DBG("Failed to get calendar: calendar_id(%d)", todo->calendar_id);
+               return false;
+       }
+       sqlite3_finalize(stmt);
+
+       bool ret = false;
+       switch (store_type) {
+       case CALENDAR_BOOK_TYPE_NONE:
+       case CALENDAR_BOOK_TYPE_TODO:
+               ret = true;
+               break;
+       case CALENDAR_BOOK_TYPE_EVENT:
+       default:
+               ret = false;
+               break;
+       }
+       return ret;
+}
+
+
+static int __cal_db_todo_update_dirty(calendar_record_h record)
+{
+       int todo_id = 0;
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_record_h original_record;
+
+       ret = calendar_record_get_int(record,_calendar_todo.id, &todo_id);
+       retv_if(CALENDAR_ERROR_NONE != ret, ret);
+
+       CAL_DBG("id=%d",todo_id);
+
+       retv_if(false == __cal_db_todo_check_calendar_book_type(record), CALENDAR_ERROR_INVALID_PARAMETER);
+
+       ret = __cal_db_todo_get_record(todo_id, &original_record);
+
+       if (ret == CALENDAR_ERROR_NONE)
+       {
+               cal_record_s *_record = NULL;
+               const cal_property_info_s* property_info = NULL;
+               int property_info_count = 0;
+               int i=0;
+
+               _record = (cal_record_s *)record;
+
+               property_info = _cal_view_get_property_info(_record->view_uri, &property_info_count);
+
+               for(i=0;i<property_info_count;i++)
+               {
+                       if (true == _cal_record_check_property_flag(record, property_info[i].property_id , CAL_PROPERTY_FLAG_DIRTY))
+                       {
+                               if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_INT) == true)
+                               {
+                                       int tmp=0;
+                                       ret = calendar_record_get_int(record,property_info[i].property_id,&tmp);
+                                       if (ret != CALENDAR_ERROR_NONE)
+                                               continue;
+                                       ret = _cal_record_set_int(original_record, property_info[i].property_id, tmp);
+                                       if (ret != CALENDAR_ERROR_NONE)
+                                               continue;
+                               }
+                               else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_STR) == true)
+                               {
+                                       char *tmp=NULL;
+                                       ret = calendar_record_get_str_p(record,property_info[i].property_id,&tmp);
+                                       if (ret != CALENDAR_ERROR_NONE)
+                                               continue;
+                                       ret = _cal_record_set_str(original_record, property_info[i].property_id, tmp);
+                                       if (ret != CALENDAR_ERROR_NONE)
+                                               continue;
+                               }
+                               else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_DOUBLE) == true)
+                               {
+                                       double tmp=0;
+                                       ret = calendar_record_get_double(record,property_info[i].property_id,&tmp);
+                                       if (ret != CALENDAR_ERROR_NONE)
+                                               continue;
+                                       ret = _cal_record_set_double(original_record, property_info[i].property_id, tmp);
+                                       if (ret != CALENDAR_ERROR_NONE)
+                                               continue;
+                               }
+                               else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_LLI) == true)
+                               {
+                                       long long int tmp=0;
+                                       ret = calendar_record_get_lli(record,property_info[i].property_id,&tmp);
+                                       if (ret != CALENDAR_ERROR_NONE)
+                                               continue;
+                                       ret = _cal_record_set_lli(original_record, property_info[i].property_id, tmp);
+                                       if (ret != CALENDAR_ERROR_NONE)
+                                               continue;
+                               }
+                               else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_CALTIME) == true)
+                               {
+                                       calendar_time_s tmp = {0,};
+                                       ret = calendar_record_get_caltime(record,property_info[i].property_id,&tmp);
+                                       if (ret != CALENDAR_ERROR_NONE)
+                                               continue;
+                                       ret = _cal_record_set_caltime(original_record, property_info[i].property_id, tmp);
+                                       if (ret != CALENDAR_ERROR_NONE)
+                                               continue;
+                               }
+                       }
+               }
+
+               // child replace
+               // alarm
+               cal_todo_s *tmp = (cal_todo_s *)original_record;
+               cal_todo_s *tmp_src = (cal_todo_s *)record;
+
+               _cal_list_clone((calendar_list_h)tmp_src->alarm_list, (calendar_list_h *)&tmp->alarm_list);
+               _cal_list_clone((calendar_list_h)tmp_src->attendee_list, (calendar_list_h *)&tmp->attendee_list);
+               _cal_list_clone((calendar_list_h)tmp_src->extended_list, (calendar_list_h *)&tmp->extended_list);
+
+       }
+       else
+       {
+               CAL_DBG("get_record fail");
+               return ret;
+       }
+
+       CAL_RECORD_RESET_COMMON((cal_record_s*)original_record);
+       ret = __cal_db_todo_update_record(original_record);
+
+       calendar_record_destroy(original_record, true);
+
+       return ret;
+}
+
+static int __cal_db_todo_get_deleted_data(int id, int* calendar_book_id, int* created_ver)
+{
+       char query[CAL_DB_SQL_MAX_LEN];
+       sqlite3_stmt *stmt = NULL;
+
+       snprintf(query, sizeof(query), "SELECT calendar_id, created_ver "
+                       "FROM %s WHERE id = %d ",
+                       CAL_TABLE_SCHEDULE, id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("query[%s]", query);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               *calendar_book_id = sqlite3_column_int(stmt, 0);
+               *created_ver = sqlite3_column_int(stmt, 1);
+       }
+       else
+       {
+               sqlite3_finalize(stmt);
+               stmt = NULL;
+               DBG("Failed to get deleted_data: event_id(%d)", id);
+               return CALENDAR_ERROR_DB_RECORD_NOT_FOUND;
+       }
+
+       sqlite3_finalize(stmt);
+       stmt = NULL;
+       return CALENDAR_ERROR_NONE;
+}
diff --git a/native/cal_db_query.c b/native/cal_db_query.c
new file mode 100644 (file)
index 0000000..d032b7b
--- /dev/null
@@ -0,0 +1,1024 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_record.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_db_query.h"
+
+#define CAL_DB_CALTIME_FIELD_MAX 3
+#define CAL_DB_ESCAPE_CHAR     '\\'
+
+static const char* __cal_db_utime_field_name[] =
+{
+       "dtstart_utime",
+       "dtend_utime",
+       "until_utime"
+};
+static const char* __cal_db_datetime_field_name[] =
+{
+       "dtstart_datetime",
+       "dtend_datetime",
+       "until_datetime"
+};
+static const char* __cal_db_timetype_field_name[] =
+{
+       "dtstart_type",
+       "dtend_type",
+       "until_type"
+};
+
+static int __cal_db_query_create_composite_condition(cal_composite_filter_s *com_filter,
+               char **condition, GSList **bind_text);
+static int __cal_db_query_create_attribute_condition(cal_composite_filter_s *com_filter,
+               cal_attribute_filter_s *filter, char **condition, GSList **bind_text);
+static int __cal_db_query_create_str_condition(cal_composite_filter_s *com_filter,
+               cal_attribute_filter_s *filter, char **condition, GSList **bind_text);
+static int __cal_db_query_create_int_condition(cal_composite_filter_s *com_filter,
+               cal_attribute_filter_s *filter, char **condition );
+static int __cal_db_query_create_double_condition(cal_composite_filter_s *com_filter,
+               cal_attribute_filter_s *filter, char **condition );
+static int __cal_db_query_create_lli_condition(cal_composite_filter_s *com_filter,
+               cal_attribute_filter_s *filter, char **condition );
+static int __cal_db_query_create_caltime_condition(cal_composite_filter_s *com_filter,
+               cal_attribute_filter_s *filter, char **condition );
+static const char * __cal_db_query_get_property_field_name(const cal_property_info_s *properties,
+               int count, unsigned int property_id);
+static const char * __cal_db_query_get_utime_field_name(const char* src);
+static const char * __cal_db_query_get_datetime_field_name(const char* src);
+static const char * __cal_db_query_get_timetype_field_name(const char* src);
+
+int _cal_db_query_create_condition(calendar_query_h query, char **condition, GSList **bind_text)
+{
+       cal_query_s *que = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retv_if(NULL == query || NULL == condition || NULL == bind_text, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       que = (cal_query_s *)query;
+
+       ret = __cal_db_query_create_composite_condition(que->filter, condition, bind_text);
+
+       return ret;
+}
+
+int _cal_db_query_create_projection(calendar_query_h query, char **projection)
+{
+       int i = 0;
+       const char *field_name;
+       char *out_projection = NULL;
+       cal_query_s *query_s = NULL;
+       cal_property_info_s *properties = NULL;
+
+       retv_if(NULL == query, CALENDAR_ERROR_INVALID_PARAMETER);
+       query_s = (cal_query_s *)query;
+
+       properties = query_s->properties;
+
+       if (query_s->projection)
+       {
+               field_name = __cal_db_query_get_property_field_name(properties, query_s->property_count, query_s->projection[0]);
+               if (field_name)
+                       _cal_db_append_string(&out_projection, (char*)field_name);
+
+               for (i=1;i<query_s->projection_count;i++)
+               {
+                       field_name = __cal_db_query_get_property_field_name(properties, query_s->property_count, query_s->projection[i]);
+                       if (field_name)
+                       {
+                               _cal_db_append_string(&out_projection, ",");
+                               _cal_db_append_string(&out_projection, (char*)field_name);
+                       }
+               }
+       }
+       else
+       {
+               // projection이 없을 경우 select *
+               _cal_db_append_string(&out_projection, "* ");
+       }
+
+       *projection = out_projection;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_query_create_order(calendar_query_h query, char *condition, char **order)
+{
+       const char *field_name = NULL;
+       char out_order[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_query_s *query_s = NULL;
+       cal_property_info_s *properties = NULL;
+
+       retv_if(NULL == query, CALENDAR_ERROR_INVALID_PARAMETER);
+       query_s = (cal_query_s *)query;
+       properties = query_s->properties;
+
+       if (query_s->sort_property_id > 0)
+       {
+               field_name = __cal_db_query_get_property_field_name(properties, query_s->property_count, query_s->sort_property_id);
+               if (CAL_PROPERTY_CHECK_DATA_TYPE(query_s->sort_property_id, CAL_PROPERTY_DATA_TYPE_CALTIME) == true && field_name)
+               {
+                       const char *p_utime = NULL;
+                       const char *p_datetime = NULL;
+
+                       p_utime = __cal_db_query_get_utime_field_name(field_name);
+                       p_datetime = __cal_db_query_get_datetime_field_name(field_name);
+
+                       if (!p_utime && !p_datetime)
+                       {
+                               if (condition)
+                               {
+                                       p_utime = __cal_db_query_get_utime_field_name(condition);
+                                       p_datetime = __cal_db_query_get_datetime_field_name(condition);
+                               }
+                               else
+                               {
+                                       DBG("No condition");
+                               }
+                       }
+
+                       if (p_utime && p_datetime)
+                       {
+                               snprintf(out_order, sizeof(out_order), "ORDER BY %s %s, %s %s, summary ASC ",
+                                               p_utime, query_s->asc == false ? "DESC" : "ASC",
+                                               p_datetime, query_s->asc == false ? "DESC" : "ASC");
+                       }
+                       else if (p_utime && !p_datetime)
+                       {
+                               snprintf(out_order, sizeof(out_order), "ORDER BY %s %s, summary ASC ",
+                                               p_utime, query_s->asc == false ? "DESC" : "ASC");
+                       }
+                       else if (!p_utime && p_datetime)
+                       {
+                               snprintf(out_order, sizeof(out_order), "ORDER BY %s %s, summary ASC ",
+                                               p_datetime, query_s->asc == false ? "DESC" : "ASC");
+                       }
+                       else
+                       {
+                               DBG("No utime, datetime");
+                       }
+               }
+               else
+               {
+                       snprintf(out_order, sizeof(out_order), "ORDER BY %s %s, summary ASC ",
+                                       field_name, query_s->asc == false ? " DESC" : "ASC");
+               }
+       }
+       else
+       {
+               return CALENDAR_ERROR_NO_DATA;
+       }
+       *order = strdup(out_order);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+bool _cal_db_query_find_projection_property(calendar_query_h query, unsigned int property)
+{
+       int i = 0;
+       cal_query_s *query_s = NULL;
+
+       retv_if(NULL == query, CALENDAR_ERROR_INVALID_PARAMETER);
+       query_s = (cal_query_s *)query;
+
+       if (query_s->projection)
+       {
+               for (i=0;i<query_s->projection_count;i++)
+               {
+                       if (query_s->projection[i] == property)
+                       {
+                               return true;
+                       }
+               }
+       }
+       else
+       {
+               // projection
+               return true;
+       }
+
+       return false;
+}
+
+int _cal_db_query_create_projection_update_set(calendar_record_h record, char **set, GSList **bind_text)
+{
+       cal_record_s *_record = NULL;
+       int i = 0;
+       const cal_property_info_s* property_info = NULL;
+       int property_info_count = 0;
+       char out_set[CAL_DB_SQL_MAX_LEN] = {0};
+       int len = 0;
+       const char *field_name;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retv_if(record == NULL, -1);
+
+       _record = (cal_record_s *)record;
+
+       if (_record->properties_max_count == 0 || _record->properties_flags == NULL)
+       {
+               CAL_DBG("record don't have properties");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       // uri를 통해, property_info_s 가져옴
+       property_info = _cal_view_get_property_info(_record->view_uri, &property_info_count);
+
+       for(i=0;i<property_info_count;i++)
+       {
+               if (true == _cal_record_check_property_flag(record, property_info[i].property_id , CAL_PROPERTY_FLAG_DIRTY) )
+               {
+                       field_name = property_info[i].fields;
+
+                       if (field_name == NULL)
+                       {
+                               continue;
+                       }
+
+                       if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_INT) == true)
+                       {
+                               int tmp=0;
+                               ret = calendar_record_get_int(record,property_info[i].property_id,&tmp);
+                               if (ret != CALENDAR_ERROR_NONE)
+                                       continue;
+                               if (strlen(out_set) != 0)
+                               {
+                                       len += snprintf(out_set+len, sizeof(out_set)-len, ", ");
+                               }
+                               len += snprintf(out_set+len, sizeof(out_set)-len, "%s=%d",field_name,tmp);
+                       }
+                       else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_STR) == true)
+                       {
+                               char *tmp=NULL;
+                               ret = calendar_record_get_str(record,property_info[i].property_id,&tmp);
+                               if (ret != CALENDAR_ERROR_NONE)
+                                       continue;
+                               if (strlen(out_set) != 0)
+                               {
+                                       len += snprintf(out_set+len, sizeof(out_set)-len, ", ");
+                               }
+                               len += snprintf(out_set+len, sizeof(out_set)-len, "%s=?",field_name);
+                               *bind_text = g_slist_append(*bind_text, tmp);
+                       }
+                       else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_DOUBLE) == true)
+                       {
+                               double tmp=0;
+                               ret = calendar_record_get_double(record,property_info[i].property_id,&tmp);
+                               if (ret != CALENDAR_ERROR_NONE)
+                                       continue;
+                               if (strlen(out_set) != 0)
+                               {
+                                       len += snprintf(out_set+len, sizeof(out_set)-len, ", ");
+                               }
+                               len += snprintf(out_set+len, sizeof(out_set)-len, "%s=%lf",field_name,tmp);
+                       }
+                       else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_LLI) == true)
+                       {
+                               long long int tmp=0;
+                               ret = calendar_record_get_lli(record,property_info[i].property_id,&tmp);
+                               if (ret != CALENDAR_ERROR_NONE)
+                                       continue;
+                               if (strlen(out_set) != 0)
+                               {
+                                       len += snprintf(out_set+len, sizeof(out_set)-len, ", ");
+                               }
+                               len += snprintf(out_set+len, sizeof(out_set)-len, "%s=%lld",field_name,tmp);
+                       }
+                       else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_CALTIME) == true)
+                       {
+                               /*
+                                * field_name
+                                * dtstart_type, dtstart_utime, dtstart_datetime
+                                *      -> dtstart_type=%d, dtstart_utime=%lli, dtstart_datetime=?
+                                * dtend_type, dtend_utime, dtend_datetime
+                                *      -> dtend_type=%d, dtend_utime=%lli, dtend_datetime=?
+                                * until_type, until_utime, until_datetime
+                                *      -> until_type=%d, until_utime=%lli, until_datetime=?
+                                */
+                               calendar_time_s tmp = {0,};
+                               const char *timetype_field = NULL;
+                               const char *utime_field = NULL;
+                               const char *datetime_field = NULL;
+                               timetype_field = __cal_db_query_get_timetype_field_name(field_name);
+                               utime_field = __cal_db_query_get_utime_field_name(field_name);
+                               datetime_field = __cal_db_query_get_datetime_field_name(field_name);
+                               ret = calendar_record_get_caltime(record,property_info[i].property_id,&tmp);
+                               if (ret != CALENDAR_ERROR_NONE)
+                                       continue;
+                               if(tmp.type == CALENDAR_TIME_UTIME)
+                               {
+                                       if (strlen(out_set) != 0)
+                                       {
+                                               len += snprintf(out_set+len, sizeof(out_set)-len, ", ");
+                                       }
+                                       len += snprintf(out_set+len, sizeof(out_set)-len, "%s=%d, %s=%lld",
+                                                       timetype_field, CALENDAR_TIME_UTIME, utime_field, tmp.time.utime);
+                               }
+                               else
+                               {
+                                       char *bind_tmp = NULL;
+                                       char bind_datetime[32] = {0};
+                                       snprintf(bind_datetime, sizeof(bind_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                                                       tmp.time.date.year,
+                                                       tmp.time.date.month,
+                                                       tmp.time.date.mday,
+                                                       tmp.time.date.hour,
+                                                       tmp.time.date.minute,
+                                                       tmp.time.date.second);
+
+                                       if (strlen(out_set) != 0)
+                                       {
+                                               len += snprintf(out_set+len, sizeof(out_set)-len, ", ");
+                                       }
+                                       len += snprintf(out_set+len, sizeof(out_set)-len, "%s=%d, %s=?",
+                                                       timetype_field, CALENDAR_TIME_LOCALTIME, datetime_field);
+
+                                       bind_tmp= strdup(bind_datetime);
+                                       *bind_text = g_slist_append(*bind_text, bind_tmp);
+                               }
+                       }
+               }
+       }
+
+       *set = strdup(out_set);
+       CAL_DBG("set=%s",*set);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_query_create_projection_update_set_with_property(
+               calendar_record_h record, unsigned int *properties, int properties_count,
+               char **set, GSList **bind_text)
+{
+       cal_record_s *_record = NULL;
+       int i = 0;
+       const cal_property_info_s* property_info = NULL;
+       int property_info_count = 0;
+       char out_set[CAL_DB_SQL_MAX_LEN] = {0};
+       int len = 0;
+       const char *field_name;
+       int ret = CALENDAR_ERROR_NONE;
+
+       retv_if(record == NULL, -1);
+
+       _record = (cal_record_s *)record;
+
+       if (_record->properties_max_count == 0 || _record->properties_flags == NULL)
+       {
+               return CALENDAR_ERROR_NONE;
+       }
+
+       // uri를 통해, property_info_s 가져옴
+       property_info = _cal_view_get_property_info(_record->view_uri, &property_info_count);
+
+       for(i=0;i<property_info_count;i++)
+       {
+               int j=0;
+               bool flag = false;
+               for(j=0;j<properties_count;j++)
+               {
+                       if( property_info[i].property_id == properties[j] )
+                       {
+                               flag = true;
+                               break;
+                       }
+               }
+               if (true == flag &&
+                               ( true == _cal_record_check_property_flag(record, property_info[i].property_id , CAL_PROPERTY_FLAG_DIRTY))  )
+               {
+                       field_name = property_info[i].fields;
+
+                       if (field_name == NULL)
+                       {
+                               continue;
+                       }
+
+                       if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_INT) == true)
+                       {
+                               int tmp=0;
+                               ret = calendar_record_get_int(record,property_info[i].property_id,&tmp);
+                               if (ret != CALENDAR_ERROR_NONE)
+                                       continue;
+                               if (strlen(out_set) != 0)
+                               {
+                                       len += snprintf(out_set+len, sizeof(out_set)-len, ", ");
+                               }
+                               len += snprintf(out_set+len, sizeof(out_set)-len, "%s=%d",field_name,tmp);
+                       }
+                       else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_STR) == true)
+                       {
+                               char *tmp=NULL;
+                               ret = calendar_record_get_str(record,property_info[i].property_id,&tmp);
+                               if (ret != CALENDAR_ERROR_NONE)
+                                       continue;
+                               if (strlen(out_set) != 0)
+                               {
+                                       len += snprintf(out_set+len, sizeof(out_set)-len, ", ");
+                               }
+                               len += snprintf(out_set+len, sizeof(out_set)-len, "%s=?",field_name);
+                               *bind_text = g_slist_append(*bind_text, tmp);
+                       }
+                       else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_DOUBLE) == true)
+                       {
+                               double tmp=0;
+                               ret = calendar_record_get_double(record,property_info[i].property_id,&tmp);
+                               if (ret != CALENDAR_ERROR_NONE)
+                                       continue;
+                               if (strlen(out_set) != 0)
+                               {
+                                       len += snprintf(out_set+len, sizeof(out_set)-len, ", ");
+                               }
+                               len += snprintf(out_set+len, sizeof(out_set)-len, "%s=%lf",field_name,tmp);
+                       }
+                       else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_LLI) == true)
+                       {
+                               long long int tmp=0;
+                               ret = calendar_record_get_lli(record,property_info[i].property_id,&tmp);
+                               if (ret != CALENDAR_ERROR_NONE)
+                                       continue;
+                               if (strlen(out_set) != 0)
+                               {
+                                       len += snprintf(out_set+len, sizeof(out_set)-len, ", ");
+                               }
+                               len += snprintf(out_set+len, sizeof(out_set)-len, "%s=%lld",field_name,tmp);
+                       }
+                       else if (CAL_PROPERTY_CHECK_DATA_TYPE(property_info[i].property_id,CAL_PROPERTY_DATA_TYPE_CALTIME) == true)
+                       {
+                               /*
+                                * field_name
+                                * dtstart_type, dtstart_utime, dtstart_datetime
+                                *      -> dtstart_type=%d, dtstart_utime=%lli, dtstart_datetime=?
+                                * dtend_type, dtend_utime, dtend_datetime
+                                *      -> dtend_type=%d, dtend_utime=%lli, dtend_datetime=?
+                                * until_type, until_utime, until_datetime
+                                *      -> until_type=%d, until_utime=%lli, until_datetime=?
+                                */
+                               calendar_time_s tmp = {0,};
+                               const char *timetype_field = NULL;
+                               const char *utime_field = NULL;
+                               const char *datetime_field = NULL;
+                               timetype_field = __cal_db_query_get_timetype_field_name(field_name);
+                               utime_field = __cal_db_query_get_utime_field_name(field_name);
+                               datetime_field = __cal_db_query_get_datetime_field_name(field_name);
+                               ret = calendar_record_get_caltime(record,property_info[i].property_id,&tmp);
+                               if (ret != CALENDAR_ERROR_NONE)
+                                       continue;
+                               if(tmp.type == CALENDAR_TIME_UTIME)
+                               {
+                                       if (strlen(out_set) != 0)
+                                       {
+                                               len += snprintf(out_set+len, sizeof(out_set)-len, ", ");
+                                       }
+                                       len += snprintf(out_set+len, sizeof(out_set)-len, "%s=%d, %s=%lld",
+                                                       timetype_field,CALENDAR_TIME_UTIME,utime_field,tmp.time.utime);
+                               }
+                               else
+                               {
+                                       char *bind_tmp = NULL;
+                                       char bind_datetime[32] = {0};
+                                       snprintf(bind_datetime, sizeof(bind_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                                                       tmp.time.date.year,
+                                                       tmp.time.date.month,
+                                                       tmp.time.date.mday,
+                                                       tmp.time.date.hour,
+                                                       tmp.time.date.minute,
+                                                       tmp.time.date.second);
+
+                                       if (strlen(out_set) != 0)
+                                       {
+                                               len += snprintf(out_set+len, sizeof(out_set)-len, ", ");
+                                       }
+                                       len += snprintf(out_set+len, sizeof(out_set)-len, "%s=%d, %s=?",
+                                                       timetype_field, CALENDAR_TIME_LOCALTIME, datetime_field);
+
+                                       bind_tmp= strdup(bind_datetime);
+                                       *bind_text = g_slist_append(*bind_text, bind_tmp);
+                               }
+                       }
+               }
+       }
+
+       *set = strdup(out_set);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_query_create_composite_condition(cal_composite_filter_s *com_filter, char **condition, GSList **bind_text)
+{
+       GSList *cursor_filter = NULL;
+       GSList *cursor_ops = NULL;
+       calendar_filter_operator_e op;
+       char *cond = NULL;
+       char *out_cond = NULL;
+       GSList *binds = NULL, *binds2 = NULL;
+       cal_filter_s *filter;
+       int ret = CALENDAR_ERROR_NONE;
+
+       if (com_filter == NULL || com_filter->filters == NULL)
+       {
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       filter = (cal_filter_s *)com_filter->filters->data;
+       if(filter->filter_type == CAL_FILTER_COMPOSITE)
+       {
+               ret = __cal_db_query_create_composite_condition((cal_composite_filter_s*)filter, &cond, &binds);
+       }
+       else
+       {
+               ret = __cal_db_query_create_attribute_condition(com_filter, (cal_attribute_filter_s*)filter, &cond, &binds);
+       }
+
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("__cal_db_query_create_attribute_condition fail");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       cursor_filter = com_filter->filters->next;
+
+       _cal_db_append_string(&out_cond, "(");
+       _cal_db_append_string(&out_cond, cond);
+       _cal_db_append_string(&out_cond, ")");
+
+       CAL_FREE(cond);
+
+       for(cursor_ops=com_filter->filter_ops; cursor_ops && cursor_filter;
+                       cursor_filter=cursor_filter->next, cursor_ops=cursor_ops->next)
+       {
+               filter = (cal_filter_s *)cursor_filter->data;
+               if(filter->filter_type == CAL_FILTER_COMPOSITE)
+               {
+                       ret = __cal_db_query_create_composite_condition((cal_composite_filter_s*)filter, &cond, &binds2);
+               }
+               else
+               {
+                       ret = __cal_db_query_create_attribute_condition(com_filter, (cal_attribute_filter_s*)filter, &cond, &binds2);
+               }
+
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("__cal_db_query_create_attribute_condition fail");
+                       CAL_FREE(out_cond);
+                       if (binds)
+                       {
+                               g_slist_free_full(binds, free);
+                               binds = NULL;
+                       }
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+
+               op = (calendar_filter_operator_e)cursor_ops->data;
+               if (op == CALENDAR_FILTER_OPERATOR_AND)
+               {
+                       _cal_db_append_string(&out_cond, "AND (");
+                       _cal_db_append_string(&out_cond, cond);
+                       _cal_db_append_string(&out_cond, ")");
+               }
+               else
+               {
+                       _cal_db_append_string(&out_cond, "OR (");
+                       _cal_db_append_string(&out_cond, cond);
+                       _cal_db_append_string(&out_cond, ")");
+               }
+
+               if(binds2)
+                       binds = g_slist_concat(binds, binds2);
+               binds2 = NULL;
+
+               CAL_FREE(cond);
+       }
+
+       *condition = out_cond;
+       *bind_text = binds;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_query_create_attribute_condition(cal_composite_filter_s *com_filter,
+               cal_attribute_filter_s *filter, char **condition, GSList **bind_text)
+{
+       int ret;
+       char *cond = NULL;
+
+       retv_if(NULL == filter, CALENDAR_ERROR_INVALID_PARAMETER);
+
+       switch (filter->filter_type)
+       {
+       case CAL_FILTER_INT:
+               ret = __cal_db_query_create_int_condition(com_filter, filter, &cond);
+               break;
+       case CAL_FILTER_STR:
+               ret = __cal_db_query_create_str_condition(com_filter, filter, &cond, bind_text);
+               break;
+       case CAL_FILTER_DOUBLE:
+               ret = __cal_db_query_create_double_condition(com_filter, filter, &cond);
+               break;
+       case CAL_FILTER_LLI:
+               ret = __cal_db_query_create_lli_condition(com_filter, filter, &cond);
+               break;
+       case CAL_FILTER_CALTIME:
+               ret = __cal_db_query_create_caltime_condition(com_filter, filter, &cond);
+               break;
+       default :
+               ERR("The filter type is not supported (%d)", filter->filter_type);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (CALENDAR_ERROR_NONE == ret)
+               *condition = (cond);
+
+       return ret;
+}
+
+static int __cal_db_query_create_int_condition(cal_composite_filter_s *com_filter,
+               cal_attribute_filter_s *filter, char **condition )
+{
+       const char *field_name;
+       char out_cond[CAL_DB_SQL_MAX_LEN] = {0};
+
+       field_name = __cal_db_query_get_property_field_name(com_filter->properties,
+                       com_filter->property_count, filter->property_id);
+       retvm_if(NULL == field_name, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property id(%d)", filter->property_id);
+
+       switch(filter->match)
+       {
+       case CALENDAR_MATCH_EQUAL:
+               snprintf(out_cond, sizeof(out_cond), "%s = %d", field_name, filter->value.i);
+               break;
+       case CALENDAR_MATCH_GREATER_THAN:
+               snprintf(out_cond, sizeof(out_cond), "%s > %d", field_name, filter->value.i);
+               break;
+       case CALENDAR_MATCH_GREATER_THAN_OR_EQUAL:
+               snprintf(out_cond, sizeof(out_cond), "%s >= %d", field_name, filter->value.i);
+               break;
+       case CALENDAR_MATCH_LESS_THAN:
+               snprintf(out_cond, sizeof(out_cond), "%s < %d", field_name, filter->value.i);
+               break;
+       case CALENDAR_MATCH_LESS_THAN_OR_EQUAL:
+               snprintf(out_cond, sizeof(out_cond), "%s <= %d", field_name, filter->value.i);
+               break;
+       case CALENDAR_MATCH_NONE:
+               snprintf(out_cond, sizeof(out_cond), "%s IS NULL", field_name);
+               break;
+       case CALENDAR_MATCH_NOT_EQUAL:
+               snprintf(out_cond, sizeof(out_cond), "%s <> %d", field_name, filter->value.i);
+               break;
+       default :
+               ERR("Invalid parameter : int match rule(%d) is not supported", filter->match);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       *condition = strdup(out_cond);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_query_create_double_condition(cal_composite_filter_s *com_filter,
+               cal_attribute_filter_s *filter, char **condition )
+{
+       const char *field_name;
+       char out_cond[CAL_DB_SQL_MAX_LEN] = {0};
+
+       field_name = __cal_db_query_get_property_field_name(com_filter->properties,
+                       com_filter->property_count, filter->property_id);
+       retvm_if(NULL == field_name, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property id(%d)", filter->property_id);
+
+       switch(filter->match)
+       {
+       case CALENDAR_MATCH_EQUAL:
+               snprintf(out_cond, sizeof(out_cond), "%s = %lf", field_name, filter->value.d);
+               break;
+       case CALENDAR_MATCH_GREATER_THAN:
+               snprintf(out_cond, sizeof(out_cond), "%s > %lf", field_name, filter->value.d);
+               break;
+       case CALENDAR_MATCH_GREATER_THAN_OR_EQUAL:
+               snprintf(out_cond, sizeof(out_cond), "%s >= %lf", field_name, filter->value.d);
+               break;
+       case CALENDAR_MATCH_LESS_THAN:
+               snprintf(out_cond, sizeof(out_cond), "%s < %lf", field_name, filter->value.d);
+               break;
+       case CALENDAR_MATCH_LESS_THAN_OR_EQUAL:
+               snprintf(out_cond, sizeof(out_cond), "%s <= %lf", field_name, filter->value.d);
+               break;
+       case CALENDAR_MATCH_NONE:
+               snprintf(out_cond, sizeof(out_cond), "%s IS NULL", field_name);
+               break;
+       case CALENDAR_MATCH_NOT_EQUAL:
+               snprintf(out_cond, sizeof(out_cond), "%s <> %lf", field_name, filter->value.d);
+               break;
+       default :
+               ERR("Invalid parameter : int match rule(%d) is not supported", filter->match);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       *condition = strdup(out_cond);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_query_create_lli_condition(cal_composite_filter_s *com_filter,
+               cal_attribute_filter_s *filter, char **condition )
+{
+       const char *field_name;
+       char out_cond[CAL_DB_SQL_MAX_LEN] = {0};
+
+       field_name = __cal_db_query_get_property_field_name(com_filter->properties,
+                       com_filter->property_count, filter->property_id);
+       retvm_if(NULL == field_name, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property id(%d)", filter->property_id);
+
+       switch(filter->match)
+       {
+       case CALENDAR_MATCH_EQUAL:
+               snprintf(out_cond, sizeof(out_cond), "%s = %lld", field_name, filter->value.lli);
+               break;
+       case CALENDAR_MATCH_GREATER_THAN:
+               snprintf(out_cond, sizeof(out_cond), "%s > %lld", field_name, filter->value.lli);
+               break;
+       case CALENDAR_MATCH_GREATER_THAN_OR_EQUAL:
+               snprintf(out_cond, sizeof(out_cond), "%s >= %lld", field_name, filter->value.lli);
+               break;
+       case CALENDAR_MATCH_LESS_THAN:
+               snprintf(out_cond, sizeof(out_cond), "%s < %lld", field_name, filter->value.lli);
+               break;
+       case CALENDAR_MATCH_LESS_THAN_OR_EQUAL:
+               snprintf(out_cond, sizeof(out_cond), "%s <= %lld", field_name, filter->value.lli);
+               break;
+       case CALENDAR_MATCH_NONE:
+               snprintf(out_cond, sizeof(out_cond), "%s IS NULL", field_name);
+               break;
+       case CALENDAR_MATCH_NOT_EQUAL:
+               snprintf(out_cond, sizeof(out_cond), "%s <> %lld", field_name, filter->value.lli);
+               break;
+       default :
+               ERR("Invalid parameter : int match rule(%d) is not supported", filter->match);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       *condition = strdup(out_cond);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_query_create_caltime_condition(cal_composite_filter_s *com_filter,
+               cal_attribute_filter_s *filter, char **condition )
+{
+       const char *field_name;
+       char out_cond[CAL_DB_SQL_MAX_LEN] = {0};
+       const char *tmp = NULL;
+
+       field_name = __cal_db_query_get_property_field_name(com_filter->properties,
+                       com_filter->property_count, filter->property_id);
+       retvm_if(NULL == field_name, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property id(%d)", filter->property_id);
+
+       if (filter->value.caltime.type == CALENDAR_TIME_UTIME )
+       {
+               tmp = __cal_db_query_get_utime_field_name(field_name);
+               if (tmp == NULL)
+               {
+                       tmp = field_name;
+               }
+               switch(filter->match)
+               {
+               case CALENDAR_MATCH_EQUAL:
+                       snprintf(out_cond, sizeof(out_cond), "%s = %lld", tmp, filter->value.caltime.time.utime);
+                       break;
+               case CALENDAR_MATCH_GREATER_THAN:
+                       snprintf(out_cond, sizeof(out_cond), "%s > %lld", tmp, filter->value.caltime.time.utime);
+                       break;
+               case CALENDAR_MATCH_GREATER_THAN_OR_EQUAL:
+                       snprintf(out_cond, sizeof(out_cond), "%s >= %lld", tmp, filter->value.caltime.time.utime);
+                       break;
+               case CALENDAR_MATCH_LESS_THAN:
+                       snprintf(out_cond, sizeof(out_cond), "%s < %lld", tmp, filter->value.caltime.time.utime);
+                       break;
+               case CALENDAR_MATCH_LESS_THAN_OR_EQUAL:
+                       snprintf(out_cond, sizeof(out_cond), "%s <= %lld", tmp, filter->value.caltime.time.utime);
+                       break;
+               case CALENDAR_MATCH_NONE:
+                       snprintf(out_cond, sizeof(out_cond), "%s IS NULL", tmp);
+                       break;
+               case CALENDAR_MATCH_NOT_EQUAL:
+                       snprintf(out_cond, sizeof(out_cond), "%s <> %lld", tmp, filter->value.caltime.time.utime);
+                       break;
+               default :
+                       ERR("Invalid parameter : int match rule(%d) is not supported", filter->match);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+       else if (filter->value.caltime.type == CALENDAR_TIME_LOCALTIME )
+       {
+               char sdate[32] = {0};
+               snprintf(sdate, sizeof(sdate), CAL_FORMAT_LOCAL_DATETIME,
+                               filter->value.caltime.time.date.year, filter->value.caltime.time.date.month, filter->value.caltime.time.date.mday,
+                               filter->value.caltime.time.date.hour, filter->value.caltime.time.date.minute, filter->value.caltime.time.date.second);
+               tmp = __cal_db_query_get_datetime_field_name(field_name);
+               if (tmp == NULL)
+               {
+                       tmp = field_name;
+               }
+               switch(filter->match)
+               {
+               case CALENDAR_MATCH_EQUAL:
+                       snprintf(out_cond, sizeof(out_cond), "%s = '%s'", tmp, sdate);
+                       break;
+               case CALENDAR_MATCH_GREATER_THAN:
+                       snprintf(out_cond, sizeof(out_cond), "%s > '%s'", tmp, sdate);
+                       break;
+               case CALENDAR_MATCH_GREATER_THAN_OR_EQUAL:
+                       snprintf(out_cond, sizeof(out_cond), "%s >= '%s'", tmp, sdate);
+                       break;
+               case CALENDAR_MATCH_LESS_THAN:
+                       snprintf(out_cond, sizeof(out_cond), "%s < '%s'", tmp, sdate);
+                       break;
+               case CALENDAR_MATCH_LESS_THAN_OR_EQUAL:
+                       snprintf(out_cond, sizeof(out_cond), "%s <= '%s'", tmp, sdate);
+                       break;
+               case CALENDAR_MATCH_NOT_EQUAL:
+                       snprintf(out_cond, sizeof(out_cond), "%s <> '%s'", tmp, sdate);
+                       break;
+               case CALENDAR_MATCH_NONE:
+               default :
+                       ERR("Invalid parameter : int match rule(%d) is not supported", filter->match);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+       }
+       else
+       {
+               ERR("Invalid parameter : property id(%d)", filter->property_id);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       cal_record_type_e record_type = _cal_view_get_type(com_filter->view_uri);
+       if (record_type != CAL_RECORD_TYPE_INSTANCE_NORMAL &&
+                       record_type != CAL_RECORD_TYPE_INSTANCE_ALLDAY &&
+                       record_type != CAL_RECORD_TYPE_INSTANCE_NORMAL_EXTENDED &&
+                       record_type != CAL_RECORD_TYPE_INSTANCE_ALLDAY_EXTENDED)
+       {
+               int len = strlen(out_cond);
+               const char *type_field = __cal_db_query_get_timetype_field_name(field_name);
+               snprintf(out_cond + len, sizeof(out_cond) - len -1, " AND %s = %d ", type_field, filter->value.caltime.type);
+       }
+
+       *condition = strdup(out_cond);
+       return CALENDAR_ERROR_NONE;
+}
+
+static char * __cal_db_get_str_with_escape(char *str, int len, bool with_escape)
+{
+       int i, j = 0;
+       char temp_str[len*2+1];
+
+       if (false == with_escape)
+               return strdup(str);
+
+       for(i=0;i<len;i++) {
+               if (str[i] == '\'' || str[i] == '_' || str[i] == '%' || str[i] == '\\') {
+                       temp_str[j++] = CAL_DB_ESCAPE_CHAR;
+               }
+               temp_str[j++] = str[i];
+       }
+       temp_str[j] = '\0';
+
+       return strdup(temp_str);
+}
+
+static int __cal_db_query_create_str_condition(cal_composite_filter_s *com_filter,
+               cal_attribute_filter_s *filter, char **condition, GSList **bind_text)
+{
+       const char *field_name;
+       char out_cond[CAL_DB_SQL_MAX_LEN] = {0};
+       bool with_escape = true;
+
+       field_name = __cal_db_query_get_property_field_name(com_filter->properties,
+                       com_filter->property_count, filter->property_id);
+       retvm_if(NULL == field_name, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid parameter : property id(%d)", filter->property_id);
+
+       switch(filter->match)
+       {
+       case CALENDAR_MATCH_EXACTLY:
+               snprintf(out_cond, sizeof(out_cond), "%s = ?", field_name);
+               with_escape = false;
+               break;
+       case CALENDAR_MATCH_FULLSTRING:
+               snprintf(out_cond, sizeof(out_cond), "%s LIKE ? ESCAPE '%c'", field_name, CAL_DB_ESCAPE_CHAR);
+               break;
+       case CALENDAR_MATCH_CONTAINS:
+               snprintf(out_cond, sizeof(out_cond), "%s LIKE ('%%' || ? || '%%') ESCAPE '%c'", field_name, CAL_DB_ESCAPE_CHAR);
+               break;
+       case CALENDAR_MATCH_STARTSWITH:
+               snprintf(out_cond, sizeof(out_cond), "%s LIKE ( ? || '%%') ESCAPE '%c'", field_name, CAL_DB_ESCAPE_CHAR);
+               break;
+       case CALENDAR_MATCH_ENDSWITH:
+               snprintf(out_cond, sizeof(out_cond), "%s LIKE ('%%' || ?) ESCAPE '%c'", field_name, CAL_DB_ESCAPE_CHAR);
+               break;
+       case CALENDAR_MATCH_EXISTS:
+               snprintf(out_cond, sizeof(out_cond), "%s IS NOT NULL", field_name);
+               break;
+       default :
+               ERR("Invalid paramter : int match rule (%d) is not supported", filter->match);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (filter->value.s)
+       {
+               *bind_text = g_slist_append(*bind_text,
+                               __cal_db_get_str_with_escape(filter->value.s, strlen(filter->value.s), with_escape));
+       }
+       *condition = strdup(out_cond);
+       return CALENDAR_ERROR_NONE;
+}
+
+static const char * __cal_db_query_get_property_field_name(const cal_property_info_s *properties,
+               int count, unsigned int property_id)
+{
+       int i;
+       for (i=0;i<count;i++)
+       {
+               cal_property_info_s *p = (cal_property_info_s*)&(properties[i]);
+               if (property_id == p->property_id)
+               {
+                       if (p->fields)
+                               return p->fields;
+                       else
+                               return NULL; //ctsvc_get_display_column();
+               }
+       }
+       return NULL;
+}
+
+static const char * __cal_db_query_get_utime_field_name(const char* src)
+{
+       char *tmp1 = NULL;
+       int i=0;
+
+       for(i=0;i<CAL_DB_CALTIME_FIELD_MAX;i++)
+       {
+               tmp1 = strstr(src,__cal_db_utime_field_name[i]);
+               if (tmp1 != NULL)
+               {
+                       return __cal_db_utime_field_name[i];
+               }
+       }
+
+       return NULL;
+}
+
+static const char * __cal_db_query_get_datetime_field_name(const char* src)
+{
+       char *tmp1 = NULL;
+       int i=0;
+
+       for(i=0;i<CAL_DB_CALTIME_FIELD_MAX;i++)
+       {
+               tmp1 = strstr(src,__cal_db_datetime_field_name[i]);
+               if (tmp1 != NULL)
+               {
+                       return __cal_db_datetime_field_name[i];
+               }
+       }
+
+       return NULL;
+}
+
+static const char * __cal_db_query_get_timetype_field_name(const char* src)
+{
+       char *tmp1 = NULL;
+       int i=0;
+
+       for(i=0;i<CAL_DB_CALTIME_FIELD_MAX;i++)
+       {
+               tmp1 = strstr(src,__cal_db_timetype_field_name[i]);
+               if (tmp1 != NULL)
+               {
+                       return __cal_db_timetype_field_name[i];
+               }
+       }
+
+       return NULL;
+}
+
diff --git a/native/cal_db_query.h b/native/cal_db_query.h
new file mode 100644 (file)
index 0000000..dff02c0
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __CALENDAR_SVC_DB_QUERY_H__
+#define __CALENDAR_SVC_DB_QUERY_H__
+
+/*
+ * bind_text->date string is only pointer copy.
+ if (bind_text) {
+        g_slist_free(bind_text);
+ }
+ CAL_FREE(condition);
+ CAL_FREE(projection);
+ */
+int _cal_db_query_create_condition(calendar_query_h query, char **condition, GSList **bind_text);
+int _cal_db_query_create_projection(calendar_query_h query, char **projection);
+int _cal_db_query_create_order(calendar_query_h query, char *condition, char **order);
+bool _cal_db_query_find_projection_property(calendar_query_h query, unsigned int property);
+
+/*
+ *  bind_text is strdup copy
+ *  please check bind_text free
+ CAL_FREE(set);
+ if(bind_text) {
+       for (cursor=bind_text; cursor;cursor=cursor->next) {
+        CAL_FREE(cursor->data);
+       }
+       g_slist_free(bind_text);
+ }
+ */
+int _cal_db_query_create_projection_update_set(calendar_record_h record, char **set, GSList **bind_text);
+int _cal_db_query_create_projection_update_set_with_property(
+               calendar_record_h record, unsigned int *properties, int properties_count,
+               char **set, GSList **bind_text);
+
+#endif // __CALENDAR_SVC_DB_QUERY_H__
diff --git a/native/cal_db_rrule.c b/native/cal_db_rrule.c
new file mode 100644 (file)
index 0000000..e134427
--- /dev/null
@@ -0,0 +1,602 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_view.h"
+#include "cal_time.h"
+
+void _cal_db_rrule_set_default(calendar_record_h record)
+{
+       cal_event_s *event = NULL;
+       retm_if(record == NULL, "Invalid argument: rrule is NULL");
+
+       event = (cal_event_s *)record;
+
+       switch (event->freq) {
+       case CALENDAR_RECURRENCE_NONE:
+               break;
+       case CALENDAR_RECURRENCE_DAILY:
+               break;
+       case CALENDAR_RECURRENCE_WEEKLY:
+               if (event->byday && strlen(event->byday) > 0)
+               {
+                       break;
+               }
+
+               event->byday = _cal_time_extract_by(event->system_type, event->start_tzid, event->wkst,
+                               &event->start, CAL_DAY_OF_WEEK);
+               DBG("Not enough field in weekly, so set byda[%s]", event->byday);
+               break;
+
+       case CALENDAR_RECURRENCE_MONTHLY:
+               if (event->bymonthday && strlen(event->bymonthday) > 0) {
+                       break;
+               }
+               else if (event->byday && strlen(event->byday) > 0) {
+                       break;
+               }
+
+               event->bymonthday = _cal_time_extract_by(event->system_type, event->start_tzid, event->wkst,
+                               &event->start, CAL_DATE);
+               DBG("Not enough field in monthly, so set bymonthday[%s]", event->bymonthday);
+               break;
+
+       case CALENDAR_RECURRENCE_YEARLY:
+               if (event->bymonth && strlen(event->bymonth) > 0) {
+                       break;
+               }
+               else if (event->byyearday && strlen(event->byyearday) > 0) {
+                       break;
+               }
+               else if (event->byweekno && strlen(event->byweekno) > 0) {
+                       break;
+               }
+
+               event->bymonth = _cal_time_extract_by(event->system_type, event->start_tzid, event->wkst,
+                               &event->start, CAL_MONTH);
+               event->bymonthday = _cal_time_extract_by(event->system_type, event->start_tzid, event->wkst,
+                               &event->start, CAL_DATE);
+               DBG("Not enough field in yearly, so set bymonth[%s] bymonthday[%s]",
+                               event->bymonth, event->bymonthday);
+               break;
+
+       default:
+               break;
+       }
+}
+
+void _cal_db_rrule_get_rrule_from_event(calendar_record_h event, cal_rrule_s **rrule)
+{
+       cal_rrule_s *_rrule;
+       cal_event_s *_event;
+
+       retm_if(event == NULL, "Invalid argument: rrule is NULL");
+       _event = (cal_event_s *)event;
+       if (_event->freq == CALENDAR_RECURRENCE_NONE) {
+               return;
+       }
+
+       _rrule = calloc(1, sizeof(cal_rrule_s));
+       retm_if(_rrule == NULL, "Failed to calloc");
+
+       _rrule->freq = _event->freq;
+
+       _rrule->range_type = _event->range_type;
+       switch (_rrule->range_type) {
+       case CALENDAR_RANGE_UNTIL:
+               _rrule->until = _event->until;
+               break;
+       case CALENDAR_RANGE_COUNT:
+               break;
+       case CALENDAR_RANGE_NONE:
+               break;
+       }
+
+       _rrule->count = _event->count;
+       _rrule->interval = _event->interval;
+       _rrule->bysecond = _event->bysecond;
+       _rrule->byminute = _event->byminute;
+       _rrule->byhour = _event->byhour;
+       _rrule->byday = _event->byday;
+       _rrule->bymonthday = _event->bymonthday;
+       _rrule->byyearday = _event->byyearday;
+       _rrule->byweekno = _event->byweekno;
+       _rrule->bymonth = _event->bymonth;
+       _rrule->bysetpos = _event->bysetpos;
+       _rrule->wkst = _event->wkst;
+
+       *rrule = _rrule;
+}
+
+void _cal_db_rrule_set_rrule_to_event(cal_rrule_s *rrule, calendar_record_h event)
+{
+       cal_event_s *_event;
+
+       retm_if(rrule == NULL, "Invalid argument: rrule is NULL");
+       retm_if(event == NULL, "Invalid argument: rrule is NULL");
+
+       _event = (cal_event_s *)event;
+
+       _event->freq = rrule->freq;
+       _event->range_type = rrule->range_type;
+       _event->until = rrule->until;
+       _event->count = rrule->count;
+       _event->interval = rrule->interval;
+       _event->bysecond = rrule->bysecond;
+       _event->byminute = rrule->byminute;
+       _event->byhour = rrule->byhour;
+       _event->byday = rrule->byday;
+       _event->bymonthday = rrule->bymonthday;
+       _event->byyearday = rrule->byyearday;
+       _event->byweekno = rrule->byweekno;
+       _event->bymonth = rrule->bymonth;
+       _event->bysetpos = rrule->bysetpos;
+       _event->wkst = rrule->wkst;
+}
+
+void _cal_db_rrule_set_rrule_to_todo(cal_rrule_s *rrule, calendar_record_h todo)
+{
+       cal_todo_s *_todo;
+
+       retm_if(rrule == NULL, "Invalid argument: rrule is NULL");
+       retm_if(todo == NULL, "Invalid argument: todo is NULL");
+
+       _todo = (cal_todo_s *)todo;
+
+       _todo->freq = rrule->freq;
+       _todo->range_type = rrule->range_type;
+       _todo->until = rrule->until;
+       _todo->count = rrule->count;
+       _todo->interval = rrule->interval;
+       _todo->bysecond = rrule->bysecond;
+       _todo->byminute = rrule->byminute;
+       _todo->byhour = rrule->byhour;
+       _todo->byday = rrule->byday;
+       _todo->bymonthday = rrule->bymonthday;
+       _todo->byyearday = rrule->byyearday;
+       _todo->byweekno = rrule->byweekno;
+       _todo->bymonth = rrule->bymonth;
+       _todo->bysetpos = rrule->bysetpos;
+       _todo->wkst = rrule->wkst;
+}
+
+void _cal_db_rrule_get_rrule_from_todo(calendar_record_h todo, cal_rrule_s **rrule)
+{
+       cal_rrule_s *_rrule;
+       cal_todo_s *_todo;
+
+       retm_if(todo == NULL, "Invalid argument: rrule is NULL");
+
+       _todo = (cal_todo_s *)todo;
+
+       _rrule = calloc(1, sizeof(cal_rrule_s));
+       retm_if(_rrule == NULL, "Failed to calloc");
+
+       _rrule->freq = _todo->freq;
+       _rrule->range_type = _todo->range_type;
+       _rrule->until = _todo->until;
+       _rrule->count = _todo->count;
+       _rrule->interval = _todo->interval;
+       _rrule->bysecond = _todo->bysecond;
+       _rrule->byminute = _todo->byminute;
+       _rrule->byhour = _todo->byhour;
+       _rrule->byday = _todo->byday;
+       _rrule->bymonthday = _todo->bymonthday;
+       _rrule->byyearday = _todo->byyearday;
+       _rrule->byweekno = _todo->byweekno;
+       _rrule->bymonth = _todo->bymonth;
+       _rrule->bysetpos = _todo->bysetpos;
+       _rrule->wkst = _todo->wkst;
+
+       *rrule = _rrule;
+}
+
+int __cal_db_rrule_insert_record(int id, cal_rrule_s *rrule)
+{
+       int rrule_id;
+       int index;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char until_datetime[32] = {0};
+       sqlite3_stmt *stmt = NULL;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       retvm_if(rrule == NULL, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid argument: rrule is NULL");
+
+       snprintf(query, sizeof(query),
+                       "INSERT INTO %s ( "
+                       "event_id, freq, range_type, "
+                       "until_type, until_utime, until_datetime, "
+                       "count, interval, "
+                       "bysecond, byminute, byhour, byday, "
+                       "bymonthday, byyearday, byweekno, bymonth, "
+                       "bysetpos, wkst "
+                       ") VALUES ( "
+                       "%d, %d, %d, "
+                       "%d, %lld, ?, "
+                       "%d, %d, "
+                       "?, ?, ?, ?, "
+                       "?, ?, ?, ?, "
+                       "?, %d "
+                       ") ",
+                       CAL_TABLE_RRULE,
+                       id, rrule->freq, rrule->range_type,
+                       rrule->until.type, rrule->until.time.utime,
+                       rrule->count, rrule->interval,
+                       rrule->wkst);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt) {
+               DBG("query[%s]", query);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       index = 1;
+
+       if (CALENDAR_TIME_LOCALTIME == rrule->until.type) {
+               snprintf(until_datetime, sizeof(until_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               rrule->until.time.date.year,
+                               rrule->until.time.date.month,
+                               rrule->until.time.date.mday,
+                               rrule->until.time.date.hour,
+                               rrule->until.time.date.minute,
+                               rrule->until.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, index, until_datetime);
+       }
+       index++;
+
+       if (rrule->bysecond)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->bysecond);
+       index++;
+
+       if (rrule->byminute)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->byminute);
+       index++;
+
+       if (rrule->byhour)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->byhour);
+       index++;
+
+       if (rrule->byday)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->byday);
+       index++;
+
+       if (rrule->bymonthday)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->bymonthday);
+       index++;
+
+       if (rrule->byyearday)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->byyearday);
+       index++;
+
+       if (rrule->byweekno)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->byweekno);
+       index++;
+
+       if (rrule->bymonth)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->bymonth);
+       index++;
+
+       if (rrule->bysetpos)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->bysetpos);
+       index++;
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       sqlite3_finalize(stmt);
+       if (CAL_DB_OK != dbret) {
+               ERR("_cal_db_util_stmt_step() Failed(%d)", dbret);
+               switch (dbret) {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       rrule_id = _cal_db_util_last_insert_id();
+       DBG("rrule_id(%d)", rrule_id);
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_rrule_get_rrule(int id, cal_rrule_s **rrule)
+{
+       char query[CAL_DB_SQL_MAX_LEN];
+       int index;
+       sqlite3_stmt *stmt = NULL;
+       cal_rrule_s *_rrule = NULL;
+       const unsigned char *temp;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       snprintf(query, sizeof(query),
+                       "SELECT * FROM %s "
+                       "WHERE event_id = %d ",
+                       CAL_TABLE_RRULE,
+                       id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt) {
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       if (CAL_DB_DONE == dbret) {
+               DBG("No event: id(%d)", id);
+               sqlite3_finalize(stmt);
+               return CALENDAR_ERROR_DB_RECORD_NOT_FOUND;
+       }
+       else if (CAL_DB_ROW != dbret) {
+               ERR("query[%s]", query);
+               ERR("Failed to step stmt(%d)", dbret);
+               sqlite3_finalize(stmt);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       _rrule = calloc(1, sizeof(cal_rrule_s));
+       retvm_if(_rrule == NULL, CALENDAR_ERROR_OUT_OF_MEMORY,
+                       "Failed to calloc");
+
+       index = 0;
+       sqlite3_column_int(stmt, index++); // id
+       sqlite3_column_int(stmt, index++); // event_id
+       _rrule->freq = sqlite3_column_int(stmt, index++);
+
+       //rrule->_rrule_id = 1;
+       _rrule->range_type = sqlite3_column_int(stmt, index++);
+       _rrule->until.type = sqlite3_column_int(stmt, index++);
+       _rrule->until.time.utime = sqlite3_column_int64(stmt, index++);
+
+       temp = sqlite3_column_text(stmt, index++);
+       if (CALENDAR_TIME_LOCALTIME == _rrule->until.type) {
+               sscanf((const char *)temp, CAL_FORMAT_LOCAL_DATETIME,
+                               &_rrule->until.time.date.year,
+                               &_rrule->until.time.date.month,
+                               &_rrule->until.time.date.mday,
+                               &_rrule->until.time.date.hour,
+                               &_rrule->until.time.date.minute,
+                               &_rrule->until.time.date.second);
+       }
+
+       _rrule->count = sqlite3_column_int(stmt, index++);
+       _rrule->interval = sqlite3_column_int(stmt, index++);
+
+       temp = sqlite3_column_text(stmt, index++);
+       _rrule->bysecond = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, index++);
+       _rrule->byminute = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, index++);
+       _rrule->byhour = SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, index++);
+       _rrule->byday= SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, index++);
+       _rrule->bymonthday= SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, index++);
+       _rrule->byyearday= SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, index++);
+       _rrule->byweekno= SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, index++);
+       _rrule->bymonth= SAFE_STRDUP(temp);
+
+       temp = sqlite3_column_text(stmt, index++);
+       _rrule->bysetpos = SAFE_STRDUP(temp);
+
+       _rrule->wkst = sqlite3_column_int(stmt, index++);
+
+       sqlite3_finalize(stmt);
+
+       *rrule = _rrule;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_rrule_delete_record(int id)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       snprintf(query, sizeof(query),
+                       "DELETE FROM %s WHERE event_id = %d ",
+                       CAL_TABLE_RRULE, id);
+
+       dbret = _cal_db_util_query_exec(query);
+       if(CAL_DB_DONE != dbret) {
+               ERR("_cal_db_util_query_exec() Failed");
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_rrule_has_record(int id, int *has_record)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       int count = 0;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+
+       snprintf(query, sizeof(query),
+                       "SELECT count(*) FROM %s WHERE event_id = %d ",
+                       CAL_TABLE_RRULE, id);
+
+       ret = _cal_db_util_query_get_first_int_result(query, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               return ret;
+       }
+
+       *has_record = count > 0 ? 1 : 0;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_db_rrule_update_record(int id, cal_rrule_s *rrule)
+{
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       char until_datetime[32] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       sqlite3_stmt *stmt = NULL;
+
+       snprintf(query, sizeof(query),
+                       "UPDATE %s SET "
+                       "freq = %d, "
+                       "range_type = %d, "
+                       "until_type = %d, "
+                       "until_utime = %lld, "
+                       "until_datetime = ?, "
+                       "count = %d, "
+                       "interval = %d, "
+                       "bysecond = ?, "
+                       "byminute= ?, "
+                       "byhour = ?, "
+                       "byday = ?, "
+                       "bymonthday = ?, "
+                       "byyearday = ?, "
+                       "byweekno = ?, "
+                       "bymonth = ?, "
+                       "bysetpos = ?, "
+                       "wkst = %d "
+                       "WHERE event_id = %d ",
+                       CAL_TABLE_RRULE,
+                       rrule->freq,
+                       rrule->range_type,
+                       rrule->until.type,
+                       rrule->until.time.utime,
+                       rrule->count,
+                       rrule->interval,
+                       rrule->wkst,
+                       id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt) {
+               DBG("query[%s]", query);
+               ERR("_cal_db_util_query_prepare() Failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       int index = 1;
+       if (CALENDAR_TIME_LOCALTIME == rrule->until.type) {
+               snprintf(until_datetime, sizeof(until_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                               rrule->until.time.date.year,
+                               rrule->until.time.date.month,
+                               rrule->until.time.date.mday,
+                               rrule->until.time.date.hour,
+                               rrule->until.time.date.minute,
+                               rrule->until.time.date.second);
+               _cal_db_util_stmt_bind_text(stmt, index, until_datetime);
+       }
+       index++;
+
+       if (rrule->bysecond)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->bysecond);
+       index++;
+
+       if (rrule->byminute)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->byminute);
+       index++;
+
+       if (rrule->byhour)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->byhour);
+       index++;
+
+       if (rrule->byday)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->byday);
+       index++;
+
+       if (rrule->bymonthday)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->bymonthday);
+       index++;
+
+       if (rrule->byyearday)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->byyearday);
+       index++;
+
+       if (rrule->byweekno)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->byweekno);
+       index++;
+
+       if (rrule->bymonth)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->bymonth);
+       index++;
+
+       if (rrule->bysetpos)
+               _cal_db_util_stmt_bind_text(stmt, index, rrule->bysetpos);
+       index++;
+
+       dbret = _cal_db_util_stmt_step(stmt);
+       sqlite3_finalize(stmt);
+       if (CAL_DB_DONE != dbret) {
+               ERR("sqlite3_step() Failed(%d)", dbret);
+               switch (dbret) {
+               case CAL_DB_ERROR_NO_SPACE:
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_rrule_insert_record(int id, cal_rrule_s *rrule)
+{
+       retvm_if(rrule == NULL, CALENDAR_ERROR_INVALID_PARAMETER,
+                       "Invalid argument: rrule is NULL");
+
+       if (rrule->freq == CALENDAR_RECURRENCE_NONE) {
+       }
+       else {
+               __cal_db_rrule_insert_record(id, rrule);
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_rrule_update_record(int id, cal_rrule_s *rrule)
+{
+       int has_record = 0;
+
+       if (NULL == rrule || rrule->freq == CALENDAR_RECURRENCE_NONE) {
+               DBG("freq is NONE");
+               __cal_db_rrule_delete_record(id);
+               return CALENDAR_ERROR_NONE;
+       }
+       else {
+               __cal_db_rrule_has_record(id, &has_record);
+               if (has_record) {
+                       __cal_db_rrule_update_record(id, rrule);
+               }
+               else {
+                       __cal_db_rrule_insert_record(id, rrule);
+               }
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
diff --git a/native/cal_db_rrule.h b/native/cal_db_rrule.h
new file mode 100644 (file)
index 0000000..a52c9ed
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_DB_RRULE_H__
+#define __CALENDAR_SVC_DB_RRULE_H__
+
+void _cal_db_rrule_set_default(calendar_record_h event);
+int _cal_db_rrule_insert_record(int id, cal_rrule_s *rrule);
+int _cal_db_rrule_update_record(int id, cal_rrule_s *rrule);
+int _cal_db_rrule_get_rrule(int id, cal_rrule_s **rrule);
+void _cal_db_rrule_get_rrule_from_event(calendar_record_h event, cal_rrule_s **rrule);
+void _cal_db_rrule_set_rrule_to_event(cal_rrule_s *rrule, calendar_record_h event);
+void _cal_db_rrule_get_rrule_from_todo(calendar_record_h todo, cal_rrule_s **rrule);
+void _cal_db_rrule_set_rrule_to_todo(cal_rrule_s *rrule, calendar_record_h todo);
+
+#endif  //__CALENDAR_SVC_DB_RRULE_H__
diff --git a/native/cal_db_util.c b/native/cal_db_util.c
new file mode 100644 (file)
index 0000000..7369a4e
--- /dev/null
@@ -0,0 +1,456 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <db-util.h>
+#include <sys/time.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_db.h"
+
+#include "cal_db_util.h"
+
+static TLS sqlite3 *calendar_db_handle;
+static TLS int transaction_cnt = 0;
+static TLS int transaction_ver = 0;
+static TLS bool version_up = false;
+
+static TLS bool event_change=false;
+static TLS bool todo_change=false;
+static TLS bool calendar_change=false;
+
+static inline void __cal_db_util_notify_event_change(void)
+{
+       int fd = open(CAL_NOTI_EVENT_CHANGED, O_TRUNC | O_RDWR);
+       if (0 <= fd) {
+               close(fd);
+               event_change = false;
+       }
+}
+
+static inline void __cal_db_util_notify_todo_change(void)
+{
+       int fd = open(CAL_NOTI_TODO_CHANGED, O_TRUNC | O_RDWR);
+       if (0 <= fd) {
+               close(fd);
+               todo_change = false;
+       }
+}
+
+static inline void __cal_db_util_notify_calendar_change(void)
+{
+       int fd = open(CAL_NOTI_CALENDAR_CHANGED, O_TRUNC | O_RDWR);
+       if (0 <= fd) {
+               close(fd);
+               calendar_change = false;
+       }
+}
+
+static inline void __cal_db_util_cancel_changes(void)
+{
+       event_change = false;
+       calendar_change = false;
+       todo_change = false;
+}
+
+int _cal_db_util_notify(cal_noti_type_e type)
+{
+       if (0 < transaction_cnt) {
+               switch (type) {
+               case CAL_NOTI_TYPE_EVENT:
+                       event_change = true;
+                       break;
+               case CAL_NOTI_TYPE_TODO:
+                       todo_change = true;
+                       break;
+               case CAL_NOTI_TYPE_CALENDAR:
+                       calendar_change = true;
+                       break;
+               default:
+                       ERR("The type(%d) is not supported", type);
+                       return CALENDAR_ERROR_INVALID_PARAMETER;
+               }
+               return CALENDAR_ERROR_NONE;
+       }
+
+       switch(type) {
+       case CAL_NOTI_TYPE_EVENT:
+               __cal_db_util_notify_event_change();
+               break;
+       case CAL_NOTI_TYPE_TODO:
+               __cal_db_util_notify_todo_change();
+               break;
+       case CAL_NOTI_TYPE_CALENDAR:
+               __cal_db_util_notify_calendar_change();
+               break;
+       default:
+               ERR("The type(%d) is not supported", type);
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_util_open(void)
+{
+       int ret = 0;
+
+       if (!calendar_db_handle) {
+               ret = db_util_open(CAL_DB_PATH, &calendar_db_handle, 0);
+               retvm_if(SQLITE_OK != ret, CALENDAR_ERROR_DB_FAILED,
+                               "db_util_open() Failed(%d).", ret);
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_util_close(void)
+{
+       int ret = 0;
+
+       if (calendar_db_handle) {
+               ret = db_util_close(calendar_db_handle);
+               warn_if(SQLITE_OK != ret, "db_util_close() Failed(%d)", ret);
+               calendar_db_handle = NULL;
+               CAL_DBG("The database disconnected really.");
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_util_last_insert_id(void)
+{
+       return sqlite3_last_insert_rowid(calendar_db_handle);
+}
+
+#define __CAL_QUERY_RETRY_TIME 2
+
+int _cal_db_util_query_get_first_int_result(const char *query, GSList *bind_text, int *result)
+{
+       int ret;
+       int index;
+       char *text = NULL;
+       struct timeval from, now, diff;
+       bool retry = false;
+       sqlite3_stmt *stmt = NULL;
+       retvm_if(NULL == calendar_db_handle, CALENDAR_ERROR_DB_FAILED, "Database is not opended");
+
+       gettimeofday(&from, NULL);
+       do
+       {
+               ret = sqlite3_prepare_v2(calendar_db_handle, query, strlen(query), &stmt, NULL);
+               if (SQLITE_BUSY == ret || SQLITE_LOCKED == ret)
+               {
+                       ERR("sqlite3_prepare_v2(%s) failed(%s).", query, sqlite3_errmsg(calendar_db_handle));
+                       gettimeofday(&now, NULL);
+                       timersub(&now, &from, &diff);
+                       retry = (diff.tv_sec < __CAL_QUERY_RETRY_TIME) ? true : false;
+                       if (retry)
+                       {
+                               usleep(50 * 1000); // 50ms
+                       }
+               }
+               else
+               {
+                       retry = false;
+               }
+       } while(retry);
+
+       if (SQLITE_OK != ret)
+       {
+               ERR("sqlite3_prepare_v2(%s) failed(%s).", query, sqlite3_errmsg(calendar_db_handle));
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       if (bind_text)
+       {
+               for (index = 0; g_slist_nth(bind_text, index); index++)
+               {
+                       text = (char *)g_slist_nth_data(bind_text, index);
+                       if (text)
+                       {
+                               _cal_db_util_stmt_bind_text(stmt, index + 1, text);
+                       }
+               }
+       }
+
+       retry = false;
+       gettimeofday(&from, NULL);
+       do
+       {
+               ret = sqlite3_step(stmt);
+               if (SQLITE_ROW != ret)
+               {
+                       if (SQLITE_DONE == ret)
+                       {
+                               sqlite3_finalize(stmt);
+                               return CALENDAR_ERROR_DB_RECORD_NOT_FOUND;
+                       }
+                       else if (SQLITE_BUSY == ret || SQLITE_LOCKED == ret)
+                       {
+                               ERR("sqlite3_step fail(%d, %s)", ret, sqlite3_errmsg(calendar_db_handle));
+                               gettimeofday(&now, NULL);
+                               timersub(&now, &from, &diff);
+                               retry = (diff.tv_sec < __CAL_QUERY_RETRY_TIME) ? true : false;
+                               if (retry)
+                               {
+                                       usleep(50 * 1000); // 50ms
+                               }
+                       }
+                       else
+                       {
+                               ERR("sqlite3_step() failed(%d, %s).", ret, sqlite3_errmsg(calendar_db_handle));
+                               retry = false;
+                       }
+               }
+               else
+                       if (result) *result = sqlite3_column_int(stmt, 0);
+       } while(retry);
+
+       sqlite3_finalize(stmt);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+cal_db_util_error_e _cal_db_util_query_exec(char *query)
+{
+       int ret;
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == calendar_db_handle, CALENDAR_ERROR_DB_FAILED, "Database is not opended");
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if(NULL == stmt, CAL_DB_ERROR_FAIL, "_cal_db_util_query_prepare() Failed");
+
+       ret = _cal_db_util_stmt_step(stmt);
+
+       if (CAL_DB_DONE != ret) {
+               sqlite3_finalize(stmt);
+               ERR("_cal_db_util_stmt_step() Failed(%d)", ret);
+               SEC_ERR("[ %s ]", query);
+               return ret;
+       }
+
+       sqlite3_finalize(stmt);
+       return CAL_DB_OK;
+}
+
+sqlite3_stmt* _cal_db_util_query_prepare(char *query)
+{
+       int ret = -1;
+       struct timeval from, now, diff;
+       bool retry = false;
+       sqlite3_stmt *stmt = NULL;
+
+       retvm_if(NULL == query, NULL, "Invalid query");
+       retvm_if(NULL == calendar_db_handle, NULL, "Database is not opended");
+       //CALS_DBG("prepare query : %s", query);
+
+       gettimeofday(&from, NULL);
+       do
+       {
+               ret = sqlite3_prepare_v2(calendar_db_handle, query, strlen(query), &stmt, NULL);
+               if (SQLITE_BUSY == ret || SQLITE_LOCKED == ret)
+               {
+                       gettimeofday(&now, NULL);
+                       timersub(&now, &from, &diff);
+                       retry = (diff.tv_sec < __CAL_QUERY_RETRY_TIME) ? true : false;
+                       if (retry)
+                       {
+                               usleep(50 * 1000); // 50ms
+                       }
+               }
+               else
+               {
+                       retry = false;
+               }
+       } while(retry);
+
+       return stmt;
+}
+
+cal_db_util_error_e _cal_db_util_stmt_step(sqlite3_stmt *stmt)
+{
+       int ret;
+       struct timeval from, now, diff;
+       bool retry = false;
+
+       gettimeofday(&from, NULL);
+       do
+       {
+               ret = sqlite3_step(stmt);
+               if (SQLITE_BUSY == ret || SQLITE_LOCKED == ret)
+               {
+                       gettimeofday(&now, NULL);
+                       timersub(&now, &from, &diff);
+                       retry = (diff.tv_sec < __CAL_QUERY_RETRY_TIME) ? true : false;
+                       if (retry)
+                       {
+                               usleep(50 * 1000); // 50ms
+                       }
+               }
+               else
+               {
+                       retry = false;
+               }
+       } while(retry);
+
+       switch (ret)
+       {
+       case SQLITE_BUSY:
+       case SQLITE_LOCKED:
+               ret = CAL_DB_ERROR_LOCKED;
+               break;
+       case SQLITE_IOERR:
+               ret = CAL_DB_ERROR_IOERR;
+               break;
+       case SQLITE_FULL:
+               ret = CAL_DB_ERROR_NO_SPACE;
+               break;
+       case SQLITE_CONSTRAINT:
+               ret = CAL_DB_ERROR_ALREADY_EXIST;
+               break;
+       case SQLITE_ROW:
+               ret = CAL_DB_ROW;
+               break;
+       case SQLITE_DONE:
+               ret = CAL_DB_DONE;
+               break;
+       default:
+               ERR("sqlite3_step() Failed(%d)", ret);
+               ret = CAL_DB_ERROR_FAIL;
+               break;
+       }
+       return ret;
+}
+
+#define CAL_COMMIT_TRY_MAX 500000
+int _cal_db_util_begin_trans(void)
+{
+       if(transaction_cnt <= 0)
+       {
+               int ret, progress;
+
+               progress = 100000;
+               ret = _cal_db_util_query_exec("BEGIN IMMEDIATE TRANSACTION");
+               // !! check error code
+               while(CAL_DB_OK != ret && progress < CAL_COMMIT_TRY_MAX) {
+                       usleep(progress);
+                       ret = _cal_db_util_query_exec("BEGIN IMMEDIATE TRANSACTION");
+                       progress *= 2;
+               }
+               retvm_if(CAL_DB_OK != ret, ret, "cal_query_exec() Failed(%d)", ret);
+
+               transaction_cnt = 0;
+               const char *query = "SELECT ver FROM "CAL_TABLE_VERSION;
+               ret = _cal_db_util_query_get_first_int_result(query, NULL, &transaction_ver);
+               if (CALENDAR_ERROR_NONE != ret)
+               {
+                       ERR("_cal_db_util_query_get_first_int_result() failed");
+                       return ret;
+               }
+               version_up = false;
+       }
+       transaction_cnt++;
+       CAL_DBG("transaction_cnt : %d", transaction_cnt);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_util_end_trans(bool is_success)
+{
+       int ret;
+       int progress = 0;
+       char query[CAL_DB_SQL_MIN_LEN];
+
+       transaction_cnt--;
+
+       if (0 != transaction_cnt) {
+               CAL_DBG("transaction_cnt : %d", transaction_cnt);
+               return CALENDAR_ERROR_NONE;
+       }
+
+       if (false == is_success) {
+               __cal_db_util_cancel_changes();
+               ret = _cal_db_util_query_exec("ROLLBACK TRANSACTION");
+               return CALENDAR_ERROR_NONE;
+       }
+
+       if (version_up) {
+               transaction_ver++;
+               snprintf(query, sizeof(query), "UPDATE %s SET ver = %d",
+                               CAL_TABLE_VERSION, transaction_ver);
+               ret = _cal_db_util_query_exec(query);
+               warn_if(CAL_DB_OK != ret, "cal_query_exec(version up) Failed(%d).", ret);
+       }
+
+       INFO("start commit");
+       progress = 100000;
+       ret = _cal_db_util_query_exec("COMMIT TRANSACTION");
+       // !! check error code
+       while (CAL_DB_OK != ret && progress < CAL_COMMIT_TRY_MAX) {
+               usleep(progress);
+               ret = _cal_db_util_query_exec("COMMIT TRANSACTION");
+               progress *= 2;
+       }
+       INFO("%s", (CAL_DB_OK == ret)?"commit": "rollback");
+
+       if (CAL_DB_OK != ret) {
+               int tmp_ret;
+               ERR("cal_query_exec() Failed(%d)", ret);
+               __cal_db_util_cancel_changes();
+               tmp_ret = _cal_db_util_query_exec("ROLLBACK TRANSACTION");
+               warn_if(CAL_DB_OK != tmp_ret, "cal_query_exec(ROLLBACK) Failed(%d).", tmp_ret);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       if (event_change) __cal_db_util_notify_event_change();
+       if (todo_change) __cal_db_util_notify_todo_change();
+       if (calendar_change) __cal_db_util_notify_calendar_change();
+
+       CAL_DBG("transaction_ver = %d",transaction_ver);
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_db_util_get_next_ver(void)
+{
+       int count = 0;
+       int ret;
+       const char *query;
+
+       if (0 < transaction_cnt) {
+               version_up = true;
+               return transaction_ver + 1;
+       }
+
+       query = "SELECT ver FROM "CAL_TABLE_VERSION;
+
+       ret = _cal_db_util_query_get_first_int_result(query, NULL, &count);
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               return ret;
+       }
+       return (1 + count);
+}
+
+int _cal_db_util_get_transaction_ver(void)
+{
+       return transaction_ver;
+}
diff --git a/native/cal_db_util.h b/native/cal_db_util.h
new file mode 100644 (file)
index 0000000..d9bcc27
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_DB_UTIL_H__
+#define __CALENDAR_SVC_DB_UTIL_H__
+
+#include <sqlite3.h>
+#include <string.h>
+
+typedef enum
+{
+       CAL_DB_ERROR_FAIL   = -1,
+       CAL_DB_ERROR_LOCKED = -204,         //SQLITE_BUSY, SQLITE_LOCKED
+       CAL_DB_ERROR_IOERR = -10,           //SQLITE_IOERR              /* Some kind of disk I/O error occurred */
+       CAL_DB_ERROR_NO_SPACE = -11,        //SQLITE_FULL               /* Insertion failed because database is full */
+       CAL_DB_ERROR_ALREADY_EXIST = -7,    //SQLITE_CONSTRAINT         /* Abort due to constraint violation */
+       CAL_DB_ROW = 1,                     //SQLITE_ROW    CAL_TRUE    /* sqlite3_step() has another row ready */
+       CAL_DB_DONE = 0,                    //SQLITE_DONE   CAL_SUCCESS /* sqlite3_step() has finished executing */
+       CAL_DB_OK = 0,                      //SQLITE_OK                 /* Successful result */
+} cal_db_util_error_e;
+
+int _cal_db_util_notify(cal_noti_type_e type);
+
+int _cal_db_util_open(void);
+int _cal_db_util_close(void);
+
+int _cal_db_util_last_insert_id(void);
+int _cal_db_util_query_get_first_int_result(const char *query, GSList *bind_text, int *result);
+
+cal_db_util_error_e _cal_db_util_query_exec(char *query);
+sqlite3_stmt* _cal_db_util_query_prepare(char *query);
+cal_db_util_error_e _cal_db_util_stmt_step(sqlite3_stmt *stmt);
+
+static inline int _cal_db_util_stmt_bind_text(sqlite3_stmt *stmt, int pos, const char *str) {
+       return sqlite3_bind_text(stmt, pos, str, str ? strlen(str) : 0, SQLITE_STATIC);
+}
+
+int _cal_db_util_begin_trans(void);
+int _cal_db_util_end_trans(bool is_success);
+
+int _cal_db_util_get_next_ver(void);
+
+int _cal_db_util_get_transaction_ver(void);
+
+#endif  //__CALENDAR_SVC_DB_UTIL_H__
diff --git a/native/cal_reminder.c b/native/cal_reminder.c
new file mode 100644 (file)
index 0000000..4afd577
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include "calendar_reminder.h"
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_view.h"
+#include "cal_time.h"
+#include "cal_record.h"
+#include "cal_access_control.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+
+API int calendar_reminder_add_cb(calendar_reminder_cb callback, void *user_data)
+{
+       ERR("This API[%s] is not valid in native library.", __func__);
+       ERR("If you want to use this API, please use in client library.");
+       return CALENDAR_ERROR_NOT_PERMITTED;
+}
+
+API int calendar_reminder_remove_cb(calendar_reminder_cb callback, void *user_data)
+{
+       ERR("This API[%s] is not valid in native library.", __func__);
+       ERR("If you want to use this API, please use in client library.");
+       return CALENDAR_ERROR_NOT_PERMITTED;
+}
+
diff --git a/native/cal_service.h b/native/cal_service.h
new file mode 100644 (file)
index 0000000..4f3c0ac
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CALENDAR_SVC_SERVICE_H__
+#define __CALENDAR_SVC_SERVICE_H__
+
+void _cal_calendar_internal_disconnect(void);
+
+#endif // __CALENDAR_SVC_SERVICE_H__
diff --git a/packaging/calendar-service.spec b/packaging/calendar-service.spec
new file mode 100644 (file)
index 0000000..1d843e4
--- /dev/null
@@ -0,0 +1,102 @@
+Name:       calendar-service
+Summary:    DB library for calendar
+Version:    0.1.126
+Release:    1
+Group:      System/Libraries
+License:    Apache-2.0
+Source0:    %{name}-%{version}.tar.gz
+Source1:    calendar-serviced.service
+Source2:    calendar-serviced.socket
+Requires(post): /sbin/ldconfig
+Requires(post): /usr/bin/sqlite3, /bin/chown
+Requires(post): contacts-service2
+Requires(postun): /sbin/ldconfig
+Requires: sys-assert
+
+BuildRequires: cmake
+BuildRequires: pkgconfig(db-util)
+BuildRequires: pkgconfig(sqlite3)
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(vconf)
+BuildRequires: pkgconfig(alarm-service)
+BuildRequires: pkgconfig(icu-i18n)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(contacts-service2)
+BuildRequires: pkgconfig(pims-ipc)
+BuildRequires: pkgconfig(security-server)
+BuildRequires: pkgconfig(capi-appfw-package-manager)
+BuildRequires: pkgconfig(accounts-svc)
+BuildRequires: pkgconfig(capi-appfw-application)
+
+%description
+DB library for calendar
+
+%package devel
+Summary:    DB library for calendar
+Group:      Development/Libraries
+Requires:   %{name} = %{version}-%{release}
+Requires:   pkgconfig(alarm-service)
+
+%description devel
+DB library for calendar (developement files)
+
+%prep
+%setup -q
+
+
+%build
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
+export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
+
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+
+make %{?jobs:-j%jobs}
+
+%install
+%make_install
+
+mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants
+install -m 0644 %SOURCE1 %{buildroot}%{_libdir}/systemd/system/calendar-serviced.service
+ln -s ../calendar-serviced.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/calendar-serviced.service
+
+mkdir -p %{buildroot}%{_libdir}/systemd/system/sockets.target.wants
+install -m 0644 %SOURCE2 %{buildroot}%{_libdir}/systemd/system/calendar-serviced.socket
+ln -s ../calendar-serviced.socket %{buildroot}%{_libdir}/systemd/system/sockets.target.wants/calendar-serviced.socket
+
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE.APLv2 %{buildroot}/usr/share/license/%{name}
+
+%post
+/sbin/ldconfig
+mkdir -p /opt/usr/dbspace
+
+chown :5000 /opt/usr/dbspace/.calendar-svc.db
+chown :5000 /opt/usr/dbspace/.calendar-svc.db-journal
+chown :5000 /opt/usr/data/calendar-svc/.CALENDAR_SVC_*
+
+chmod 660 /opt/usr/dbspace/.calendar-svc.db
+chmod 660 /opt/usr/dbspace/.calendar-svc.db-journal
+chmod 660 /opt/usr/data/calendar-svc/.CALENDAR_SVC_*
+
+%postun -p /sbin/ldconfig
+
+%files
+%manifest calendar-service.manifest
+%defattr(-,root,root,-)
+%{_bindir}/calendar-serviced*
+%{_libdir}/libcalendar-service2.so.*
+/opt/usr/data/calendar-svc/.CALENDAR_SVC_*
+%config(noreplace) /opt/usr/dbspace/.calendar-svc.db*
+%{_libdir}/systemd/system/multi-user.target.wants/calendar-serviced.service
+%{_libdir}/systemd/system/calendar-serviced.service
+%{_libdir}/systemd/system/sockets.target.wants/calendar-serviced.socket
+%{_libdir}/systemd/system/calendar-serviced.socket
+/usr/share/license/%{name}
+
+%files devel
+%defattr(-,root,root,-)
+%{_includedir}/calendar-service2/*.h
+%{_libdir}/*.so
+%{_libdir}/pkgconfig/calendar-service2.pc
diff --git a/packaging/calendar-serviced.service b/packaging/calendar-serviced.service
new file mode 100644 (file)
index 0000000..d9e5ba4
--- /dev/null
@@ -0,0 +1,13 @@
+[Unit]
+Description=Calendar Service daemon
+After=tizen-runtime.target contacts-service.service
+Requires=tizen-runtime.target contacts-service.service
+
+[Service]
+Type=simple
+ExecStart=/usr/bin/calendar-serviced
+Restart=always
+RestartSec=1
+
+[Install]
+WantedBy=multi-user.target
diff --git a/packaging/calendar-serviced.socket b/packaging/calendar-serviced.socket
new file mode 100644 (file)
index 0000000..f73e704
--- /dev/null
@@ -0,0 +1,11 @@
+[Unit]
+Description=Calendar Service socket
+
+[Socket]
+ListenStream=/tmp/.cal_svc_ipc
+SmackLabelIPIn=calendar-service
+SmackLabelIPOut=calendar-service
+Service=calendar-serviced.service
+
+[Install]
+WantedBy=sockets.target
diff --git a/packaging/libslp-calendar.spec b/packaging/libslp-calendar.spec
deleted file mode 100644 (file)
index 367f2f6..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-Name:       libslp-calendar
-Summary:    DB library for calendar
-Version:    0.1.13
-Release:    41
-Group:      System/Libraries
-License:    Apache 2.0
-Source0:    %{name}-%{version}.tar.gz
-Requires(post): /sbin/ldconfig
-Requires(post): /usr/bin/sqlite3
-Requires(postun): /sbin/ldconfig
-
-BuildRequires: cmake
-BuildRequires: pkgconfig(db-util)
-BuildRequires: pkgconfig(sqlite3)
-BuildRequires: pkgconfig(glib-2.0)
-BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(vconf)
-BuildRequires: pkgconfig(alarm-service)
-BuildRequires: pkgconfig(icu-i18n)
-BuildRequires: pkgconfig(appsvc)
-
-%description
-DB library for calendar
-
-%package devel
-Summary:    DB library for calendar
-Group:      Development/Libraries
-Requires:   %{name} = %{version}-%{release}
-Requires:   pkgconfig(alarm-service)
-
-%description devel
-DB library for calendar (developement files)
-
-%prep
-%setup -q
-
-
-%build
-cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
-
-
-make %{?jobs:-j%jobs}
-
-%install
-%make_install
-
-
-%post
-/sbin/ldconfig
-mkdir -p /opt/dbspace
-if [ -f /opt/dbspace/.calendar-svc.db ]
-then
-        echo "calendar-svc.db exist"
-else
-               calendar-svc-initdb
-fi
-
-chown :6003 /opt/dbspace/.calendar-svc.db
-chown :6003 /opt/dbspace/.calendar-svc.db-journal
-chown :6003 /opt/data/calendar-svc/.CALENDAR_SVC_*
-
-chmod 660 /opt/dbspace/.calendar-svc.db
-chmod 660 /opt/dbspace/.calendar-svc.db-journal
-chmod 660 /opt/data/calendar-svc/.CALENDAR_SVC_*
-
-vconftool set -t int db/calendar/timezone_on_off 0 -g 6003
-vconftool set -t string db/calendar/timezone_path "Asia/Seoul" -g 6003
-
-%postun -p /sbin/ldconfig
-
-
-%files
-%defattr(-,root,root,-)
-%{_bindir}/calendar-svc-initdb
-%{_libdir}/libcalendar-service.so.*
-/opt/data/calendar-svc/.CALENDAR_SVC_CALENDAR_CHANGED
-/opt/data/calendar-svc/.CALENDAR_SVC_EVENT_CHANGED
-/opt/data/calendar-svc/.CALENDAR_SVC_TODO_CHANGED
-
-%files devel
-%defattr(-,root,root,-)
-%{_includedir}/calendar-svc/*.h
-%{_includedir}/calendar/*.h
-%{_libdir}/*.so
-%{_libdir}/pkgconfig/calendar.pc
-%{_libdir}/pkgconfig/calendar-service.pc
index 96aff0f..8f707a8 100755 (executable)
@@ -1,24 +1,6 @@
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
 LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
 
-SET(TARGET calendar-svc-initdb)
-
 EXECUTE_PROCESS(COMMAND ./generator.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
 
-FILE(GLOB SRCS *.c)
-
-pkg_check_modules(initdb_pkgs REQUIRED db-util dlog)
-
-UNSET(EXTRA_CFLAGS)
-FOREACH(flag ${initdb_pkgs_CFLAGS})
-       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-
-ADD_EXECUTABLE(${TARGET} ${SRCS})
-SET_TARGET_PROPERTIES(${TARGET} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS})
-TARGET_LINK_LIBRARIES(${TARGET} ${initdb_pkgs_LDFLAGS})
-
-INSTALL(TARGETS ${TARGET} DESTINATION bin)
+FILE(GLOB DB_FILES ${CMAKE_SOURCE_DIR}/schema/.calendar-svc.db*)
+INSTALL(FILES ${DB_FILES} DESTINATION /opt/usr/dbspace)
diff --git a/schema/db-gen/Makefile b/schema/db-gen/Makefile
new file mode 100755 (executable)
index 0000000..6fa00e1
--- /dev/null
@@ -0,0 +1,22 @@
+CC = gcc
+
+REQUIRED_PKG = db-util
+CFLAGS = -g -Wall #-fprofile-arcs -ftest-coverage
+LDFLAGS =
+ifdef REQUIRED_PKG
+       CFLAGS += `pkg-config --cflags $(REQUIRED_PKG)`
+       LDFLAGS += `pkg-config --libs $(REQUIRED_PKG)`
+endif
+
+SRCS = $(wildcard ../initdb.c)
+OBJECTS = $(SRCS:.c=.o)
+TARGETS = $(OBJECTS:.o=)
+
+all: $(TARGETS)
+
+% : %.o
+       $(CC) $(LDFLAGS) -o $@ $<
+
+clean:
+       rm -rf $(OBJECTS) $(TARGETS)
+
index 123460b..e900e5a 100755 (executable)
@@ -1,7 +1,7 @@
 #
 # Calendar Service
 #
-# Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+# Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -27,3 +27,10 @@ make
 ./schema-header-gen ../schema.sql > ../schema.h
 
 make clean
+
+# Make DB
+cd ../db-gen
+make
+../initdb ../
+
+make clean
index 6836a30..30c4257 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  * Calendar Service
  *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
index 0767003..aaa4caa 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  * Calendar Service
  *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <db-util.h>
 
 #include "schema.h"
-#include "cals-db-info.h"
-#include "cals-internal.h"
-#include "calendar-svc-errors.h"
 
+#define CALS_DB_NAME ".calendar-svc.db"
+#define CALS_DB_JOURNAL_NAME ".calendar-svc.db-journal"
+#define CALS_DB_PATH "/opt/usr/dbspace/"CALS_DB_NAME
+#define CALS_DB_JOURNAL_PATH "/opt/usr/dbspace/"CALS_DB_JOURNAL_NAME
 
-static inline int remake_db_file()
+// For Security
+#define CALS_SECURITY_FILE_GROUP 5000
+#define CALS_SECURITY_DEFAULT_PERMISSION 0660
+#define CALS_SECURITY_DIR_DEFAULT_PERMISSION 0770
+
+static inline int remake_db_file(char* db_path)
 {
        int ret, fd;
        char *errmsg;
        sqlite3 *db;
+       char db_file[256]={0,};
+       char db_journal_file[256]={0,};
+
+       if(db_path == NULL)
+       {
+           snprintf(db_file,sizeof(db_file),CALS_DB_PATH);
+           snprintf(db_journal_file,sizeof(db_journal_file),CALS_DB_JOURNAL_PATH);
+       }
+       else
+       {
+           snprintf(db_file,sizeof(db_file),"%s%s",db_path, CALS_DB_NAME);
+           snprintf(db_journal_file,sizeof(db_journal_file),"%s%s", db_path, CALS_DB_JOURNAL_NAME);
+       }
 
-       ret = db_util_open(CALS_DB_PATH, &db, 0);
-       retvm_if(SQLITE_OK != ret, CAL_ERR_DB_NOT_OPENED, "db_util_open() Failed(%d)", ret);
+       ret = db_util_open(db_file, &db, 0);
+
+       if (SQLITE_OK != ret)
+       {
+               printf("db_util_open() Failed(%d)\n", ret);
+               return -1;
+       }
 
        ret = sqlite3_exec(db, schema_query, NULL, 0, &errmsg);
        if (SQLITE_OK != ret) {
-               ERR("remake calendar DB file is Failed : %s", errmsg);
+               printf("remake calendar DB file is Failed : %s\n", errmsg);
                sqlite3_free(errmsg);
        }
 
        db_util_close(db);
 
-       fd = open(CALS_DB_PATH, O_CREAT | O_RDWR, 0660);
-       retvm_if(-1 == fd, CAL_ERR_FAIL, "open Failed");
+       fd = open(db_file, O_CREAT | O_RDWR, 0660);
+       if (-1 == fd)
+       {
+               printf("open Failed\n");
+               return -1;
+       }
 
-       fchown(fd, getuid(), CALS_SECURITY_FILE_GROUP);
+       ret = fchown(fd, getuid(), CALS_SECURITY_FILE_GROUP);
+       if (-1 == ret)
+       {
+               printf("Failed to fchown\n");
+               close(fd);
+               return -1;
+       }
        fchmod(fd, CALS_SECURITY_DEFAULT_PERMISSION);
        close(fd);
 
-       fd = open(CALS_DB_JOURNAL_PATH, O_CREAT | O_RDWR, 0660);
-       retvm_if(-1 == fd, CAL_ERR_FAIL, "open Failed");
+       fd = open(db_journal_file, O_CREAT | O_RDWR, 0660);
+
+       if (-1 == fd)
+       {
+               printf("open Failed\n");
+               return -1;
+       }
 
-       fchown(fd, getuid(), CALS_SECURITY_FILE_GROUP);
+       ret = fchown(fd, getuid(), CALS_SECURITY_FILE_GROUP);
+       if (-1 == ret)
+       {
+               printf("Failed to fchown\n");
+               close(fd);
+               return -1;
+       }
        fchmod(fd, CALS_SECURITY_DEFAULT_PERMISSION);
        close(fd);
 
-       return CAL_SUCCESS;
+       return 0;
 }
 
-static inline int check_db_file(void)
+static inline int check_db_file(char* db_path)
 {
-       int fd = open(CALS_DB_PATH, O_RDONLY);
-       retvm_if(-1 == fd, -1,
-                       "DB file(%s) is not exist", CALS_DB_PATH);
-
+    int fd = -1;
+
+    char db_file[256]={0,};
+    if(db_path == NULL)
+    {
+        snprintf(db_file,sizeof(db_file),CALS_DB_PATH);
+    }
+    else
+    {
+        snprintf(db_file,sizeof(db_file),"%s%s",db_path, CALS_DB_NAME);
+    }
+
+    fd = open(db_file, O_RDONLY);
+
+       if (-1 == fd)
+       {
+               printf("DB file(%s) is not exist\n", db_file);
+               return -1;
+       }
+       printf("DB file(%s) \n", db_file);
        close(fd);
-       return CAL_SUCCESS;
+       return 0;
 }
 
-static inline int check_schema(void)
+static inline int check_schema(char* db_path)
 {
-       if (check_db_file())
-               remake_db_file();
-
-       return CAL_SUCCESS;
+       if (check_db_file(db_path))
+               remake_db_file(db_path);
+       return 0;
 }
 
 int main(int argc, char **argv)
 {
-       return check_schema();
+    char *tmp = NULL;
+    if(argc > 1)
+    {
+        tmp = argv[1];
+    }
+       return check_schema(tmp);
 }
index c307b24..c45afbd 100755 (executable)
@@ -1,7 +1,7 @@
 --
 -- Calendar Service
 --
--- Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+-- Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
 --
 -- Licensed under the Apache License, Version 2.0 (the "License");
 -- you may not use this file except in compliance with the License.
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 --
+PRAGMA user_version = 105;
 
 CREATE TABLE schedule_table
 (
 id INTEGER PRIMARY KEY AUTOINCREMENT,
-account_id INTEGER,
 type INTEGER,
 summary TEXT,
 description TEXT,
 location TEXT,
 categories TEXT,
 exdate TEXT,
-missed INTEGER,
 task_status INTEGER,
 priority INTEGER,
-timezone INTEGER,
-file_id INTEGER,
+timezone INTEGER DEFAULT 0,
 contact_id INTEGER,
 busy_status INTEGER,
 sensitivity INTEGER,
 uid TEXT,
-calendar_type INTEGER,
 organizer_name TEXT,
 organizer_email TEXT,
 meeting_status INTEGER,
-gcal_id TEXT,
-updated TEXT,
-location_type INTEGER,
-location_summary TEXT,
-etag TEXT,
 calendar_id INTEGER,
-sync_status INTEGER,
-edit_uri TEXT,
-gevent_id TEXT,
-dst INTEGER,
-original_event_id INTEGER,
+original_event_id INTEGER DEFAULT -1,
 latitude DOUBLE,
 longitude DOUBLE,
 email_id INTEGER,
-availability INTEGER,
 created_time INTEGER,
 completed_time INTEGER,
 progress INTEGER,
@@ -62,29 +49,63 @@ created_ver INTEGER,
 is_deleted INTEGER DEFAULT 0,
 dtstart_type INTEGER,
 dtstart_utime INTEGER,
-dtstart_datetime TEXT,
+dtstart_datetime DATE,
 dtstart_tzid TEXT,
 dtend_type INTEGER,
 dtend_utime INTEGER,
-dtend_datetime TEXT,
+dtend_datetime DATE,
 dtend_tzid TEXT,
 last_mod INTEGER,
-rrule_id INTEGER DEFAULT 0
+rrule_id INTEGER DEFAULT 0,
+recurrence_id TEXT,
+rdate TEXT,
+has_attendee INTEGER,
+has_alarm INTEGER,
+system_type INTEGER,
+updated INTEGER,
+sync_data1 TEXT,
+sync_data2 TEXT,
+sync_data3 TEXT,
+sync_data4 TEXT,
+has_exception INTEGER DEFAULT 0,
+has_extended INTEGER DEFAULT 0,
+freq INTEGER DEFAULT 0,
+is_allday INTEGER DEFAULT 0
 );
 CREATE INDEX sch_idx1 ON schedule_table(type);
-CREATE TRIGGER trg_sch_del AFTER DELETE ON schedule_table
+CREATE INDEX sch_idx2 ON schedule_table(calendar_id);
+CREATE INDEX sch_idx3 ON schedule_table(sync_data4);
+
+CREATE TRIGGER trg_original_mod AFTER UPDATE OF is_deleted 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);
+   UPDATE schedule_table SET is_deleted = 1 WHERE original_event_id = old.id;
+ END;
+
+CREATE TRIGGER trg_schedule_del AFTER DELETE ON schedule_table
+ BEGIN
+   DELETE FROM rrule_table WHERE event_id = old.id;
+   DELETE FROM alarm_table WHERE event_id = old.id;
    DELETE FROM schedule_table WHERE original_event_id = old.id;
+   DELETE FROM normal_instance_table WHERE event_id = old.id;
+   DELETE FROM allday_instance_table WHERE event_id = old.id;
+   DELETE FROM attendee_table WHERE event_id = old.id;
+   DELETE FROM extended_table WHERE record_id = old.id AND record_type = 2;
+   DELETE FROM extended_table WHERE record_id = old.id AND record_type = 3;
  END;
 
-CREATE TRIGGER trig_original_mod AFTER UPDATE OF is_deleted ON schedule_table
+-- type + 1: is cal_record_type_e = cal_sch_type_e + 1
+CREATE TRIGGER trg_schedule_del2 AFTER DELETE ON schedule_table
+ WHEN old.is_deleted = 0 AND old.calendar_id = (SELECT id FROM calendar_table WHERE id = old.calendar_id)
  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;
+   INSERT INTO deleted_table VALUES(old.id, old.type + 1, old.calendar_id, (SELECT ver FROM version_table) + 1, old.created_ver, old.original_event_id);
+ END;
+
+CREATE TRIGGER trg_schedule_del3 AFTER DELETE ON schedule_table
+ WHEN old.is_deleted = 1 AND old.calendar_id = (SELECT id FROM calendar_table WHERE id = old.calendar_id)
+ BEGIN
+   INSERT INTO deleted_table VALUES(old.id, old.type + 1, old.calendar_id, old.changed_ver, old.created_ver, old.original_event_id);
  END;
 
 CREATE TABLE rrule_table
@@ -116,78 +137,68 @@ event_id INTEGER,
 dtstart_utime INTEGER,
 dtend_utime INTEGER
 );
+CREATE INDEX n_i_idx1 ON normal_instance_table(event_id, dtstart_utime);
+--CREATE INDEX n_i_idx2 ON normal_instance_table(dtstart_utime);
+CREATE INDEX n_i_idx3 ON normal_instance_table (dtend_utime, dtstart_utime);
+CREATE INDEX n_i_idx4 ON normal_instance_table (dtstart_utime, dtend_utime);
 
 CREATE TABLE allday_instance_table
 (
 event_id INTEGER,
-dtstart_datetime TEXT,
-dtend_datetime TEXT
+dtstart_datetime DATE,
+dtend_datetime DATE
 );
+CREATE INDEX a_i_idx1 ON allday_instance_table(event_id, dtstart_datetime);
+--CREATE INDEX a_i_idx2 ON allday_instance_table(dtstart_datetime);
+CREATE INDEX a_i_idx3 ON allday_instance_table (dtend_datetime, dtstart_datetime);
+CREATE INDEX a_i_idx4 ON allday_instance_table (dtstart_datetime, dtend_datetime);
 
-CREATE TABLE cal_participant_table
+CREATE TABLE attendee_table
 (
 event_id INTEGER,
 attendee_name TEXT,
 attendee_email TEXT,
 attendee_number TEXT,
 attendee_status INTEGER,
-attendee_type INTEGER,
 attendee_ct_index INTEGER,
 attendee_role INTEGER,
 attendee_rsvp INTEGER,
 attendee_group TEXT,
 attendee_delegator_uri TEXT,
-attendee_delegate_uri TEXT,
-attendee_uid TEXT
+attendee_uid TEXT,
+attendee_cutype INTEGER,
+attendee_delegatee_uri TEXT,
+attendee_member TEXT
 );
 
+CREATE INDEX attendee_idx1 on attendee_table(event_id);
+
 CREATE TABLE calendar_table
 (
-calendar_id TEXT,
+id INTEGER PRIMARY KEY AUTOINCREMENT,
 uid TEXT,
-link TEXT,
 updated INTEGER,
 name TEXT,
 description TEXT,
-author TEXT,
 color TEXT,
-hidden INTEGER,
-selected INTEGER,
 location TEXT,
-locale INTEGER,
-country INTEGER,
-time_zone INTEGER,
-timezone_label TEXT,
-display_all_timezones INTEGER,
-date_field_order INTEGER,
-format_24hour_time INTEGER,
-week_start INTEGER,
-default_cal_mode INTEGER,
-custom_cal_mode INTEGER,
-user_location TEXT,
-weather TEXT,
-show_declined_events INTEGER,
-hide_invitations INTEGER,
-alternate_calendar INTEGER,
 visibility INTEGER,
-projection INTEGER,
-sequence INTEGER,
-suppress_reply_notifications INTEGER,
 sync_event INTEGER,
-times_cleaned INTEGER,
-guests_can_modify INTEGER,
-guests_can_invite_others INTEGER,
-guests_can_see_guests INTEGER,
-access_level INTEGER,
-sync_status INTEGER,
-is_deleted INTEGER,
+is_deleted INTEGER DEFAULT 0,
 account_id INTEGER,
-sensitivity INTEGER,
-store_type INTEGER
+store_type INTEGER,
+sync_data1 TEXT,
+sync_data2 TEXT,
+sync_data3 TEXT,
+sync_data4 TEXT,
+deleted INTEGER DEFAULT 0,
+mode INTEGER DEFAULT 0,
+owner_label TEXT
 );
 
 CREATE TABLE timezone_table
 (
+id INTEGER PRIMARY KEY AUTOINCREMENT,
 tz_offset_from_gmt INTEGER,
 standard_name TEXT,
 std_start_month INTEGER,
@@ -200,19 +211,39 @@ day_light_start_month INTEGER,
 day_light_start_position_of_week INTEGER,
 day_light_start_day INTEGER,
 day_light_start_hour INTEGER,
-day_light_bias INTEGER
+day_light_bias INTEGER,
+calendar_id INTEGER
 );
 
+CREATE TRIGGER trg_cal_del AFTER DELETE ON calendar_table
+ BEGIN
+   DELETE FROM timezone_table WHERE calendar_id = old.id;
+   DELETE FROM schedule_table WHERE calendar_id = old.id;
+   DELETE FROM extended_table WHERE record_id = old.id AND record_type = 1;
+ END;
+
 CREATE TABLE alarm_table
 (
 event_id INTEGER,
-alarm_time INTEGER,
 remind_tick INTEGER,
 remind_tick_unit INTEGER,
-alarm_tone TEXT,
 alarm_description TEXT,
 alarm_type INTEGER,
-alarm_id INTEGER
+alarm_id INTEGER DEFAULT 0,
+alarm_summary TEXT,
+alarm_action INTEGER DEFAULT 0,
+alarm_attach TEXT,
+alarm_utime INTEGER,
+alarm_datetime DATE
+);
+
+CREATE TABLE extended_table
+(
+id INTEGER PRIMARY KEY AUTOINCREMENT,
+record_id INTEGER,
+record_type INTEGER,
+key TEXT,
+value TEXT
 );
 
 CREATE TABLE deleted_table
@@ -220,15 +251,19 @@ CREATE TABLE deleted_table
 schedule_id INTEGER,
 schedule_type INTEGER,
 calendar_id INTEGER,
-deleted_ver INTEGER
+deleted_ver INTEGER,
+created_ver INTEGER,
+original_event_id INTEGER DEFAULT -1
 );
 CREATE INDEX deleted_schedule_ver_idx ON deleted_table(deleted_ver);
 
 CREATE TABLE version_table
 (
-ver INTEGER PRIMARY KEY
+ver INTEGER PRIMARY KEY,
+contacts_ver INTEGER DEFAULT 0
 );
-INSERT INTO version_table VALUES(0);
+INSERT INTO version_table VALUES(0, 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,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);
+INSERT INTO calendar_table VALUES(1,0,0,'Default event calendar'   ,0,'224.167.79.255',0,1,1,0,-1,1,0,0,0,0,0,0,'calendar');
+INSERT INTO calendar_table VALUES(2,0,0,'Default todo calendar'    ,0,'41.177.227.255',0,1,1,0,-1,2,0,0,0,0,0,0,'calendar');
+INSERT INTO calendar_table VALUES(3,0,0,'Default birthday calendar',0,'141.17.27.255' ,0,1,0,0,-1,1,0,0,0,0,0,0,'calendar');
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
new file mode 100755 (executable)
index 0000000..d3a7624
--- /dev/null
@@ -0,0 +1,121 @@
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/server)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/native)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common/ipc)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/schema)
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/server)
+
+SET(DAEMON calendar-serviced)
+SET(LIBNAME calendar-service-server)
+
+SET(LIBSRCS
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_alarm.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_attendee.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_calendar.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_event.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_instance_allday.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_instance_allday_extended.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_instance_normal.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_instance_normal_extended.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_search.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_timezone.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_todo.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_updated_info.c
+       ${CMAKE_SOURCE_DIR}/common/ipc/cal_ipc_marshal_extended.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_calendar.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_event.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_todo.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_attendee.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_alarm.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_search.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_timezone.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_updated_info.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_instance_normal.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_instance_allday.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_instance_normal_extended.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_instance_allday_extended.c
+       ${CMAKE_SOURCE_DIR}/common/cal_record_extended.c
+       ${CMAKE_SOURCE_DIR}/common/cal_view.c
+       ${CMAKE_SOURCE_DIR}/common/cal_filter.c
+       ${CMAKE_SOURCE_DIR}/common/cal_query.c
+       ${CMAKE_SOURCE_DIR}/common/cal_list.c
+       ${CMAKE_SOURCE_DIR}/common/cal_time.cpp
+       ${CMAKE_SOURCE_DIR}/common/cal_inotify.c
+    ${CMAKE_SOURCE_DIR}/common/cal_vcalendar.c
+    ${CMAKE_SOURCE_DIR}/common/cal_vcalendar_make.c
+    ${CMAKE_SOURCE_DIR}/common/cal_vcalendar_parse.c
+       ${CMAKE_SOURCE_DIR}/common/cal_mutex.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db.c
+       ${CMAKE_SOURCE_DIR}/native/cal_calendar.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_calendar.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_util.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_alarm.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_attendee.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_instance.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_rrule.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_query.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_calendar.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_event.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_event.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_search.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_attendee.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_alarm.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_timezone.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_instance_normal.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_instance_normal_extended.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_instance_allday.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_instance_allday_extended.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_todo.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_plugin_extended.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_extended.c
+       ${CMAKE_SOURCE_DIR}/native/cal_reminder.c
+       ${CMAKE_SOURCE_DIR}/native/cal_access_control.c
+       ${CMAKE_SOURCE_DIR}/native/cal_db_instance_helper.c
+       cal_server_ipc.c
+)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(calserver_pkgs REQUIRED
+       dlog
+       pims-ipc
+       db-util
+       alarm-service
+       capi-base-common
+       icu-i18n
+       accounts-svc
+       capi-appfw-application
+       )
+
+FOREACH(flag ${calserver_pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fPIE")
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
+SET(calserver_pkgs_LDFLAGS "${pkgs_LDFLAGS} ${calserver_pkgs_LDFLAGS}")
+
+ADD_DEFINITIONS("-DCAL_IPC_SERVER")
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+
+ADD_LIBRARY(${LIBNAME} STATIC ${LIBSRCS})
+TARGET_LINK_LIBRARIES(${LIBNAME} ${calserver_pkgs_LDFLAGS})
+
+#cmake_policy(SET CMP0002 OLD)
+ADD_EXECUTABLE(${DAEMON}
+       cal_server.c
+       cal_server_contacts.c
+       cal_server_alarm.c
+       cal_server_calendar_delete.c
+       cal_server_reminder.c
+       cal_server_schema.c
+       cal_server_update.c
+       )
+SET_TARGET_PROPERTIES(${DAEMON} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS})
+TARGET_LINK_LIBRARIES(${DAEMON} ${calserver_pkgs_LDFLAGS} ${LIBNAME})
+
+INSTALL(TARGETS ${DAEMON} DESTINATION bin)
diff --git a/server/cal_server.c b/server/cal_server.c
new file mode 100644 (file)
index 0000000..c9c7a25
--- /dev/null
@@ -0,0 +1,409 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grp.h>
+#include <sys/types.h>
+#include <unistd.h>     //getuid
+#include <pims-ipc.h>
+#include <pims-ipc-svc.h>
+#include <glib-object.h>
+#include <alarm.h>
+#include <contacts.h>
+#include <account.h>
+
+#include "calendar.h"
+#include "cal_internal.h" // DBG
+#include "cal_ipc.h"
+#include "cal_server_ipc.h"
+#include "cal_typedef.h"
+#include "cal_inotify.h"
+
+#include "cal_db.h" // CAL_SECURITY_FILE_GROUP
+
+#include "cal_server_contacts.h"
+#include "cal_server_alarm.h"
+#include "cal_server_calendar_delete.h"
+#include "cal_server_schema.h"
+#include "cal_server_update.h"
+#include "cal_access_control.h"
+#include "cal_db_calendar.h"
+#include "cal_time.h" // u_clean
+
+//static GMainLoop *loop;
+
+static account_subscribe_h cal_account_h = NULL;
+#ifdef CAL_MEMORY_TEST
+GMainLoop* main_loop = NULL;
+#endif //#ifdef CAL_MEMORY_TEST
+
+static int __server_main();
+static bool __cal_server_account_delete_cb(const char* event_type, int account_id, void* user_data);
+
+static gboolean __cal_server_timeout_cb(gpointer argv)
+{
+       int ret;
+       int *try_count = (int *)argv;
+       DBG("called count(%d)", *try_count);
+       if (*try_count > 2)
+       {
+               ERR("Tried 3 times but failed to contacts connect");
+               return false;
+       }
+
+       ret = contacts_connect();
+       if (CONTACTS_ERROR_NONE == ret)
+       {
+               DBG("contact connected");
+       }
+       else
+       {
+               ERR("Failed to connect (%d) times", *try_count + 1);
+               *try_count += 1;
+               return true;
+       }
+
+       ret = _cal_server_contacts();
+       return false;
+}
+
+static bool __cal_server_account_delete_cb(const char* event_type, int account_id, void* user_data)
+{
+       CAL_FN_CALL;
+
+       if (strcmp(event_type, ACCOUNT_NOTI_NAME_DELETE) == 0)
+       {
+               calendar_db_delete_account(account_id);
+               _cal_server_contacts_delete(account_id);
+       }
+       return true;
+}
+
+#ifdef CAL_MEMORY_TEST
+static gboolean  __cal_server_ipc_destroy_idle(void* user_data)
+{
+       ERR();
+       g_main_loop_quit(main_loop);
+}
+
+void _cal_server_ipc_destroy(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       ERR();
+       int ret = CALENDAR_ERROR_NONE;
+
+       // kill daemon destroy
+       g_timeout_add_seconds(1, &__cal_server_ipc_destroy_idle, NULL);
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+
+       return;
+}
+#endif //#ifdef CAL_MEMORY_TEST
+
+static int __server_main(void)
+{
+       int ret;
+       int on_contact = 0;
+       int try_count = 0;
+       g_type_init();
+
+       pims_ipc_svc_init(CAL_IPC_SOCKET_PATH,CAL_SECURITY_FILE_GROUP, 0777);
+
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_CONNECT, _cal_server_ipc_connect, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DISCONNECT, _cal_server_ipc_disconnect, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_CHECK_PERMISSION, _cal_server_ipc_check_permission, NULL) != 0) {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_INSERT_RECORD, _cal_server_ipc_db_insert_record, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_GET_RECORD, _cal_server_ipc_db_get_record, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_UPDATE_RECORD, _cal_server_ipc_db_update_record, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_DELETE_RECORD, _cal_server_ipc_db_delete_record, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_GET_ALL_RECORDS, _cal_server_ipc_db_get_all_records, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_GET_RECORDS_WITH_QUERY, _cal_server_ipc_db_get_records_with_query, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_CLEAN_AFTER_SYNC, _cal_server_ipc_db_clean_after_sync, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_GET_COUNT, _cal_server_ipc_db_get_count, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_GET_COUNT_WITH_QUERY, _cal_server_ipc_db_get_count_with_query, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_INSERT_RECORDS, _cal_server_ipc_db_insert_records, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_UPDATE_RECORDS, _cal_server_ipc_db_update_records, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_DELETE_RECORDS, _cal_server_ipc_db_delete_records, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_CHANGES_BY_VERSION, _cal_server_ipc_db_get_changes_by_version, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_GET_CURRENT_VERSION, _cal_server_ipc_db_get_current_version, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_INSERT_VCALENDARS, _cal_server_ipc_db_insert_vcalendars, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_REPLACE_VCALENDARS, _cal_server_ipc_db_replace_vcalendars, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_REPLACE_RECORD, _cal_server_ipc_db_replace_record, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_REPLACE_RECORDS, _cal_server_ipc_db_replace_records, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DB_CHANGES_EXCEPTION, _cal_server_ipc_db_changes_exception, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+#ifdef CAL_MEMORY_TEST
+       if (pims_ipc_svc_register(CAL_IPC_MODULE, CAL_IPC_SERVER_DESTROY, _cal_server_ipc_destroy, NULL) != 0)
+       {
+               ERR("pims_ipc_svc_register error");
+               return -1;
+       }
+#endif //#ifdef CAL_MEMORY_TEST
+
+       // for subscribe
+       pims_ipc_svc_init_for_publish(CAL_IPC_SOCKET_PATH_FOR_SUBSCRIPTION, CAL_SECURITY_FILE_GROUP, CAL_SECURITY_DEFAULT_PERMISSION);
+
+       //loop = g_main_loop_new(NULL, FALSE);
+
+       //calendar_alarm_init();
+
+       ret = contacts_connect();
+       if (CONTACTS_ERROR_NONE != ret)
+       {
+               ERR("contacts_connect() failed");
+               g_timeout_add_seconds(30, __cal_server_timeout_cb, (gpointer)&try_count);
+       }
+       else
+       {
+               DBG("contacts connected");
+               on_contact = 1;
+       }
+
+       ret = calendar_connect();
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("calendar_connect() failed");
+               return ret;
+       }
+
+       _cal_db_initialize_view_table();
+
+       if (on_contact)
+       {
+               ret = _cal_server_contacts();
+               if (CALENDAR_ERROR_NONE != ret)
+               {
+                       contacts_disconnect();
+                       ERR("_cal_server_contacts() failed");
+                       return -1;
+               }
+
+               _cal_server_contacts_sync_start();
+       }
+
+       // access_control
+       _cal_access_control_set_client_info("calendar-service", NULL);
+
+       ret = account_subscribe_create(&cal_account_h);
+       if (ACCOUNT_ERROR_NONE == ret) {
+               ret = account_subscribe_notification(cal_account_h, __cal_server_account_delete_cb, NULL);
+               if (ACCOUNT_ERROR_NONE != ret) {
+                       DBG("account_subscribe_notification Failed (%d)", ret);
+               }
+       }
+       else
+               DBG("account_subscribe_create Failed (%d)", ret);
+
+       _cal_inotify_initialize();
+       ret = _cal_server_alarm();
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               if (on_contact)
+               {
+                       contacts_disconnect();
+               }
+               ERR("_cal_server_alarm() failed");
+               return -1;
+       }
+
+       _cal_server_calendar_delete_start();
+
+#ifdef CAL_MEMORY_TEST
+       main_loop = g_main_loop_new(NULL, FALSE);
+
+       pims_ipc_svc_run_main_loop(main_loop);
+
+       ERR("exit");
+       g_main_loop_unref(main_loop);
+#else  //#ifdef CAL_MEMORY_TEST
+       pims_ipc_svc_run_main_loop(NULL);
+#endif //#ifdef CAL_MEMORY_TEST
+
+       _cal_time_u_cleanup();
+       _cal_inotify_finalize();
+       calendar_disconnect();
+
+       contacts_disconnect();
+       on_contact = 0;
+
+       if (cal_account_h)
+       {
+               account_unsubscribe_notification(cal_account_h);
+               cal_account_h = NULL;
+       }
+
+       pims_ipc_svc_deinit_for_publish();
+       pims_ipc_svc_deinit();
+
+       _cal_access_control_unset_client_info();
+       alarmmgr_fini();
+
+       return 0;
+}
+
+int main(int argc, char *argv[])
+{
+       if (getuid() == 0)
+       {        // root
+               gid_t glist[] = {CAL_SECURITY_FILE_GROUP};
+               if (setgroups(1, glist) < 0)        // client and server should have same Groups
+               {
+                       ERR("setgroups() failed");
+               }
+       }
+
+       _cal_server_schema_check();
+       _cal_server_update();
+
+       __server_main();
+       return 0;
+}
+
diff --git a/server/cal_server_alarm.c b/server/cal_server_alarm.c
new file mode 100644 (file)
index 0000000..3b380d1
--- /dev/null
@@ -0,0 +1,1045 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+
+#include <sys/time.h>
+#include <unistd.h>
+
+#include <alarm.h>
+#include <vconf.h>
+#include <app.h>
+
+#include "cal_internal.h"
+#include "calendar.h"
+#include "cal_time.h"
+#include "cal_typedef.h"
+#include "cal_inotify.h"
+
+#include "cal_db_util.h"
+#include "cal_db.h"
+#include "cal_db_query.h"
+#include "cal_server_reminder.h"
+
+#define CAL_SEARCH_LOOP_MAX 4
+
+#define COLOR_CYAN "\033[0;36m"
+#define COLOR_END "\033[0;m"
+
+struct _alarm_data_s
+{
+       int event_id;
+       long long int alert_utime; // to compare
+       int unit;
+       int tick;
+       int type; // utime, local
+       long long int time;
+       int record; // todo, event
+       char datetime[32];
+};
+
+// this api is necessary for repeat instance.
+static int __cal_server_alarm_unset_alerted_alarmmgr_id(int alarm_id)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       ret = _cal_db_util_begin_trans();
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_begin_trans() failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       DBG("alarm_id(%d)", alarm_id);
+
+       snprintf(query, sizeof(query), "UPDATE %s SET alarm_id = 0 WHERE alarm_id = %d ",
+                       CAL_TABLE_ALARM, alarm_id);
+
+       dbret = _cal_db_util_query_exec(query);
+       if (CAL_DB_OK != dbret)
+       {
+               ERR("_cal_db_util_query_exec() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       _cal_db_util_end_trans(false);
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       _cal_db_util_end_trans(false);
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       _cal_db_util_end_trans(true);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_server_alarm_clear_all_cb(alarm_id_t alarm_id, void *data)
+{
+       int ret;
+
+       DBG("remove alarm id(%d)", alarm_id);
+       __cal_server_alarm_unset_alerted_alarmmgr_id(alarm_id);
+       ret = alarmmgr_remove_alarm(alarm_id);
+       if (ret != ALARMMGR_RESULT_SUCCESS)
+       {
+               ERR("alarmmgr_remove_alarm() failed(ret:%d)", ret);
+               return ret;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_server_alarm_update_alarm_id(int alarm_id, int event_id, int tick, int unit)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       ret = _cal_db_util_begin_trans();
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_begin_trans() failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       DBG("Update alarm_id(%d) in alarm table", alarm_id);
+       snprintf(query, sizeof(query), "UPDATE %s SET "
+                       "alarm_id = %d "
+                       "WHERE event_id = %d AND remind_tick = %d AND remind_tick_unit = %d",
+                       CAL_TABLE_ALARM,
+                       alarm_id,
+                       event_id, tick, unit);
+
+       dbret = _cal_db_util_query_exec(query);
+       if (CAL_DB_OK != dbret)
+       {
+               ERR("_cal_db_util_query_exec() Failed(%d)", dbret);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       _cal_db_util_end_trans(false);
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       _cal_db_util_end_trans(false);
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       _cal_db_util_end_trans(true);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_server_alarm_get_alert_time(int alarm_id, time_t *tt_alert)
+{
+       retvm_if(NULL == tt_alert, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter: tt_alert is NULL");
+
+       char query[2048] = {0};
+       snprintf(query, sizeof(query),
+                       "SELECT event_id, remind_tick_unit, remind_tick, alarm_type, alarm_utime, alarm_datetime "
+                       "FROM %s WHERE alarm_id = %d ",
+                       CAL_TABLE_ALARM, alarm_id);
+
+       sqlite3_stmt *stmt = NULL;
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if (NULL == stmt, CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() Failed");
+
+       int event_id = 0;
+       int unit = 0;
+       int tick = 0;
+       int type = 0;
+       long long int utime = 0;
+       char datetime[32] = {0};
+       if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               int index = 0;
+               event_id = sqlite3_column_int(stmt, index++);
+               unit = sqlite3_column_int(stmt, index++);
+               tick = sqlite3_column_int(stmt, index++);
+               type = sqlite3_column_int(stmt, index++);
+               utime = sqlite3_column_int64(stmt, index++);
+               snprintf(datetime, sizeof(datetime), "%s", (const char *)sqlite3_column_text(stmt, index++));
+       }
+       sqlite3_finalize(stmt);
+
+       if (NULL == tt_alert) {
+               ERR("Invalid parameter: tt_alert is NULL");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       if (CALENDAR_ALARM_TIME_UNIT_SPECIFIC == unit) {
+               if (CALENDAR_TIME_UTIME == type) {
+                       *tt_alert = utime;
+
+               } else {
+                       int y = 0, m = 0, d = 0;
+                       int h = 0, n = 0, s = 0;
+                       sscanf(datetime, CAL_FORMAT_LOCAL_DATETIME, &y, &m, &d, &h, &n, &s);
+                       struct tm st = {0};
+                       st.tm_year = y - 1900;
+                       st.tm_mon = m - 1;
+                       st.tm_mday = d;
+                       st.tm_hour = h;
+                       st.tm_min = n;
+                       st.tm_sec = s;
+                       *tt_alert = (long long int)mktime(&st);
+                       DBG("datetime[%s] to %02d:%02d:%02d (%lld)", datetime, h, n, s, *tt_alert);
+               }
+               return CALENDAR_ERROR_NONE;
+       }
+
+       // not specific
+       snprintf(query, sizeof(query),
+                       "SELECT type, dtstart_type, dtstart_utime, dtstart_datetime, "
+                       "dtend_type, dtend_utime, dtend_datetime "
+                       "FROM %s WHERE id = %d ",
+                       CAL_TABLE_SCHEDULE, event_id);
+
+       stmt = _cal_db_util_query_prepare(query);
+       retvm_if (NULL == stmt, CALENDAR_ERROR_DB_FAILED, "_cal_db_util_query_prepare() Failed");
+       int record_type = 0;
+       int dtstart_type = 0;
+       long long int dtstart_utime = 0;
+       char dtstart_datetime[32] = {0};
+       int dtend_type = 0;
+       long long int dtend_utime = 0;
+       char dtend_datetime[32] = {0};
+
+       if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               int index = 0;
+               record_type = sqlite3_column_int(stmt, index++);
+
+               dtstart_type = sqlite3_column_int(stmt, index++);
+               dtstart_utime = sqlite3_column_int64(stmt, index++);
+               snprintf(dtstart_datetime, sizeof(dtstart_datetime), "%s", (const char *)sqlite3_column_text(stmt, index++));
+
+               dtend_type = sqlite3_column_int(stmt, index++);
+               dtend_utime = sqlite3_column_int64(stmt, index++);
+               snprintf(dtend_datetime, sizeof(dtend_datetime), "%s", (const char *)sqlite3_column_text(stmt, index++));
+       }
+       sqlite3_finalize(stmt);
+
+       if (CALENDAR_BOOK_TYPE_EVENT == record_type) {
+               if (CALENDAR_TIME_UTIME == dtstart_type) {
+                       *tt_alert = dtstart_utime - (tick * unit);
+                       DBG("utime(%lld) - (tick(%d) * unit(%d))", dtstart_utime, tick, unit);
+
+               } else {
+                       int y = 0, m = 0, d = 0;
+                       int h = 0, n = 0, s = 0;
+                       sscanf(dtstart_datetime, CAL_FORMAT_LOCAL_DATETIME, &y, &m, &d, &h, &n, &s);
+                       struct tm st = {0};
+                       st.tm_year = y - 1900;
+                       st.tm_mon = m - 1;
+                       st.tm_mday = d;
+                       st.tm_hour = h;
+                       st.tm_min = n;
+                       st.tm_sec = s;
+                       *tt_alert = (long long int)mktime(&st) - (tick * unit);
+                       DBG("datetime[%s] - (tick(%d) * unit(%d))", dtstart_datetime, tick, unit);
+               }
+
+       } else {
+               if (CALENDAR_TIME_UTIME == dtend_type) {
+                       *tt_alert = dtend_utime - (tick * unit);
+                       DBG("utime(%lld) - (tick(%d) * unit(%d))", dtstart_utime, tick, unit);
+
+               } else {
+                       int y = 0, m = 0, d = 0;
+                       int h = 0, n = 0, s = 0;
+                       sscanf(dtend_datetime, CAL_FORMAT_LOCAL_DATETIME, &y, &m, &d, &h, &n, &s);
+                       struct tm st = {0};
+                       st.tm_year = y - 1900;
+                       st.tm_mon = m - 1;
+                       st.tm_mday = d;
+                       st.tm_hour = h;
+                       st.tm_min = n;
+                       st.tm_sec = s;
+                       *tt_alert = (long long int)mktime(&st) - (tick * unit);
+                       DBG("datetime[%s] - (tick(%d) * unit(%d))", dtend_datetime, tick, unit);
+               }
+       }
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_server_alarm_get_alert_list(time_t utime, GList **l)
+{
+       ENTER();
+       tzset();
+       struct tm st_local = {0};
+       localtime_r(&utime, &st_local);
+       char datetime[32] = {0};
+       snprintf(datetime, sizeof(datetime), CAL_FORMAT_LOCAL_DATETIME,
+                       st_local.tm_year +1900, st_local.tm_mon + 1, st_local.tm_mday,
+                       st_local.tm_hour, st_local.tm_min, st_local.tm_sec);
+
+       char query_specific_utime[512] = {0};
+       snprintf(query_specific_utime, sizeof(query_specific_utime),
+                       // alarm utime(normal event + todo)
+                       "SELECT event_id, remind_tick_unit, remind_tick, alarm_type, alarm_utime, alarm_datetime "
+                       "FROM %s "
+                       "WHERE remind_tick_unit = %d AND alarm_type = %d AND alarm_utime = %ld ",
+                       CAL_TABLE_ALARM,
+                       CALENDAR_ALARM_TIME_UNIT_SPECIFIC, CALENDAR_TIME_UTIME, utime);
+
+       char query_specific_localtime[512] = {0};
+       snprintf(query_specific_localtime, sizeof(query_specific_localtime),
+                       // alarm local
+                       "SELECT event_id, remind_tick_unit, remind_tick, alarm_type, alarm_utime, alarm_datetime "
+                       "FROM %s "
+                       "WHERE remind_tick_unit = %d AND alarm_type = %d AND alarm_datetime = '%s' ",
+                       CAL_TABLE_ALARM,
+                       CALENDAR_ALARM_TIME_UNIT_SPECIFIC, CALENDAR_TIME_LOCALTIME, datetime);
+
+       char query_nonspecific_event_utime[512] = {0};
+       snprintf(query_nonspecific_event_utime, sizeof(query_nonspecific_event_utime),
+                       // A:alarm B:normal instance
+                       "SELECT A.event_id, A.remind_tick_unit, A.remind_tick, A.alarm_type, B.dtstart_utime, A.alarm_datetime "
+                       "FROM %s as A, %s as B ON A.event_id = B.event_id "
+                       "WHERE A.remind_tick_unit > %d AND (B.dtstart_utime - ( A.remind_tick_unit * A.remind_tick )) = %ld ",
+                       CAL_TABLE_ALARM, CAL_TABLE_NORMAL_INSTANCE,
+                       CALENDAR_ALARM_TIME_UNIT_SPECIFIC, utime);
+
+       char query_nonspecific_event_localtime[512] = {0};
+       snprintf(query_nonspecific_event_localtime, sizeof(query_nonspecific_event_localtime),
+                       // A:alarm B:allday
+                       "SELECT A.event_id, A.remind_tick_unit, A.remind_tick, A.alarm_type, A.alarm_utime, B.dtstart_datetime "
+                       "FROM %s as A, %s as B ON A.event_id = B.event_id "
+                       "WHERE A.remind_tick_unit > %d AND "
+                       "( strftime('%%s', B.dtstart_datetime) - ( A.remind_tick_unit * A.remind_tick ) - strftime('%%s', '%s') = 0) ",
+                       CAL_TABLE_ALARM, CAL_TABLE_ALLDAY_INSTANCE,
+                       CALENDAR_ALARM_TIME_UNIT_SPECIFIC, datetime);
+
+       char query_nonspecific_todo_utime[512] = {0};
+       snprintf(query_nonspecific_todo_utime, sizeof(query_nonspecific_todo_utime),
+                       // A:alarm B:todo(normal)
+                       "SELECT A.event_id, A.remind_tick_unit, A.remind_tick, A.alarm_type, B.dtend_utime, A.alarm_datetime "
+                       "FROM %s as A, %s as B ON A.event_id = B.id "
+                       "WHERE A.remind_tick_unit > %d AND B.type = %d "
+                       "AND (B.dtend_utime - ( A.remind_tick_unit * A.remind_tick )) = %ld ",
+                       CAL_TABLE_ALARM, CAL_TABLE_SCHEDULE,
+                       CALENDAR_ALARM_TIME_UNIT_SPECIFIC, CALENDAR_BOOK_TYPE_TODO,
+                       utime);
+
+       char query_nonspecific_todo_localtime[512] = {0};
+       snprintf(query_nonspecific_todo_localtime, sizeof(query_nonspecific_todo_localtime),
+                       // A:alarm B:todo(allday)
+                       "SELECT A.event_id, A.remind_tick_unit, A.remind_tick, A.alarm_type, A.alarm_utime, B.dtend_datetime "
+                       "FROM %s as A, %s as B ON A.event_id = B.id "
+                       "WHERE A.remind_tick_unit > %d AND B.type = %d "
+                       "AND ( strftime('%%s', B.dtend_datetime) - ( A.remind_tick_unit * A.remind_tick ) - strftime('%%s', '%s') = 0) ",
+                       CAL_TABLE_ALARM, CAL_TABLE_SCHEDULE,
+                       CALENDAR_ALARM_TIME_UNIT_SPECIFIC, CALENDAR_BOOK_TYPE_TODO,
+                       datetime);
+
+       char query[3072] = {0};
+       snprintf(query, sizeof(query), "%s UNION %s UNION %s UNION %s UNION %s UNION %s ",
+                       query_specific_utime, query_specific_localtime, query_nonspecific_event_utime,
+                       query_nonspecific_event_localtime, query_nonspecific_todo_utime, query_nonspecific_todo_localtime);
+
+       sqlite3_stmt *stmt = NULL;
+       stmt = _cal_db_util_query_prepare(query);
+
+       int index = 0;
+       int count = 0;
+       while (CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               index = 0;
+               struct _alarm_data_s *ad = calloc(1, sizeof(struct _alarm_data_s));
+               if (NULL == ad)
+               {
+                       ERR("calloc() failed");
+                       continue;
+               }
+               ad->event_id = sqlite3_column_int(stmt, index++);
+               ad->unit = sqlite3_column_int(stmt, index++);
+               ad->tick = sqlite3_column_int(stmt, index++);
+               ad->type = sqlite3_column_int(stmt, index++);
+               ad->time = (long long int)sqlite3_column_int64(stmt, index++);
+               snprintf(ad->datetime, sizeof(ad->datetime), "%s", (const char *)sqlite3_column_text(stmt, index++));
+               *l= g_list_append(*l, ad);
+               count++;
+               DBG("<%3d> id(%d) unit(%d) tick(%d) type(%d) time(%lld) [%s]",
+                               count, ad->event_id, ad->unit, ad->tick, ad->type, ad->time, ad->datetime);
+       }
+       sqlite3_finalize(stmt);
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __cal_server_alarm_get_upcoming_specific_utime(time_t utime, GList **l) // case 1
+{
+       char query_specific_utime[512] = {0};
+       snprintf(query_specific_utime, sizeof(query_specific_utime),
+                       // alarm utime(normal event + todo)
+                       "SELECT event_id, remind_tick_unit, remind_tick, alarm_type, alarm_utime, alarm_datetime "
+                       "FROM %s "
+                       "WHERE remind_tick_unit = %d AND alarm_type = %d AND alarm_utime > %ld ORDER BY alarm_utime ASC LIMIT 1 ",
+                       CAL_TABLE_ALARM,
+                       CALENDAR_ALARM_TIME_UNIT_SPECIFIC, CALENDAR_TIME_UTIME, utime);
+
+       sqlite3_stmt *stmt = NULL;
+       stmt = _cal_db_util_query_prepare(query_specific_utime);
+       if (NULL == stmt) {
+               ERR("_cal_db_util_query_prepare() Failed");
+               ERR("[%s]", query_specific_utime);
+               return;
+       }
+
+       if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               struct _alarm_data_s *ad = calloc(1, sizeof(struct _alarm_data_s));
+               if (NULL == ad) {
+                       ERR("calloc() Fail");
+                       sqlite3_finalize(stmt);
+                       return;
+               }
+
+               int index = 0;
+               ad->event_id = sqlite3_column_int(stmt, index++);
+               ad->unit = sqlite3_column_int(stmt, index++);
+               ad->tick = sqlite3_column_int(stmt, index++);
+               ad->type = sqlite3_column_int(stmt, index++);
+               ad->time = (long long int)sqlite3_column_int64(stmt, index++);
+               snprintf(ad->datetime, sizeof(ad->datetime), "%s", (const char *)sqlite3_column_text(stmt, index++));
+               *l = g_list_append(*l, ad);
+               DBG("found id(%d) unit(%d) tick(%d) type(%d) time(%lld) [%s]",
+                               ad->event_id, ad->unit, ad->tick, ad->type, ad->time, ad->datetime);
+               ad->alert_utime = ad->time;
+       }
+       sqlite3_finalize(stmt);
+}
+
+static void __cal_server_alarm_get_upcoming_specific_localtime(const char *datetime, GList **l)
+{
+       char query_specific_localtime[512] = {0};
+       snprintf(query_specific_localtime, sizeof(query_specific_localtime),
+                       // alarm local
+                       "SELECT event_id, remind_tick_unit, remind_tick, alarm_type, alarm_utime, alarm_datetime "
+                       "FROM %s "
+                       "WHERE remind_tick_unit = %d AND alarm_type = %d AND alarm_datetime > '%s' ORDER BY alarm_datetime ASC LIMIT 1 ",
+                       CAL_TABLE_ALARM,
+                       CALENDAR_ALARM_TIME_UNIT_SPECIFIC, CALENDAR_TIME_LOCALTIME, datetime);
+
+       sqlite3_stmt *stmt = NULL;
+       stmt = _cal_db_util_query_prepare(query_specific_localtime);
+       if (NULL == stmt) {
+               ERR("_cal_db_util_query_prepare() Failed");
+               ERR("[%s]", query_specific_localtime);
+               return;
+       }
+
+       if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               struct _alarm_data_s *ad = calloc(1, sizeof(struct _alarm_data_s));
+               if (NULL == ad) {
+                       ERR("calloc() Fail");
+                       sqlite3_finalize(stmt);
+                       return;
+               }
+
+               int index = 0;
+               ad->event_id = sqlite3_column_int(stmt, index++);
+               ad->unit = sqlite3_column_int(stmt, index++);
+               ad->tick = sqlite3_column_int(stmt, index++);
+               ad->type = sqlite3_column_int(stmt, index++);
+               ad->time = (long long int)sqlite3_column_int64(stmt, index++);
+               snprintf(ad->datetime, sizeof(ad->datetime), "%s", (const char *)sqlite3_column_text(stmt, index++));
+               *l = g_list_append(*l, ad);
+               DBG("found id(%d) unit(%d) tick(%d) type(%d) time(%lld) [%s]",
+                               ad->event_id, ad->unit, ad->tick, ad->type, ad->time, ad->datetime);
+
+               struct tm st = {0};
+               char buf[8] = {0};
+               snprintf(buf, strlen("YYYY") + 1, "%s", ad->datetime);
+               st.tm_year = atoi(buf) - 1900;
+               snprintf(buf, strlen("MM") + 1, "%s", ad->datetime + 5);
+               st.tm_mon = atoi(buf) -1;
+               snprintf(buf, strlen("DD") + 1, "%s", ad->datetime + 8);
+               st.tm_mday = atoi(buf);
+               snprintf(buf, strlen("HH") + 1, "%s", ad->datetime + 11);
+               st.tm_hour = atoi(buf);
+               snprintf(buf, strlen("MM") + 1, "%s", ad->datetime + 14);
+               st.tm_min = atoi(buf);
+               snprintf(buf, strlen("SS") + 1, "%s", ad->datetime + 17);
+               st.tm_sec = atoi(buf);
+               ad->alert_utime = (long long int)mktime(&st);
+       }
+       sqlite3_finalize(stmt);
+}
+
+static void __cal_server_alarm_get_upcoming_nonspecific_event_utime(time_t utime, GList **l)
+{
+       char query_nonspecific_event_utime[512] = {0};
+       snprintf(query_nonspecific_event_utime, sizeof(query_nonspecific_event_utime),
+                       // A:alarm B:normal instance
+                       "SELECT A.event_id, A.remind_tick_unit, A.remind_tick, A.alarm_type, B.dtstart_utime, A.alarm_datetime "
+                       "FROM %s as A, %s as B ON A.event_id = B.event_id "
+                       "WHERE A.remind_tick_unit > %d AND (B.dtstart_utime - ( A.remind_tick_unit * A.remind_tick )) > %ld "
+                       "ORDER BY (B.dtstart_utime - ( A.remind_tick_unit * A.remind_tick )) LIMIT 1 ",
+                       CAL_TABLE_ALARM, CAL_TABLE_NORMAL_INSTANCE,
+                       CALENDAR_ALARM_TIME_UNIT_SPECIFIC, utime);
+
+       sqlite3_stmt *stmt = NULL;
+       stmt = _cal_db_util_query_prepare(query_nonspecific_event_utime);
+       if (NULL == stmt) {
+               ERR("_cal_db_util_query_prepare() Failed");
+               ERR("[%s]", query_nonspecific_event_utime);
+               return;
+       }
+
+       if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               struct _alarm_data_s *ad = calloc(1, sizeof(struct _alarm_data_s));
+               if (NULL == ad) {
+                       ERR("calloc() Fail");
+                       sqlite3_finalize(stmt);
+                       return;
+               }
+
+               int index = 0;
+               ad->event_id = sqlite3_column_int(stmt, index++);
+               ad->unit = sqlite3_column_int(stmt, index++);
+               ad->tick = sqlite3_column_int(stmt, index++);
+               ad->type = sqlite3_column_int(stmt, index++);
+               ad->time = (long long int)sqlite3_column_int64(stmt, index++);
+               snprintf(ad->datetime, sizeof(ad->datetime), "%s", (const char *)sqlite3_column_text(stmt, index++));
+               *l = g_list_append(*l, ad);
+               DBG("found id(%d) unit(%d) tick(%d) type(%d) time(%lld) [%s]",
+                               ad->event_id, ad->unit, ad->tick, ad->type, ad->time, ad->datetime);
+
+               ad->alert_utime = ad->time - (ad->tick * ad->unit);
+       }
+       sqlite3_finalize(stmt);
+}
+
+static void __cal_server_alarm_get_upcoming_nonspecific_event_localtime(const char *datetime, GList **l)
+{
+       char query_nonspecific_event_localtime[512] = {0};
+       snprintf(query_nonspecific_event_localtime, sizeof(query_nonspecific_event_localtime),
+                       // A:alarm B:allday
+                       "SELECT A.event_id, A.remind_tick_unit, A.remind_tick, A.alarm_type, A.alarm_utime, B.dtstart_datetime "
+                       "FROM %s as A, %s as B ON A.event_id = B.event_id "
+                       "WHERE A.remind_tick_unit > %d AND "
+                       "( strftime('%%s', B.dtstart_datetime) - ( A.remind_tick_unit * A.remind_tick ) - strftime('%%s', '%s') > 0 ) "
+                       "ORDER BY ( strftime('%%s', B.dtstart_datetime) - ( A.remind_tick_unit * A.remind_tick )) LIMIT 1 ",
+                       CAL_TABLE_ALARM, CAL_TABLE_ALLDAY_INSTANCE,
+                       CALENDAR_ALARM_TIME_UNIT_SPECIFIC, datetime);
+
+       sqlite3_stmt *stmt = NULL;
+       stmt = _cal_db_util_query_prepare(query_nonspecific_event_localtime);
+       if (NULL == stmt) {
+               ERR("_cal_db_util_query_prepare() Failed");
+               ERR("[%s]", query_nonspecific_event_localtime);
+               return;
+       }
+
+       if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               struct _alarm_data_s *ad = calloc(1, sizeof(struct _alarm_data_s));
+               if (NULL == ad) {
+                       ERR("calloc() Fail");
+                       sqlite3_finalize(stmt);
+                       return;
+               }
+
+               int index = 0;
+               ad->event_id = sqlite3_column_int(stmt, index++);
+               ad->unit = sqlite3_column_int(stmt, index++);
+               ad->tick = sqlite3_column_int(stmt, index++);
+               ad->type = sqlite3_column_int(stmt, index++);
+               ad->time = (long long int)sqlite3_column_int64(stmt, index++);
+               snprintf(ad->datetime, sizeof(ad->datetime), "%s", (const char *)sqlite3_column_text(stmt, index++));
+               *l = g_list_append(*l, ad);
+               DBG("found id(%d) unit(%d) tick(%d) type(%d) time(%lld) [%s]",
+                               ad->event_id, ad->unit, ad->tick, ad->type, ad->time, ad->datetime);
+
+               struct tm st = {0};
+               char buf[8] = {0};
+               snprintf(buf, strlen("YYYY") + 1, "%s", ad->datetime);
+               st.tm_year = atoi(buf) - 1900;
+               snprintf(buf, strlen("MM") + 1, "%s", ad->datetime + 5);
+               st.tm_mon = atoi(buf) -1;
+               snprintf(buf, strlen("DD") + 1, "%s", ad->datetime + 8);
+               st.tm_mday = atoi(buf);
+               snprintf(buf, strlen("HH") + 1, "%s", ad->datetime + 11);
+               st.tm_hour = atoi(buf);
+               snprintf(buf, strlen("MM") + 1, "%s", ad->datetime + 14);
+               st.tm_min = atoi(buf);
+               snprintf(buf, strlen("SS") + 1, "%s", ad->datetime + 17);
+               st.tm_sec = atoi(buf);
+               DBG(CAL_FORMAT_LOCAL_DATETIME,
+                               st.tm_year + 1900,
+                               st.tm_mon +1,
+                               st.tm_mday,
+                               st.tm_hour,
+                               st.tm_min,
+                               st.tm_sec);
+               ad->alert_utime = (long long int)mktime(&st) - (ad->tick * ad->unit);
+
+       }
+       sqlite3_finalize(stmt);
+}
+
+static void __cal_server_alarm_get_upcoming_nonspecific_todo_utime(time_t utime, GList **l)
+{
+       char query_nonspecific_todo_utime[512] = {0};
+       snprintf(query_nonspecific_todo_utime, sizeof(query_nonspecific_todo_utime),
+                       // A:alarm B:todo(normal)
+                       "SELECT A.event_id, A.remind_tick_unit, A.remind_tick, A.alarm_type, B.dtend_utime, A.alarm_datetime "
+                       "FROM %s as A, %s as B ON A.event_id = B.id "
+                       "WHERE A.remind_tick_unit > %d AND B.type = %d "
+                       "AND (B.dtend_utime - ( A.remind_tick_unit * A.remind_tick )) > %ld "
+                       "ORDER BY (B.dtend_utime - ( A.remind_tick_unit * A.remind_tick )) LIMIT 1 ",
+                       CAL_TABLE_ALARM, CAL_TABLE_SCHEDULE,
+                       CALENDAR_ALARM_TIME_UNIT_SPECIFIC, CALENDAR_BOOK_TYPE_TODO,
+                       utime);
+
+       sqlite3_stmt *stmt = NULL;
+       stmt = _cal_db_util_query_prepare(query_nonspecific_todo_utime);
+       if (NULL == stmt) {
+               ERR("_cal_db_util_query_prepare() Failed");
+               ERR("[%s]", query_nonspecific_todo_utime);
+               return;
+       }
+
+       if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               struct _alarm_data_s *ad = calloc(1, sizeof(struct _alarm_data_s));
+               if (NULL == ad) {
+                       ERR("calloc() Fail");
+                       sqlite3_finalize(stmt);
+                       return;
+               }
+
+               int index = 0;
+               ad->event_id = sqlite3_column_int(stmt, index++);
+               ad->unit = sqlite3_column_int(stmt, index++);
+               ad->tick = sqlite3_column_int(stmt, index++);
+               ad->type = sqlite3_column_int(stmt, index++);
+               ad->time = (long long int)sqlite3_column_int64(stmt, index++);
+               snprintf(ad->datetime, sizeof(ad->datetime), "%s", (const char *)sqlite3_column_text(stmt, index++));
+               *l = g_list_append(*l, ad);
+               DBG("found id(%d) unit(%d) tick(%d) type(%d) time(%lld) [%s]",
+                               ad->event_id, ad->unit, ad->tick, ad->type, ad->time, ad->datetime);
+
+               ad->alert_utime = ad->time - (ad->tick * ad->unit);
+       }
+       sqlite3_finalize(stmt);
+}
+
+static void __cal_server_alarm_get_upcoming_nonspecific_todo_localtime(const char *datetime, GList **l)
+{
+       char query_nonspecific_todo_localtime[512] = {0};
+       snprintf(query_nonspecific_todo_localtime, sizeof(query_nonspecific_todo_localtime),
+                       // A:alarm B:todo(allday)
+                       "SELECT A.event_id, A.remind_tick_unit, A.remind_tick, A.alarm_type, A.alarm_utime, B.dtend_datetime "
+                       "FROM %s as A, %s as B ON A.event_id = B.id "
+                       "WHERE A.remind_tick_unit > %d AND B.type = %d "
+                       "AND ( strftime('%%s', B.dtend_datetime) - ( A.remind_tick_unit * A.remind_tick ) - strftime('%%s', '%s') > 0) "
+                       "ORDER BY ( strftime('%%s', B.dtend_datetime) - ( A.remind_tick_unit * A.remind_tick )) LIMIT 1 ",
+                       CAL_TABLE_ALARM, CAL_TABLE_SCHEDULE,
+                       CALENDAR_ALARM_TIME_UNIT_SPECIFIC, CALENDAR_BOOK_TYPE_TODO,
+                       datetime);
+
+       sqlite3_stmt *stmt = NULL;
+       stmt = _cal_db_util_query_prepare(query_nonspecific_todo_localtime);
+       if (NULL == stmt) {
+               ERR("_cal_db_util_query_prepare() Failed");
+               ERR("[%s]", query_nonspecific_todo_localtime);
+               return;
+       }
+
+       if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) {
+               struct _alarm_data_s *ad = calloc(1, sizeof(struct _alarm_data_s));
+               if (NULL == ad) {
+                       ERR("calloc() Fail");
+                       sqlite3_finalize(stmt);
+                       return;
+               }
+
+               int index = 0;
+               ad->event_id = sqlite3_column_int(stmt, index++);
+               ad->unit = sqlite3_column_int(stmt, index++);
+               ad->tick = sqlite3_column_int(stmt, index++);
+               ad->type = sqlite3_column_int(stmt, index++);
+               ad->time = (long long int)sqlite3_column_int64(stmt, index++);
+               snprintf(ad->datetime, sizeof(ad->datetime), "%s", (const char *)sqlite3_column_text(stmt, index++));
+               *l = g_list_append(*l, ad);
+               DBG("found id(%d) unit(%d) tick(%d) type(%d) time(%lld) [%s]",
+                               ad->event_id, ad->unit, ad->tick, ad->type, ad->time, ad->datetime);
+
+               struct tm st = {0};
+               char buf[8] = {0};
+               snprintf(buf, strlen("YYYY") + 1, "%s", ad->datetime);
+               st.tm_year = atoi(buf) - 1900;
+               snprintf(buf, strlen("MM") + 1, "%s", ad->datetime + 5);
+               st.tm_mon = atoi(buf) -1;
+               snprintf(buf, strlen("DD") + 1, "%s", ad->datetime + 8);
+               st.tm_mday = atoi(buf);
+               snprintf(buf, strlen("HH") + 1, "%s", ad->datetime + 11);
+               st.tm_hour = atoi(buf);
+               snprintf(buf, strlen("MM") + 1, "%s", ad->datetime + 14);
+               st.tm_min = atoi(buf);
+               snprintf(buf, strlen("SS") + 1, "%s", ad->datetime + 17);
+               st.tm_sec = atoi(buf);
+               ad->alert_utime = (long long int)mktime(&st) - (ad->tick * ad->unit);
+       }
+       sqlite3_finalize(stmt);
+}
+
+static gint __cal_server_alarm_sort_cb(gconstpointer a, gconstpointer b)
+{
+       struct _alarm_data_s *p1 = (struct _alarm_data_s *)a;
+       struct _alarm_data_s *p2 = (struct _alarm_data_s *)b;
+       DBG("%lld) > (%lld)",p1->alert_utime, p2->alert_utime);
+
+       return p1->alert_utime > p2->alert_utime ? 1 : -1;
+}
+
+static GFunc __cal_server_alarm_print_cb(gpointer data, gpointer user_data)
+{
+       struct _alarm_data_s *ad = (struct _alarm_data_s *)data;
+       DBG("id(%d) unit(%d) tick(%d) type(%d) time(%lld)", ad->event_id, ad->unit, ad->tick, ad->type, ad->time);
+       return 0;
+}
+
+static int __cal_server_alarm_register(GList *alarm_list)
+{
+       ENTER();
+       int ret = CALENDAR_ERROR_NONE;
+       struct _alarm_data_s *ad = NULL;
+       if (NULL == alarm_list)
+       {
+               DBG("No alarmlist");
+               return CALENDAR_ERROR_NONE;
+       }
+       GList *l = g_list_first(alarm_list);
+       ad = (struct _alarm_data_s *)l->data;
+       if (NULL == ad)
+       {
+               ERR("No data");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       // clear all alarm which set by mine.
+       ret = alarmmgr_enum_alarm_ids(__cal_server_alarm_clear_all_cb, NULL);
+       if (ret != ALARMMGR_RESULT_SUCCESS)
+       {
+               ERR("alarmmgr_enum_alarm_ids() failed");
+               return ret;
+       }
+       //      time_t mod_time = (time_t)(ad->time - (ad->time % 60));
+       time_t mod_time = (time_t)ad->alert_utime;
+
+       alarm_entry_t *alarm_info = NULL;
+       alarm_info = alarmmgr_create_alarm();
+       if (NULL == alarm_info)
+       {
+               ERR("Failed to create alarm");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       tzset();
+       struct tm st_alarm = {0};
+       localtime_r(&mod_time, &st_alarm);
+
+       alarm_date_t date = {0};
+       date.year = st_alarm.tm_year + 1900;
+       date.month = st_alarm.tm_mon + 1;
+       date.day = st_alarm.tm_mday;
+       date.hour = st_alarm.tm_hour;
+       date.min = st_alarm.tm_min;
+       date.sec = st_alarm.tm_sec;
+       alarmmgr_set_time(alarm_info, date);
+       DBG(COLOR_CYAN" >>> registered record id (%d) at %04d/%02d/%02d %02d:%02d:%02d "COLOR_END" (utime(%lld), datetime[%s], tick(%d) unit(%d))",
+                       ad->event_id, date.year, date.month, date.day, date.hour, date.min, date.sec,
+                       ad->time, ad->datetime, ad->tick, ad->unit);
+
+       int alarm_id = 0;
+       ret = alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &alarm_id);
+       if (ret < 0)
+       {
+               ERR("alarmmgr_add_alarm_with_localtime failed (%d)", ret);
+               alarmmgr_free_alarm(alarm_info);
+               return ret;
+       }
+       DBG("alarmmgr id (%d)", alarm_id);
+       __cal_server_alarm_update_alarm_id(alarm_id, ad->event_id, ad->tick, ad->unit);
+       alarmmgr_free_alarm(alarm_info);
+       return CALENDAR_ERROR_NONE;
+}
+
+static bool __app_matched_cb(app_control_h app_control, const char *package, void *user_data)
+{
+       retvm_if (NULL == user_data, true, "Invalid parameter: user_data is NULL");
+
+       int ret = 0;
+       char *mime = NULL;
+       ret = app_control_get_mime(app_control, &mime);
+       retvm_if(APP_CONTROL_ERROR_NONE != ret, true, "app_control_get_mime() is failed(%d)", ret);
+
+       const char *reminder_mime = "application/x-tizen.calendar.reminder";
+       if (strncmp(mime, reminder_mime, strlen(reminder_mime))) { // not same
+               DBG("get mime[%s] is not [%s]", mime, reminder_mime);
+               free(mime);
+               return true;
+       }
+       free(mime);
+
+       GList *alarm_list = (GList *)user_data;
+       int len = 0;
+       len = g_list_length(alarm_list);
+       if (0 == len) {
+               DBG("len is 0, no alarm list");
+               return true;
+       }
+
+       app_control_h b = NULL;
+       app_control_create(&b);
+       app_control_set_operation(b,  APP_CONTROL_OPERATION_DEFAULT);
+       app_control_set_app_id(b, package);
+
+       // data
+       char **ids = NULL;
+       ids = calloc(len, sizeof(char *));
+       if (NULL == ids) {
+               ERR("calloc() is failed");
+               app_control_destroy(b);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       GList *l = g_list_first(alarm_list);
+       int i;
+       for (i = 0; i < len; i++) {
+               struct _alarm_data_s *ad = (struct _alarm_data_s *)l->data;
+               if (NULL == ad) {
+                       ERR("No data");
+                       l = g_list_next(l);
+                       continue;
+               }
+               DBG("pkg[%s] time[%lld] tick[%d] unit[%d] record_type[%d]",
+                               package, ad->time, ad->tick, ad->unit, ad->record);
+
+               char buf_event_id[128] = {0};
+               char buf_time[128] = {0};
+               char buf_tick[128] = {0};
+               char buf_unit[128] = {0};
+               char buf_record_type[128] = {0};
+               snprintf(buf_event_id, sizeof(buf_event_id), "%d", ad->event_id);
+               snprintf(buf_time, sizeof(buf_time), "%lld", ad->time);
+               snprintf(buf_tick, sizeof(buf_tick), "%d", ad->tick);
+               snprintf(buf_unit, sizeof(buf_unit), "%d", ad->unit);
+               snprintf(buf_record_type, sizeof(buf_record_type), "%d", ad->record);
+
+               char *p = NULL;
+               _cal_server_reminder_add_callback_data(&p, "id", buf_event_id);
+               _cal_server_reminder_add_callback_data(&p, "time", buf_time);
+               _cal_server_reminder_add_callback_data(&p, "tick", buf_tick);
+               _cal_server_reminder_add_callback_data(&p, "unit", buf_unit);
+               _cal_server_reminder_add_callback_data(&p, "type", buf_record_type);
+
+               app_control_add_extra_data(b, buf_event_id, p); // key: id, value: id=4&time=123123&..
+               DBG("value[%s]", p);
+               free(p);
+
+               // append ids
+               ids[i] = strdup(buf_event_id);
+
+               l = g_list_next(l);
+       }
+       app_control_add_extra_data_array(b, "ids", (const char **)ids, len);
+       app_control_send_launch_request (b, NULL, NULL);
+       app_control_destroy(b);
+
+       // free ids
+       for (i = 0; i < len; i++) {
+               free(ids[i]);
+               ids[i] = NULL;
+       }
+       free(ids);
+
+       return true;
+}
+
+static void __cal_server_alarm_noti_with_control(GList *alarm_list)
+{
+       retm_if(NULL == alarm_list, "No alarm list");
+
+       app_control_h app_control = NULL;
+       app_control_create(&app_control);
+       app_control_set_operation(app_control, APP_CONTROL_OPERATION_VIEW);
+       app_control_set_mime(app_control, "application/x-tizen.calendar.reminder");
+       app_control_foreach_app_matched(app_control, __app_matched_cb, alarm_list);
+       app_control_destroy(app_control);
+}
+
+static void __cal_server_alarm_noti_with_callback(GList *alarm_list)
+{
+       retm_if(NULL == alarm_list, "No alarm list");
+
+       GList *l = g_list_first(alarm_list);
+       while (l) {
+               struct _alarm_data_s *ad = (struct _alarm_data_s *)l->data;
+               if (NULL == ad) {
+                       ERR("No data");
+                       l = g_list_next(l);
+                       continue;
+               }
+               DBG("callback time[%lld] tick[%d] unit[%d] record_type[%d]",
+                               ad->time, ad->tick, ad->unit, ad->record);
+
+               char buf_event_id[128] = {0};
+               char buf_time[128] = {0};
+               char buf_tick[128] = {0};
+               char buf_unit[128] = {0};
+               char buf_record_type[128] = {0};
+               snprintf(buf_event_id, sizeof(buf_event_id), "%d", ad->event_id);
+               snprintf(buf_time, sizeof(buf_time), "%lld", ad->time);
+               snprintf(buf_tick, sizeof(buf_tick), "%d", ad->tick);
+               snprintf(buf_unit, sizeof(buf_unit), "%d", ad->unit);
+               snprintf(buf_record_type, sizeof(buf_record_type), "%d", ad->record);
+
+               char *p = NULL;
+               _cal_server_reminder_add_callback_data(&p, "id", buf_event_id);
+               _cal_server_reminder_add_callback_data(&p, "time", buf_time);
+               _cal_server_reminder_add_callback_data(&p, "tick", buf_tick);
+               _cal_server_reminder_add_callback_data(&p, "unit", buf_unit);
+               _cal_server_reminder_add_callback_data(&p, "type", buf_record_type);
+               _cal_server_reminder_publish(p);
+               free(p);
+
+               l = g_list_next(l);
+       }
+}
+
+static int __cal_server_alarm_register_with_alarmmgr(time_t tt)
+{
+       GList *l = NULL;
+
+       tzset();
+       struct tm st_local = {0};
+       localtime_r(&tt, &st_local);
+       char alarm_datetime[32] = {0};
+       snprintf(alarm_datetime, sizeof(alarm_datetime), CAL_FORMAT_LOCAL_DATETIME,
+                       st_local.tm_year +1900, st_local.tm_mon + 1, st_local.tm_mday,
+                       st_local.tm_hour, st_local.tm_min, st_local.tm_sec);
+       DBG("register with given time (%ld) datetime[%s]", tt, alarm_datetime);
+
+       __cal_server_alarm_get_upcoming_specific_utime(tt, &l);
+       __cal_server_alarm_get_upcoming_specific_localtime(alarm_datetime, &l);
+       __cal_server_alarm_get_upcoming_nonspecific_event_utime(tt, &l);
+       __cal_server_alarm_get_upcoming_nonspecific_event_localtime(alarm_datetime, &l);
+       __cal_server_alarm_get_upcoming_nonspecific_todo_utime(tt, &l);
+       __cal_server_alarm_get_upcoming_nonspecific_todo_localtime(alarm_datetime, &l);
+
+       l = g_list_sort(l, __cal_server_alarm_sort_cb);
+       g_list_foreach(l, (GFunc)__cal_server_alarm_print_cb, NULL);
+       __cal_server_alarm_register(l);
+
+       // free list
+       l = g_list_first(l);
+       while(l) {
+               struct _alarm_data_s *ad = (struct _alarm_data_s *)l->data;
+               free(ad);
+               l = g_list_next(l);
+       }
+       g_list_free(l);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int _alert_cb(alarm_id_t alarm_id, void *data)
+{
+       ENTER();
+       GList *l = NULL;
+
+       DBG("alarm_id (%ld", alarm_id);
+       time_t tt_alert = 0;
+       __cal_server_alarm_get_alert_time(alarm_id, &tt_alert);
+       __cal_server_alarm_get_alert_list(tt_alert, &l);
+       __cal_server_alarm_unset_alerted_alarmmgr_id(alarm_id);
+       __cal_server_alarm_noti_with_callback(l);
+       __cal_server_alarm_noti_with_control(l);
+       __cal_server_alarm_register_with_alarmmgr(tt_alert);
+       LEAVE();
+       return 0;
+}
+
+////////////////////////////////////////////////////////////////////
+static void __cal_server_alarm_timechange_cb(keynode_t *node, void *data)
+{
+       ENTER();
+       int t = 0;
+       int ret;
+
+       if (node) {
+               t = vconf_keynode_get_int(node);
+       }
+       else
+       {
+               ret = vconf_get_int(VCONFKEY_SYSTEM_TIMECHANGE, &t);
+               warn_if(0 < ret, "vconf_get_int() Failed");
+       }
+
+       if (t < 0)
+       {
+               __cal_server_alarm_register_with_alarmmgr(time(NULL));
+       }
+       else
+       {
+               DBG("system changed time(%ld)", t);
+               __cal_server_alarm_register_with_alarmmgr((time_t)t);
+       }
+}
+
+void __cal_server_alarm_set_timechange(void)
+{
+       vconf_notify_key_changed(VCONFKEY_SYSTEM_TIME_CHANGED,
+                       __cal_server_alarm_timechange_cb, NULL);
+
+       vconf_notify_key_changed(VCONFKEY_TELEPHONY_NITZ_GMT,
+                       __cal_server_alarm_timechange_cb, NULL);
+       vconf_notify_key_changed(VCONFKEY_TELEPHONY_NITZ_EVENT_GMT,
+                       __cal_server_alarm_timechange_cb, NULL);
+       vconf_notify_key_changed(VCONFKEY_TELEPHONY_NITZ_ZONE,
+                       __cal_server_alarm_timechange_cb, NULL);
+}
+
+static void __changed_cb(const char* view_uri, void* data)
+{
+       ENTER();
+       __cal_server_alarm_register_with_alarmmgr(time(NULL));
+}
+
+static int __cal_server_alarm_set_inotify(calendar_db_changed_cb callback)
+{
+       _cal_inotify_subscribe(CAL_NOTI_TYPE_EVENT, CAL_NOTI_EVENT_CHANGED, callback, NULL);
+       _cal_inotify_subscribe(CAL_NOTI_TYPE_TODO, CAL_NOTI_TODO_CHANGED, callback, NULL);
+       return 0;
+}
+
+int _cal_server_alarm(void)
+{
+       ENTER();
+       int ret;
+
+       __cal_server_alarm_set_timechange();
+       __cal_server_alarm_set_inotify(__changed_cb);
+
+       ret = alarmmgr_init("calendar-service");
+       retvm_if(ret < 0, ret, "alarmmgr_init() failed");
+
+       ret = alarmmgr_set_cb(_alert_cb, NULL);
+       retvm_if(ret < 0, ret, "alarmmgr_set_cb() failed");
+
+       __cal_server_alarm_register_with_alarmmgr(time(NULL));
+
+       return CALENDAR_ERROR_NONE;
+}
+
diff --git a/server/cal_server_alarm.h b/server/cal_server_alarm.h
new file mode 100644 (file)
index 0000000..38c5da6
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CAL_SERVER_ALARM_H__
+#define __CAL_SERVER_ALARM_H__
+
+int _cal_server_alarm(void);
+
+#endif  //__CAL_SERVER_ALARM_H__
diff --git a/server/cal_server_calendar_delete.c b/server/cal_server_calendar_delete.c
new file mode 100644 (file)
index 0000000..07a7479
--- /dev/null
@@ -0,0 +1,386 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>     //calloc
+#include <glib.h>
+#include <unistd.h> //sleep
+
+#include "calendar.h"
+#include "cal_typedef.h"
+#include "cal_internal.h"
+#include "cal_server_calendar_delete.h"
+#include "cal_db.h"
+#include "cal_db_util.h"
+
+#define CAL_SERVER_CALENDAR_DELETE_COUNT 50
+#define CAL_SERVER_CALENDAR_DELETE_STEP_TIME 1
+#define CAL_SERVER_CALENDAR_DELETE_THREAD_NAME "cal_server_calendar_delete"
+
+typedef enum
+{
+       STEP_1, // create calendar_id_list
+       STEP_2, // delete schedule_table <-- CAL_SERVER_CALENDAR_DELETE_COUNT
+       // loop STEP_2
+       STEP_3, // delete calendar_table
+} __calendar_delete_step_e;
+
+typedef struct {
+       GList *calendar_id_list;
+       int current_calendar_id;
+       __calendar_delete_step_e step;
+} __calendar_delete_data_s;
+
+GThread *__cal_server_calendar_delete_thread = NULL;
+GCond __cal_server_calendar_delete_cond;
+GMutex __cal_server_calendar_delete_mutex;
+
+static bool __cal_server_calendar_delete_step(int ret, __calendar_delete_data_s* data);
+static int __cal_server_calendar_delete_step1(__calendar_delete_data_s* data);
+static int __cal_server_calendar_delete_step2(__calendar_delete_data_s* data);
+static int __cal_server_calendar_delete_step3(__calendar_delete_data_s* data);
+static bool  __cal_server_calendar_run(__calendar_delete_data_s* data);
+static gpointer  __cal_server_calendar_main(gpointer user_data);
+
+static bool __cal_server_calendar_delete_step(int ret, __calendar_delete_data_s* data)
+{
+       if (ret != CALENDAR_ERROR_NONE && ret != CALENDAR_ERROR_NO_DATA)
+       {
+               if(data->calendar_id_list)
+               {
+                       g_list_free(data->calendar_id_list);
+               }
+               CAL_FREE(data);
+               ERR("fail (%d)",ret);
+
+               return false;
+       }
+       switch (data->step)
+       {
+       case STEP_1:
+               if (ret == CALENDAR_ERROR_NO_DATA)
+               {
+                       if(data->calendar_id_list)
+                       {
+                               g_list_free(data->calendar_id_list);
+                       }
+                       CAL_FREE(data);
+                       ERR("step_1 no_data");
+
+                       return false;
+               }
+               data->step = STEP_2;
+               break;
+       case STEP_2:
+               if (ret == CALENDAR_ERROR_NO_DATA)
+               {
+                       data->step = STEP_3;
+               }
+               break;
+       case STEP_3:
+               data->step = STEP_1;
+               break;
+       default:
+               data->step = STEP_1;
+               break;
+       }
+
+       // go next step
+       return true;
+}
+
+static int __cal_server_calendar_delete_step1(__calendar_delete_data_s* data)
+{
+       char query[CAL_DB_SQL_MIN_LEN] = {0,};
+       sqlite3_stmt *stmt = NULL;
+       int count = 0;
+
+       CAL_FN_CALL;
+
+       if (data->calendar_id_list == NULL)
+       {
+               // get event_list
+               snprintf(query, sizeof(query), "SELECT id FROM %s "
+                               "WHERE deleted = 1",
+                               CAL_TABLE_CALENDAR);
+
+               stmt = _cal_db_util_query_prepare(query);
+               if (NULL == stmt)
+               {
+                       ERR("_cal_db_util_query_prepare() Failed");
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+               while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+               {
+                       int id = 0;
+                       id = sqlite3_column_int(stmt, 0);
+                       data->calendar_id_list = g_list_append(data->calendar_id_list, GINT_TO_POINTER(id));
+               }
+               sqlite3_finalize(stmt);
+       }
+
+       count = g_list_length(data->calendar_id_list);
+       if ( count <= 0)
+       {
+               return CALENDAR_ERROR_NO_DATA;
+       }
+
+       GList *cursor = g_list_first(data->calendar_id_list);
+       if (cursor)
+       {
+               data->current_calendar_id = GPOINTER_TO_INT(cursor->data);
+               data->calendar_id_list = g_list_remove(data->calendar_id_list, GINT_TO_POINTER(data->current_calendar_id));
+
+               return CALENDAR_ERROR_NONE;
+       }
+       else
+       {
+               return CALENDAR_ERROR_NO_DATA;
+       }
+}
+
+static int __cal_server_calendar_delete_step2(__calendar_delete_data_s* data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MIN_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       GList *list = NULL;
+       sqlite3_stmt *stmt = NULL;
+       int count = 0;
+
+       CAL_FN_CALL;
+
+       ret = _cal_db_util_begin_trans();
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_begin_trans() failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       // get event_list
+       snprintf(query, sizeof(query), "SELECT id FROM %s "
+                       "WHERE calendar_id = %d LIMIT %d",
+                       CAL_TABLE_SCHEDULE,
+                       data->current_calendar_id, CAL_SERVER_CALENDAR_DELETE_COUNT);
+
+       stmt = _cal_db_util_query_prepare(query);
+       if (NULL == stmt)
+       {
+               ERR("_cal_db_util_query_prepare() Failed");
+               _cal_db_util_end_trans(false);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       while(CAL_DB_ROW == _cal_db_util_stmt_step(stmt))
+       {
+               int id = 0;
+               id = sqlite3_column_int(stmt, 0);
+               list = g_list_append(list, GINT_TO_POINTER(id));
+       }
+
+       sqlite3_finalize(stmt);
+       stmt = NULL;
+
+       count = g_list_length(list);
+       if ( count <= 0)
+       {
+               _cal_db_util_end_trans(false);
+               return CALENDAR_ERROR_NO_DATA;
+       }
+
+       GList *cursor = g_list_first(list);
+       while(cursor)
+       {
+               int id = GPOINTER_TO_INT(cursor->data);
+               /* delete event table */
+               snprintf(query, sizeof(query), "DELETE FROM %s "
+                               "WHERE id = %d",
+                               CAL_TABLE_SCHEDULE,
+                               id);
+
+               dbret = _cal_db_util_query_exec(query);
+               CAL_DBG("%s",query);
+               if (CAL_DB_OK != dbret)
+               {
+                       ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+                       _cal_db_util_end_trans(false);
+                       g_list_free(list);
+                       switch (dbret)
+                       {
+                       case CAL_DB_ERROR_NO_SPACE:
+                               _cal_db_util_end_trans(false);
+                               return CALENDAR_ERROR_FILE_NO_SPACE;
+                       default:
+                               _cal_db_util_end_trans(false);
+                               return CALENDAR_ERROR_DB_FAILED;
+                       }
+               }
+               cursor = g_list_next(cursor);
+       }
+
+       g_list_free(list);
+
+       _cal_db_util_end_trans(true);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_server_calendar_delete_step3(__calendar_delete_data_s* data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MIN_LEN] = {0};
+       cal_db_util_error_e dbret = CAL_DB_OK;
+
+       ret = _cal_db_util_begin_trans();
+       if (CALENDAR_ERROR_NONE != ret)
+       {
+               ERR("_cal_db_util_begin_trans() failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       CAL_FN_CALL;
+
+       /* delete event table */
+       snprintf(query, sizeof(query), "DELETE FROM %s "
+                       "WHERE id = %d",
+                       CAL_TABLE_CALENDAR,
+                       data->current_calendar_id);
+
+       dbret = _cal_db_util_query_exec(query);
+       if (CAL_DB_OK != dbret)
+       {
+               ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+               _cal_db_util_end_trans(false);
+               switch (dbret)
+               {
+               case CAL_DB_ERROR_NO_SPACE:
+                       _cal_db_util_end_trans(false);
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       _cal_db_util_end_trans(false);
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+
+       _cal_db_util_end_trans(true);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static bool  __cal_server_calendar_run(__calendar_delete_data_s* data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       CAL_FN_CALL;
+
+       if(data == NULL)
+       {
+               ERR("data is NULL");
+
+               return false;
+       }
+
+       switch (data->step)
+       {
+       case STEP_1:
+               ret = __cal_server_calendar_delete_step1(data);
+               break;
+       case STEP_2:
+               ret = __cal_server_calendar_delete_step2(data);
+               break;
+       case STEP_3:
+               ret = __cal_server_calendar_delete_step3(data);
+               break;
+       default:
+               ERR("invalid step");
+               if(data->calendar_id_list)
+               {
+                       g_list_free(data->calendar_id_list);
+               }
+               CAL_FREE(data);
+
+               return false;
+       }
+
+       return __cal_server_calendar_delete_step(ret, data);
+
+}
+
+static gpointer  __cal_server_calendar_main(gpointer user_data)
+{
+       __calendar_delete_data_s *callback_data = NULL;
+       int ret = CALENDAR_ERROR_NONE;
+       CAL_FN_CALL;
+
+       while(1)
+       {
+               callback_data = calloc(1,sizeof(__calendar_delete_data_s));
+
+               if (callback_data != NULL)
+               {
+                       callback_data->step = STEP_1;
+
+                       // delete
+                       while(1)
+                       {
+                               ret = calendar_connect();
+                               if (CALENDAR_ERROR_NONE != ret)
+                               {
+                                       break;
+                               }
+                               sleep(CAL_SERVER_CALENDAR_DELETE_STEP_TIME); // sleep 1 sec.
+                               if (__cal_server_calendar_run(callback_data) == false)
+                               {
+                                       callback_data = NULL;
+                                       CAL_DBG("end");
+                                       break;
+                               }
+                       }
+                       calendar_disconnect();
+                       CAL_FREE(callback_data);
+               }
+               else
+               {
+                       ERR("calloc fail");
+               }
+
+               g_mutex_lock(&__cal_server_calendar_delete_mutex);
+               CAL_DBG("wait");
+               g_cond_wait(&__cal_server_calendar_delete_cond, &__cal_server_calendar_delete_mutex);
+               g_mutex_unlock(&__cal_server_calendar_delete_mutex);
+       }
+
+       return NULL;
+}
+
+void _cal_server_calendar_delete_start(void)
+{
+       CAL_FN_CALL;
+
+       if (__cal_server_calendar_delete_thread == NULL)
+       {
+               g_mutex_init(&__cal_server_calendar_delete_mutex);
+               g_cond_init(&__cal_server_calendar_delete_cond);
+               __cal_server_calendar_delete_thread = g_thread_new(CAL_SERVER_CALENDAR_DELETE_THREAD_NAME,__cal_server_calendar_main,NULL);
+       }
+
+       // don't use mutex.
+       g_cond_signal(&__cal_server_calendar_delete_cond);
+
+       return ;
+
+}
diff --git a/server/cal_server_calendar_delete.h b/server/cal_server_calendar_delete.h
new file mode 100644 (file)
index 0000000..3d859b0
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __CAL_SERVER_CALENDAR_DELETE_H__
+#define __CAL_SERVER_CALENDAR_DELETE_H__
+
+void _cal_server_calendar_delete_start(void);
+
+#endif /*__CAL_SERVER_CALENDAR_DELETE_H__*/
diff --git a/server/cal_server_contacts.c b/server/cal_server_contacts.c
new file mode 100644 (file)
index 0000000..3ae2eb3
--- /dev/null
@@ -0,0 +1,694 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include <sys/time.h> // check time
+#include <contacts.h>
+#include <unistd.h>    // usleep
+
+#include "calendar.h"
+#include "cal_internal.h" // DBG
+#include "cal_typedef.h"
+#include "cal_db.h"
+#include "cal_db_util.h"
+#include "cal_time.h"
+#include "cal_server_contacts.h"
+#include "cal_access_control.h"
+
+#define CAL_SERVER_CONTACTS_SYNC_THREAD_NAME "cal_server_contacts_sync"
+
+static struct timeval stv; // check time
+static struct timeval etv; // check time
+
+GThread *__cal_server_contacts_sync_thread = NULL;
+GCond __cal_server_contacts_sync_cond;
+GMutex __cal_server_contacts_sync_mutex;
+
+static int __cal_server_contacts_get_contacts_db_version(int *version)
+{
+       int ver = 0;
+       int ret;
+       const char *query = "SELECT contacts_ver FROM "CAL_TABLE_VERSION;
+
+       DBG("query[%s]", query);
+       ret = _cal_db_util_query_get_first_int_result(query, NULL, &ver);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_db_util_query_get_first_int_result() failed");
+               return ret;
+       }
+
+       if (version) *version = ver;
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_server_contacts_set_contacts_db_version(int version)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       cal_db_util_error_e dbret = CAL_DB_OK;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+
+       ret = _cal_db_util_begin_trans();
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("_cal_db_util_begin_trans() failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+
+       snprintf(query, sizeof(query), "UPDATE %s SET contacts_ver = %d",
+                       CAL_TABLE_VERSION, version);
+       dbret = _cal_db_util_query_exec(query);
+       if (CAL_DB_OK != dbret) {
+               ERR("_cal_db_util_query_exec() failed (%d)", dbret);
+               switch (dbret) {
+               case CAL_DB_ERROR_NO_SPACE:
+                       _cal_db_util_end_trans(false);
+                       return CALENDAR_ERROR_FILE_NO_SPACE;
+               default:
+                       _cal_db_util_end_trans(false);
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+       }
+       _cal_db_util_end_trans(true);
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_server_contacts_set_new_event(int id, char *label, int date, char *type, int account_id, calendar_record_h *out_event)
+{
+       int ret;
+       char buf[4] = {0};
+       calendar_record_h event = NULL;
+       calendar_time_s st = {0};
+       calendar_time_s et = {0};
+
+       *out_event = NULL;
+
+       DBG("date(%d)", date);
+       st.type = CALENDAR_TIME_LOCALTIME;
+       st.time.date.year = date / 10000;
+       st.time.date.month = (date % 10000) / 100;
+       st.time.date.mday = date % 100;
+       st.time.date.hour = 0;
+       st.time.date.minute = 0;
+       st.time.date.second = 0;
+
+       et.type = CALENDAR_TIME_LOCALTIME;
+       _cal_time_get_next_date(&st, &et);
+
+       snprintf(buf, sizeof(buf), "%d", st.time.date.mday);
+
+       ret = calendar_record_create(_calendar_event._uri, &event);
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "calendar_record_create() failed");
+       ret = calendar_record_set_str(event, _calendar_event.summary, label);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_record_set_str() failed:summary");
+               calendar_record_destroy(event, true);
+               return ret;
+       }
+
+       ret = calendar_record_set_int(event, _calendar_event.calendar_book_id, DEFAULT_BIRTHDAY_CALENDAR_BOOK_ID);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_record_set_int() failed:calendar_book_id");
+               calendar_record_destroy(event, true);
+               return ret;
+       }
+       ret = calendar_record_set_caltime(event, _calendar_event.start_time, st);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_record_set_caltime() failed:start_time");
+               calendar_record_destroy(event, true);
+               return ret;
+       }
+       ret = calendar_record_set_caltime(event, _calendar_event.end_time, et);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_record_set_caltime() failed:end_time");
+               calendar_record_destroy(event, true);
+               return ret;
+       }
+       ret = calendar_record_set_int(event, _calendar_event.person_id, id);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_record_set_int() failed:person_id");
+               calendar_record_destroy(event, true);
+               return ret;
+       }
+       ret = calendar_record_set_str(event, _calendar_event.sync_data1, type);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_record_set_str() failed:sync_data1");
+               calendar_record_destroy(event, true);
+               return ret;
+       }
+       ret = calendar_record_set_int(event, _calendar_event.freq, CALENDAR_RECURRENCE_YEARLY);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_record_set_int() failed:freq");
+               calendar_record_destroy(event, true);
+               return ret;
+       }
+       ret = calendar_record_set_int(event, _calendar_event.interval, 1);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_record_set_int() failed:interval");
+               calendar_record_destroy(event, true);
+               return ret;
+       }
+       ret = calendar_record_set_str(event, _calendar_event.bymonthday, buf);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_record_set_str() failed:bymonthday");
+               calendar_record_destroy(event, true);
+               return ret;
+       }
+       ret = calendar_record_set_int(event, _calendar_event.range_type, CALENDAR_RANGE_NONE);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_record_set_int() failed:interval");
+               calendar_record_destroy(event, true);
+               return ret;
+       }
+
+       if (account_id > 0) {
+               snprintf(buf, sizeof(buf), "%d", account_id);
+               ret = calendar_record_set_str(event, _calendar_event.sync_data4, buf);
+               if (CALENDAR_ERROR_NONE != ret) {
+                       ERR("calendar_record_set_str() failed:interval");
+                       calendar_record_destroy(event, true);
+                       return ret;
+               }
+       }
+
+       *out_event = event;
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_server_contacts_find_delete_event(int id, int **delete_ids, int *delete_count)
+{
+       int ret;
+       int event_id;
+       int count;
+       calendar_list_h list = NULL;
+       calendar_record_h event = NULL;
+       calendar_query_h query = NULL;
+       calendar_filter_h filter = NULL;
+
+       ret = calendar_query_create(_calendar_event._uri, &query);
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "calendar_query_create() failed");
+       ret = calendar_filter_create(_calendar_event._uri, &filter);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_filter_create() failed");
+               calendar_query_destroy(query);
+               return ret;
+       }
+       ret = calendar_filter_add_int(filter, _calendar_event.person_id,
+                       CALENDAR_MATCH_EQUAL, id);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("Failed to add _calendar_event.person_id");
+               calendar_filter_destroy(filter);
+               calendar_query_destroy(query);
+               return ret;
+       }
+       ret = calendar_query_set_filter(query, filter);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_query_set_filter() failed");
+               calendar_filter_destroy(filter);
+               calendar_query_destroy(query);
+               return ret;
+       }
+       ret = calendar_db_get_records_with_query(query, 0, 0, &list);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_db_get_records_with_query() failed");
+               calendar_list_destroy(list, true);
+               calendar_filter_destroy(filter);
+               calendar_query_destroy(query);
+               return ret;
+       }
+       ret = calendar_list_get_count(list, &count);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_list_get_count() failed");
+               calendar_list_destroy(list, true);
+               calendar_filter_destroy(filter);
+               calendar_query_destroy(query);
+               return ret;
+       }
+       DBG("event count(%d)\n", count);
+
+       calendar_list_first(list);
+       *delete_count = 0;
+       *delete_ids = (int*)calloc(count, sizeof(int));
+       do {
+               if (calendar_list_get_current_record_p(list, &event) == CALENDAR_ERROR_NONE) {
+                       if (event == NULL) {
+                               DBG("No event\n");
+                               break;
+                       }
+                       calendar_record_get_int(event, _calendar_event.id, &event_id);
+                       (*delete_ids)[*delete_count] = event_id;
+                       (*delete_count)++;
+                       DBG("delete event_id(%d)\n", event_id);
+               }
+       } while (calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+
+       calendar_list_destroy(list, true);
+       calendar_filter_destroy(filter);
+       calendar_query_destroy(query);
+
+       return CALENDAR_ERROR_NONE;
+}
+
+static int __cal_server_contacts_make_insert_event(int id, calendar_list_h *out_list)
+{
+       int ret = 0;
+       int index;
+       int type;
+       int date;
+       int address_book_id = 0;
+       int account_id = 0;
+       contacts_record_h ctevent = NULL;
+       contacts_record_h address_book = NULL;
+       contacts_record_h contact = NULL;
+       calendar_record_h out_event = NULL;
+
+       ret = contacts_db_get_record(_contacts_contact._uri, id, &contact);
+       retvm_if(CALENDAR_ERROR_NONE != ret, ret, "contacts_db_get_record() Fail(%d)", ret);
+
+       ret = contacts_record_get_int(contact, _contacts_contact.address_book_id, &address_book_id);
+       if (ret != CONTACTS_ERROR_NONE) {
+               DBG("get fail");
+       }
+       else if (address_book_id > 0) { // default phone addressbook is 0
+               if (contacts_db_get_record(_contacts_address_book._uri, address_book_id, &address_book) != CONTACTS_ERROR_NONE) {
+                       DBG("contacts_db_get_record(%d)", address_book_id);
+               }
+               else {
+                       contacts_record_get_int(address_book, _contacts_address_book.account_id, &account_id);
+                       DBG("account_id[%d]",account_id);
+                       contacts_record_destroy(address_book, true);
+               }
+       }
+
+       index = 0;
+       while (CONTACTS_ERROR_NONE == contacts_record_get_child_record_at_p(contact,
+                               _contacts_contact.event, index++, &ctevent)) {
+               ret = contacts_record_get_int(ctevent, _contacts_event.type, &type);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       ERR("Failed to get _contacts_event.type");
+                       break;
+               }
+               ret = contacts_record_get_int(ctevent, _contacts_event.date, &date);
+               if (CONTACTS_ERROR_NONE != ret) {
+                       ERR("Failed to get _contacts_event.date");
+                       break;
+               }
+
+               bool is_proper_type = true;
+               char *caltype = NULL;
+               switch (type) {
+               case CONTACTS_EVENT_TYPE_BIRTH:
+                       caltype = "birthday";
+                       break;
+
+               case CONTACTS_EVENT_TYPE_ANNIVERSARY:
+                       caltype = "anniversary";
+                       break;
+
+               case CONTACTS_EVENT_TYPE_OTHER:
+                       caltype = "other";
+                       break;
+
+               case CONTACTS_EVENT_TYPE_CUSTOM:
+                       ret = contacts_record_get_str_p(ctevent, _contacts_event.label, &caltype);
+                       if (CALENDAR_ERROR_NONE != ret) {
+                               ERR("Failed to get _contacts_event.label");
+                               break;
+                       }
+                       break;
+
+               default:
+                       DBG("Couldn't find type(%d)", type);
+                       is_proper_type = false;
+                       break;
+               }
+
+               if (false == is_proper_type)
+                       continue;
+
+               char *display = NULL;
+               ret = contacts_record_get_str_p(contact, _contacts_contact.display_name, &display);
+               if (CALENDAR_ERROR_NONE != ret) {
+                       ERR("Failed to get _contacts_contact.display_name");
+                       break;
+               }
+               SEC_DBG("id(%d) display[%s] type(%d)", id, display, type);
+
+               __cal_server_contacts_set_new_event(id, display, date, caltype, account_id, &out_event);
+               calendar_list_add(*out_list, out_event);
+       }
+
+       contacts_record_destroy(contact, true);
+       contact = NULL;
+       return CALENDAR_ERROR_NONE;
+}
+
+static void __contacts_changed_cb(const char* view_uri, void *user_data)
+{
+       _cal_server_contacts_sync_start();
+}
+
+static void __cal_server_contacts_append_delete_ids(int **delete_ids, int *size, int *delete_count, int *del_ids, int dcount)
+{
+       if (*size < *delete_count + dcount) {
+               do {
+                       (*size) = (*size) * 2;
+               } while(*size < *delete_count + dcount);
+               *delete_ids = realloc(*delete_ids, *size * sizeof(int));
+               if (NULL == *delete_ids) {
+                       ERR("realloc() Fail");
+                       return;
+               }
+       }
+
+       int i=0;
+       for(;i<dcount;i++) {
+               (*delete_ids)[*delete_count] = del_ids[i];
+               (*delete_count)++;
+       }
+}
+
+#define BULK_MAX_COUNT         100
+#define SYNC_USLEEP            500
+
+static int __cal_server_contacts_sync()
+{
+       int ret;
+       int db_ver = -1;
+       int latest_ver = -1;
+       int status;
+       int id;
+       int count = 0;
+       contacts_list_h list = NULL;
+       contacts_record_h updated = NULL;
+
+       calendar_list_h insert_list = NULL;
+
+       gettimeofday(&stv, NULL); // check time
+
+       ret = __cal_server_contacts_get_contacts_db_version(&db_ver);
+       if (ret != CALENDAR_ERROR_NONE)
+               return false;
+
+       DBG("contacts db version(%d)", db_ver);
+
+       ret = contacts_db_get_changes_by_version(_contacts_contact_updated_info._uri,
+                       -1, db_ver, &list, &latest_ver);
+       if (CONTACTS_ERROR_NONE != ret) {
+               ERR("contacts_db_get_changes_by_version() failed");
+               contacts_list_destroy(list, true);
+               return false;
+       }
+
+       if (list == NULL) {
+               DBG("list is NULL");
+               return false;
+       }
+       DBG("get changes and get the latest contacts version(%d)\n", latest_ver);
+
+       ret = contacts_list_get_count(list, &count);
+       DBG("contacts count(%d)", count);
+       if (count == 0) {
+               if (db_ver != latest_ver) {
+                       __cal_server_contacts_set_contacts_db_version(latest_ver);
+                       DBG("set latest ver(%d)", latest_ver);
+               }
+               return false;
+       }
+
+       int size = 100;
+       int *delete_ids = calloc(size, sizeof(int));
+       int delete_count = 0;
+
+       calendar_list_create(&insert_list);
+
+       while (CONTACTS_ERROR_NONE == ret) {
+               int *del_ids = NULL;
+               int dcount = 0;
+               contacts_list_get_current_record_p(list, &updated);
+               contacts_record_get_int(updated, _contacts_contact_updated_info.contact_id, &id);
+               contacts_record_get_int(updated, _contacts_contact_updated_info.type, &status);
+
+               switch (status) {
+               case CONTACTS_CHANGE_INSERTED:
+                       __cal_server_contacts_make_insert_event(id, &insert_list);
+                       break;
+
+               case CONTACTS_CHANGE_UPDATED:
+                       __cal_server_contacts_find_delete_event(id, &del_ids, &dcount);
+                       __cal_server_contacts_append_delete_ids(&delete_ids, &size, &delete_count, del_ids, dcount);
+                       free(del_ids);
+                       __cal_server_contacts_make_insert_event(id, &insert_list);
+                       break;
+
+               case CONTACTS_CHANGE_DELETED:
+                       __cal_server_contacts_find_delete_event(id, &del_ids, &dcount);
+                       __cal_server_contacts_append_delete_ids(&delete_ids, &size, &delete_count, del_ids, dcount);
+                       free(del_ids);
+                       break;
+
+               default:
+                       ERR("Not valid");
+                       break;
+               }
+               ret = contacts_list_next(list);
+       }
+
+       // delete events
+       int index = 0;
+       int remain_count = delete_count;
+       while (remain_count > 0) {
+               int ids[BULK_MAX_COUNT] = {0};
+               int i;
+               for (i=0;i<BULK_MAX_COUNT && index<delete_count;i++) {
+                       ids[i] = delete_ids[index];
+                       remain_count--;
+                       index++;
+               }
+               DBG("delete record : count(%d)", index);
+               calendar_db_delete_records(_calendar_event._uri, ids, i);
+               usleep(SYNC_USLEEP);
+       }
+       free(delete_ids);
+
+       // insert events
+       int insert_count = 0;
+       calendar_list_get_count(insert_list, &insert_count);
+       while (insert_count > BULK_MAX_COUNT) {
+               calendar_list_h temp = NULL;
+               calendar_list_create(&temp);
+               int i;
+               for (i=0;i<BULK_MAX_COUNT;i++) {
+                       calendar_record_h temp_record = NULL;
+                       calendar_list_first(insert_list);
+                       calendar_list_get_current_record_p(insert_list, &temp_record);
+                       calendar_list_remove(insert_list, temp_record);
+                       calendar_list_add(temp, temp_record);
+                       insert_count--;
+               }
+               calendar_db_insert_records(temp, NULL, NULL);
+               calendar_list_destroy(temp, true);
+               calendar_list_get_count(insert_list, &insert_count);
+               usleep(SYNC_USLEEP);
+       }
+       if (insert_count > 0) {
+               DBG("insert record : count(%d)", insert_count);
+               calendar_db_insert_records(insert_list, NULL, NULL);
+               usleep(SYNC_USLEEP);
+       }
+       calendar_list_destroy(insert_list, true);
+
+       contacts_list_destroy(list, true);
+       __cal_server_contacts_set_contacts_db_version(latest_ver);
+       DBG("set latest ver(%d)", latest_ver);
+
+       int diff;
+       gettimeofday(&etv, NULL);
+       diff = ((int)etv.tv_sec *1000 + (int)etv.tv_usec/1000)
+               -((int)stv.tv_sec *1000 + (int)stv.tv_usec/1000);
+       DBG(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); // time check
+       DBG("diff %ld(%d.%d)",diff, diff/1000, diff%1000); // time check
+
+       return true;
+}
+
+int _cal_server_contacts(void)
+{
+       int ret;
+
+       ret = contacts_db_add_changed_cb(_contacts_event._uri, __contacts_changed_cb, NULL);
+       retvm_if(CONTACTS_ERROR_NONE != ret, ret, "contacts_db_add_changed_cb() failed");
+
+       return CALENDAR_ERROR_NONE;
+}
+
+void _cal_server_contacts_delete(int account_id)
+{
+       int ret;
+       int event_id;
+       int count;
+       calendar_list_h list = NULL;
+       calendar_record_h event = NULL;
+       calendar_query_h query = NULL;
+       calendar_filter_h filter = NULL;
+       char buf[4];
+       int *record_id_array = NULL;
+       int i = 0;
+
+       snprintf(buf, sizeof(buf), "%d", account_id);
+
+       ret = calendar_query_create(_calendar_event._uri, &query);
+       retm_if(CALENDAR_ERROR_NONE != ret, "calendar_query_create() failed");
+       ret = calendar_filter_create(_calendar_event._uri, &filter);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_filter_create() failed");
+               calendar_query_destroy(query);
+               return ;
+       }
+       ret = calendar_filter_add_str(filter, _calendar_event.sync_data4,
+                       CALENDAR_MATCH_EXACTLY, buf);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("Failed to add _calendar_event.person_id");
+               calendar_filter_destroy(filter);
+               calendar_query_destroy(query);
+               return ;
+       }
+       ret = calendar_filter_add_operator(filter, CALENDAR_FILTER_OPERATOR_AND);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("Failed to add _calendar_event.person_id");
+               calendar_filter_destroy(filter);
+               calendar_query_destroy(query);
+               return ;
+       }
+       ret = calendar_filter_add_int(filter, _calendar_event.calendar_book_id,
+                       CALENDAR_MATCH_EQUAL,DEFAULT_BIRTHDAY_CALENDAR_BOOK_ID);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("Failed to add _calendar_event.person_id");
+               calendar_filter_destroy(filter);
+               calendar_query_destroy(query);
+               return ;
+       }
+       ret = calendar_query_set_filter(query, filter);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_query_set_filter() failed");
+               calendar_filter_destroy(filter);
+               calendar_query_destroy(query);
+               return ;
+       }
+       unsigned int projection = _calendar_event.id;
+       ret = calendar_query_set_projection(query, &projection ,1);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_query_set_projection() failed");
+               calendar_filter_destroy(filter);
+               calendar_query_destroy(query);
+               return ;
+       }
+
+       ret = calendar_db_get_records_with_query(query, 0, 0, &list);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_db_get_records_with_query() failed");
+               calendar_list_destroy(list, true);
+               calendar_filter_destroy(filter);
+               calendar_query_destroy(query);
+               return ;
+       }
+       ret = calendar_list_get_count(list, &count);
+       if (CALENDAR_ERROR_NONE != ret) {
+               ERR("calendar_list_get_count() failed");
+               calendar_list_destroy(list, true);
+               calendar_filter_destroy(filter);
+               calendar_query_destroy(query);
+               return ;
+       }
+       DBG("event count(%d)\n", count);
+
+       if (count > 0) {
+               record_id_array = (int *)malloc(count*sizeof(int));
+               calendar_list_first(list);
+               do {
+                       if (calendar_list_get_current_record_p(list, &event) == CALENDAR_ERROR_NONE) {
+                               if (event == NULL) {
+                                       DBG("No event\n");
+                                       break;
+                               }
+                               calendar_record_get_int(event, _calendar_event.id, &event_id);
+                               DBG("delete event_id(%d)\n", event_id);
+                               record_id_array[i] = event_id;
+                               i++;
+                       }
+               } while (calendar_list_next(list) != CALENDAR_ERROR_NO_DATA);
+
+               // delete
+               ret = calendar_db_delete_records(_calendar_event._uri, record_id_array, i);
+               if (ret != CALENDAR_ERROR_NONE)
+                       DBG("calendar_db_delete_records fail");
+               free(record_id_array);
+       }
+       calendar_list_destroy(list, true);
+       calendar_filter_destroy(filter);
+       calendar_query_destroy(query);
+
+       return;
+}
+
+static gpointer  __cal_server_contacts_sync_main(gpointer user_data)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       CAL_FN_CALL;
+
+       while(1) {
+               ret = calendar_connect();
+               if (CALENDAR_ERROR_NONE != ret)
+                       break;
+               _cal_access_control_set_client_info("calendar-service", NULL);
+
+               while(1) {
+                       if (__cal_server_contacts_sync() == false) {
+                               CAL_DBG("end");
+                               break;
+                       }
+               }
+               _cal_access_control_unset_client_info();
+
+               calendar_disconnect();
+
+               g_mutex_lock(&__cal_server_contacts_sync_mutex);
+               CAL_DBG("wait");
+               g_cond_wait(&__cal_server_contacts_sync_cond, &__cal_server_contacts_sync_mutex);
+               g_mutex_unlock(&__cal_server_contacts_sync_mutex);
+       }
+
+       return NULL;
+}
+
+void _cal_server_contacts_sync_start(void)
+{
+       CAL_FN_CALL;
+
+       if (__cal_server_contacts_sync_thread == NULL) {
+               g_mutex_init(&__cal_server_contacts_sync_mutex);
+               g_cond_init(&__cal_server_contacts_sync_cond);
+               __cal_server_contacts_sync_thread = g_thread_new(CAL_SERVER_CONTACTS_SYNC_THREAD_NAME, __cal_server_contacts_sync_main,NULL);
+       }
+
+       // don't use mutex.
+       g_cond_signal(&__cal_server_contacts_sync_cond);
+
+       return;
+}
+
diff --git a/server/cal_server_contacts.h b/server/cal_server_contacts.h
new file mode 100644 (file)
index 0000000..58525e3
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CAL_SERVER_CONTACTS_H__
+#define __CAL_SERVER_CONTACTS_H__
+
+int _cal_server_contacts(void);
+void _cal_server_contacts_delete(int account_id);
+void _cal_server_contacts_sync_start(void);
+
+#endif //__CAL_SERVER_CONTACTS_H__
diff --git a/server/cal_server_ipc.c b/server/cal_server_ipc.c
new file mode 100644 (file)
index 0000000..d061166
--- /dev/null
@@ -0,0 +1,1870 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include <malloc.h>            // malloc_trim
+#include <security-server.h>
+
+#include "calendar_service.h"
+#include "calendar_db.h"
+#include "calendar_query.h"
+#include "calendar_vcalendar.h"
+
+#include "cal_typedef.h"
+#include "cal_db.h"
+#include "cal_db_util.h"
+#include "cal_ipc_marshal.h"
+#include "cal_internal.h"
+#include "cal_server_ipc.h"
+#include "cal_access_control.h"
+
+void _cal_server_ipc_connect(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char *smack_label = NULL;
+       char *cookie = NULL;
+
+       if (indata)
+       {
+               int cookie_size = 0;
+               char *buf = NULL;
+               gsize buf_len;
+               // Access control : get cookie from indata
+               ret = _cal_ipc_unmarshal_int(indata, &cookie_size);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+
+               if (cookie_size <= 0)
+               {
+                       ERR("cookie size is %d", cookie_size);
+                       ret = CALENDAR_ERROR_IPC;
+                       goto ERROR_RETURN;
+               }
+
+               ret = _cal_ipc_unmarshal_char(indata, &buf);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_char fail");
+                       goto ERROR_RETURN;
+               }
+               cookie = (char*)g_base64_decode((const gchar*)buf, &buf_len);
+               CAL_FREE(buf);
+               smack_label = security_server_get_smacklabel_cookie(cookie);
+               if (NULL == smack_label)
+               {
+                       ERR("security_server_get_smacklabel_cookie fail");
+                       ret = CALENDAR_ERROR_SYSTEM;
+                       CAL_FREE(cookie);
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ERR("There is no indata fail");
+               ret = CALENDAR_ERROR_SYSTEM;
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_connect();
+       if (ret == CALENDAR_ERROR_NONE) {
+               _cal_access_control_set_client_info(smack_label, cookie);
+       }
+
+ERROR_RETURN:
+       if (outdata) {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata) {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0) {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else {
+               ERR("outdata is NULL");
+       }
+
+DATA_FREE:
+       CAL_FREE(cookie);
+       CAL_FREE(smack_label);
+       return;
+}
+
+void _cal_server_ipc_disconnect(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+
+       ret = calendar_disconnect();
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       return;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       return;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       return;
+}
+
+void _cal_server_ipc_check_permission(pims_ipc_h ipc, pims_ipc_data_h indata,
+               pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       int permission;
+       bool result;
+
+       if (NULL == indata) {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("check permission fail.");
+               goto ERROR_RETURN;
+       }
+
+       ret = _cal_ipc_unmarshal_int(indata, &permission);
+       if (ret != CALENDAR_ERROR_NONE) {
+               ERR("_cal_ipc_unmarshal_int fail");
+               goto ERROR_RETURN;
+       }
+
+       result = _cal_access_control_have_permission(permission);
+
+ERROR_RETURN:
+       *outdata = pims_ipc_data_create(0);
+       if (!*outdata) {
+               ERR("pims_ipc_data_create fail");
+               return;
+       }
+
+       if (pims_ipc_data_put(*outdata, (void*)&ret, sizeof(int)) != 0) {
+               pims_ipc_data_destroy(*outdata);
+               *outdata = NULL;
+               ERR("pims_ipc_data_put fail (return value)");
+               return;
+       }
+       if (ret == CALENDAR_ERROR_NONE) {
+               if (pims_ipc_data_put(*outdata, (void*)&result, sizeof(bool)) != 0) {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       return;
+               }
+       }
+}
+
+void _cal_server_ipc_db_insert_record(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_record_h record = NULL;
+       int id = 0;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_record(indata,&record);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_record fail");
+                       record = NULL;
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_insert_record(record, &id);
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (ret == CALENDAR_ERROR_NONE)
+               {
+                       int transaction_ver = _cal_db_util_get_transaction_ver();
+                       if (_cal_ipc_marshal_int(transaction_ver,*outdata) != CALENDAR_ERROR_NONE)
+                       {
+                               pims_ipc_data_destroy(*outdata);
+                               *outdata = NULL;
+                               ERR("_cal_ipc_marshal fail");
+                               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                               goto ERROR_RETURN;
+                       }
+                       if (_cal_ipc_marshal_int(id,*outdata) != CALENDAR_ERROR_NONE)
+                       {
+                               pims_ipc_data_destroy(*outdata);
+                               *outdata = NULL;
+                               ERR("_cal_ipc_marshal fail");
+                               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                               goto ERROR_RETURN;
+                       }
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+
+DATA_FREE:
+       if (record)
+       {
+               calendar_record_destroy(record,true);
+       }
+       return;
+}
+
+void _cal_server_ipc_db_get_record(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char* view_uri = NULL;
+       int id = 0;
+       calendar_record_h record = NULL;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_char(indata,&view_uri);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_char fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata,&id);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_get_record(view_uri,id,&record);
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (ret == CALENDAR_ERROR_NONE) {
+                       if (_cal_ipc_marshal_record(record, *outdata) != CALENDAR_ERROR_NONE) {
+                               pims_ipc_data_destroy(*outdata);
+                               *outdata = NULL;
+                               ERR("_cal_ipc_marshal_record fail");
+                               goto DATA_FREE;
+                       }
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+       if (record)
+       {
+               calendar_record_destroy(record,true);
+       }
+       CAL_FREE(view_uri);
+       return;
+}
+
+void _cal_server_ipc_db_update_record(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_record_h record = NULL;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_record(indata,&record);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_record fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_update_record(record);
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (ret == CALENDAR_ERROR_NONE)
+               {
+                       int transaction_ver = _cal_db_util_get_transaction_ver();
+                       if (_cal_ipc_marshal_int(transaction_ver,*outdata) != CALENDAR_ERROR_NONE)
+                       {
+                               pims_ipc_data_destroy(*outdata);
+                               ERR("_cal_ipc_marshal fail");
+                               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                               goto DATA_FREE;
+                       }
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+       if (record)
+       {
+               calendar_record_destroy(record,true);
+       }
+       return;
+}
+
+void _cal_server_ipc_db_delete_record(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char* view_uri = NULL;
+       int id = 0;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_char(indata,&view_uri);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_record fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata,&id);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_delete_record(view_uri,id);
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (ret == CALENDAR_ERROR_NONE)
+               {
+                       int transaction_ver = _cal_db_util_get_transaction_ver();
+                       if (_cal_ipc_marshal_int(transaction_ver,*outdata) != CALENDAR_ERROR_NONE)
+                       {
+                               pims_ipc_data_destroy(*outdata);
+                               ERR("_cal_ipc_marshal fail");
+                               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                               goto DATA_FREE;
+                       }
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+
+       CAL_FREE(view_uri);
+       return;
+}
+
+void _cal_server_ipc_db_get_all_records(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char* view_uri = NULL;
+       int offset = 0;
+       int limit = 0;
+       calendar_list_h list = NULL;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_char(indata,&view_uri);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_record fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata,&offset);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata,&limit);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_get_all_records(view_uri,offset,limit,&list);
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto DATA_FREE;
+               }
+               ret = _cal_ipc_marshal_list(list,*outdata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+
+       if (list)
+       {
+               calendar_list_destroy(list,true);
+       }
+       CAL_FREE(view_uri);
+       return;
+}
+
+void _cal_server_ipc_db_get_records_with_query(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_query_h query = NULL;
+       int offset = 0;
+       int limit = 0;
+       calendar_list_h list = NULL;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_query(indata,&query);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_record fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata,&offset);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata,&limit);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_get_records_with_query(query,offset,limit,&list);
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto DATA_FREE;
+               }
+               ret = _cal_ipc_marshal_list(list,*outdata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+
+       if (list)
+       {
+               calendar_list_destroy(list,true);
+       }
+       if (query)
+       {
+               calendar_query_destroy(query);
+       }
+       return;
+}
+
+void _cal_server_ipc_db_clean_after_sync(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       int calendar_book_id = 0;
+       int calendar_db_version = 0;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_int(indata,&calendar_book_id);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata,&calendar_db_version);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_clean_after_sync(calendar_book_id, calendar_db_version);
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       return;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       return;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+
+       return;
+}
+
+void _cal_server_ipc_db_get_count(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char* view_uri = NULL;
+       int count = 0;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_char(indata,&view_uri);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_record fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_get_count(view_uri,&count);
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       goto DATA_FREE;
+               }
+               ret = _cal_ipc_marshal_int(count,*outdata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+       CAL_FREE(view_uri);
+       return;
+}
+
+void _cal_server_ipc_db_get_count_with_query(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_query_h query = NULL;
+       int count = 0;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_query(indata,&query);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_record fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_get_count_with_query(query,&count);
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (CALENDAR_ERROR_NONE != ret) {
+                       goto DATA_FREE;
+               }
+               ret = _cal_ipc_marshal_int(count,*outdata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+       if (query)
+       {
+               calendar_query_destroy(query);
+       }
+       return;
+}
+
+void _cal_server_ipc_db_insert_records(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_list_h list = NULL;
+       int id_count = 0;
+       int *ids = NULL;
+       int i=0;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_list(indata,&list);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_list fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_insert_records(list, &ids, &id_count);
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if(ret == CALENDAR_ERROR_NONE)
+               {
+                       int transaction_ver = _cal_db_util_get_transaction_ver();
+                       if (_cal_ipc_marshal_int(transaction_ver,*outdata) != CALENDAR_ERROR_NONE)
+                       {
+                               pims_ipc_data_destroy(*outdata);
+                               ERR("_cal_ipc_marshal fail");
+                               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                               goto ERROR_RETURN;
+                       }
+                       // marshal : id_count+[ids]*id_count
+                       // id_count
+                       if (pims_ipc_data_put(*outdata,(void*)&id_count,sizeof(int)) != 0)
+                       {
+                               pims_ipc_data_destroy(*outdata);
+                               *outdata = NULL;
+                               ERR("pims_ipc_data_put fail");
+                               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+                               goto ERROR_RETURN;
+                       }
+
+                       for(i=0;i<id_count;i++)
+                       {
+                               // marshal ids
+                               if (pims_ipc_data_put(*outdata,(void*)&ids[i],sizeof(int)) != 0)
+                               {
+                                       pims_ipc_data_destroy(*outdata);
+                                       *outdata = NULL;
+                                       ERR("pims_ipc_data_put fail");
+                                       ret = CALENDAR_ERROR_INVALID_PARAMETER;
+                                       goto ERROR_RETURN;
+                               }
+                       }
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+       if (list)
+       {
+               calendar_list_destroy(list,true);
+       }
+       CAL_FREE(ids);
+       return;
+}
+
+void _cal_server_ipc_db_update_records(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       calendar_list_h list = NULL;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_list(indata,&list);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_list fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_update_records(list);
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (ret == CALENDAR_ERROR_NONE)
+               {
+                       int transaction_ver = _cal_db_util_get_transaction_ver();
+                       if (_cal_ipc_marshal_int(transaction_ver,*outdata) != CALENDAR_ERROR_NONE)
+                       {
+                               pims_ipc_data_destroy(*outdata);
+                               ERR("_cal_ipc_marshal fail");
+                               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                               goto DATA_FREE;
+                       }
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+       if (list)
+       {
+               calendar_list_destroy(list,true);
+       }
+       return;
+}
+
+void _cal_server_ipc_db_delete_records(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       int count = 0;
+       int *ids = NULL;
+       char *uri = NULL;
+       int i = 0;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_char(indata,&uri);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_char fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata,&count);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+               if (count <=0)
+               {
+                       goto ERROR_RETURN;
+               }
+               ids = (int*)malloc(sizeof(int)*count);
+               for(i=0;i<count;i++)
+               {
+                       ret = _cal_ipc_unmarshal_int(indata,&ids[i]);
+                       if (ret != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("_cal_ipc_unmarshal_int fail");
+                               goto ERROR_RETURN;
+                       }
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_delete_records(uri,ids,count);
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (ret == CALENDAR_ERROR_NONE)
+               {
+                       int transaction_ver = _cal_db_util_get_transaction_ver();
+                       if (_cal_ipc_marshal_int(transaction_ver,*outdata) != CALENDAR_ERROR_NONE)
+                       {
+                               pims_ipc_data_destroy(*outdata);
+                               ERR("_cal_ipc_marshal fail");
+                               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                               goto DATA_FREE;
+                       }
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+       CAL_FREE(uri);
+       CAL_FREE(ids);
+       return;
+}
+
+void _cal_server_ipc_db_get_changes_by_version(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char* view_uri = NULL;
+       int calendar_book_id = 0;
+       int calendar_db_version = 0;
+       calendar_list_h record_list = NULL;
+       int current_calendar_db_version = 0;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_char(indata,&view_uri);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_char fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata,&calendar_book_id);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata,&calendar_db_version);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_get_changes_by_version(view_uri,calendar_book_id,calendar_db_version,&record_list,&current_calendar_db_version);
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (CALENDAR_ERROR_NONE != ret) {
+                       goto DATA_FREE;
+               }
+               ret = _cal_ipc_marshal_list(record_list,*outdata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_marshal_list fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_marshal_int(current_calendar_db_version,*outdata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+       if (record_list)
+       {
+               calendar_list_destroy(record_list,true);
+       }
+       CAL_FREE(view_uri);
+       return;
+}
+
+void _cal_server_ipc_db_get_current_version(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       int calendar_db_version = 0;
+
+       ret = calendar_db_get_current_version(&calendar_db_version);
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       return;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       return;
+               }
+               if (ret == CALENDAR_ERROR_NONE) {
+                       ret = _cal_ipc_marshal_int(calendar_db_version,*outdata);
+                       if (ret != CALENDAR_ERROR_NONE) {
+                               ERR("_cal_ipc_marshal_int fail");
+                               return;
+                       }
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       return;
+}
+
+void _cal_server_ipc_db_insert_vcalendars(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char *stream = NULL;
+       int count = 0;
+       int *ids = NULL;
+       int i = 0;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_char(indata, &stream);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("unmarshal fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("db_insert_vcalendars fail.");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_insert_vcalendars(stream, &ids, &count);
+
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("calendar_db_insert_vcalendars fail");
+               goto ERROR_RETURN;
+       }
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               // return
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (ret == CALENDAR_ERROR_NONE)
+               {
+                       int transaction_ver = _cal_db_util_get_transaction_ver();
+                       if (_cal_ipc_marshal_int(transaction_ver,*outdata) != CALENDAR_ERROR_NONE)
+                       {
+                               pims_ipc_data_destroy(*outdata);
+                               *outdata = NULL;
+                               ERR("_cal_ipc_marshal fail");
+                               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                               goto ERROR_RETURN;
+                       }
+               }
+               // count
+               ret = _cal_ipc_marshal_int(count,*outdata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("_cal_ipc_marshal_list fail");
+                       goto ERROR_RETURN;
+               }
+               for(i=0;i<count;i++)
+               {
+                       ret = _cal_ipc_marshal_int(ids[i],*outdata);
+                       if (ret != CALENDAR_ERROR_NONE)
+                       {
+                               pims_ipc_data_destroy(*outdata);
+                               *outdata = NULL;
+                               ERR("_cal_ipc_marshal_list fail");
+                               goto ERROR_RETURN;
+                       }
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+       CAL_FREE(stream);
+       CAL_FREE(ids);
+       return;
+}
+
+void _cal_server_ipc_db_replace_vcalendars(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char *stream = NULL;
+       int count = 0;
+       int *ids = NULL;
+       int i = 0;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_char(indata, &stream);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("unmarshal fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata, &count);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("unmarshal fail");
+                       goto ERROR_RETURN;
+               }
+               ids = (int*)malloc(sizeof(int)*count);
+               if (ids == NULL)
+               {
+                       ERR("malloc fail");
+                       goto ERROR_RETURN;
+               }
+               for(i=0;i<count;i++)
+               {
+                       ret = _cal_ipc_unmarshal_int(indata, &ids[i]);
+                       if (ret != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("unmarshal fail");
+                               goto ERROR_RETURN;
+                       }
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("db_replace_vcalendars fail.");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_replace_vcalendars(stream, ids, count);
+
+       if (ret != CALENDAR_ERROR_NONE)
+       {
+               ERR("calendar_db_insert_vcalendars fail");
+               goto ERROR_RETURN;
+       }
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               // return
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (ret == CALENDAR_ERROR_NONE)
+               {
+                       int transaction_ver = _cal_db_util_get_transaction_ver();
+                       if (_cal_ipc_marshal_int(transaction_ver,*outdata) != CALENDAR_ERROR_NONE)
+                       {
+                               pims_ipc_data_destroy(*outdata);
+                               *outdata = NULL;
+                               ERR("_cal_ipc_marshal fail");
+                               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                               goto DATA_FREE;
+                       }
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+       CAL_FREE(stream);
+       CAL_FREE(ids);
+       return;
+}
+
+void _cal_server_ipc_db_replace_record(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       int id = 0;
+       calendar_record_h record = NULL;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_record(indata,&record);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_record fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata,&id);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_record fail");
+                       goto ERROR_RETURN;
+               }
+       }
+
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_replace_record(record, id);
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (ret == CALENDAR_ERROR_NONE)
+               {
+                       int transaction_ver = _cal_db_util_get_transaction_ver();
+                       if (_cal_ipc_marshal_int(transaction_ver,*outdata) != CALENDAR_ERROR_NONE)
+                       {
+                               pims_ipc_data_destroy(*outdata);
+                               *outdata = NULL;
+                               ERR("_cal_ipc_marshal fail");
+                               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                               goto DATA_FREE;
+                       }
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+       if (record)
+       {
+               calendar_record_destroy(record,true);
+       }
+       return;
+}
+
+void _cal_server_ipc_db_replace_records(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       int i;
+       int count = 0;
+       int *ids = NULL;
+       calendar_list_h list = NULL;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_list(indata,&list);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_list fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata, &count);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+               if (count <= 0)
+               {
+                       goto ERROR_RETURN;
+               }
+               ids = (int*)malloc(sizeof(int) * count);
+               for(i = 0; i < count; i++)
+               {
+                       ret = _cal_ipc_unmarshal_int(indata,&ids[i]);
+                       if (ret != CALENDAR_ERROR_NONE)
+                       {
+                               ERR("_cal_ipc_unmarshal_int fail");
+                               goto ERROR_RETURN;
+                       }
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_replace_records(list, ids, count);
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (ret == CALENDAR_ERROR_NONE)
+               {
+                       int transaction_ver = _cal_db_util_get_transaction_ver();
+                       if (_cal_ipc_marshal_int(transaction_ver,*outdata) != CALENDAR_ERROR_NONE)
+                       {
+                               pims_ipc_data_destroy(*outdata);
+                               *outdata = NULL;
+                               ERR("_cal_ipc_marshal fail");
+                               ret = CALENDAR_ERROR_OUT_OF_MEMORY;
+                               goto DATA_FREE;
+                       }
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+       CAL_FREE(ids);
+       if (list)
+       {
+               calendar_list_destroy(list,true);
+       }
+       return;
+}
+
+void _cal_server_ipc_db_changes_exception(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char* view_uri = NULL;
+       int original_event_id = 0;
+       int calendar_db_version = 0;
+       calendar_list_h record_list = NULL;
+
+       if (indata)
+       {
+               ret = _cal_ipc_unmarshal_char(indata,&view_uri);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_char fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata,&original_event_id);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+               ret = _cal_ipc_unmarshal_int(indata,&calendar_db_version);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_unmarshal_int fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ret = CALENDAR_ERROR_INVALID_PARAMETER;
+               ERR("_cal_server_ipc_db_insert_record fail");
+               goto ERROR_RETURN;
+       }
+
+       ret = calendar_db_get_changes_exception_by_version(view_uri,original_event_id,calendar_db_version,&record_list);
+
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+               if (CALENDAR_ERROR_NONE != ret) {
+                       goto DATA_FREE;
+               }
+               ret = _cal_ipc_marshal_list(record_list,*outdata);
+               if (ret != CALENDAR_ERROR_NONE)
+               {
+                       ERR("_cal_ipc_marshal_list fail");
+                       goto ERROR_RETURN;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+       goto DATA_FREE;
+
+ERROR_RETURN:
+       if (outdata)
+       {
+               *outdata = pims_ipc_data_create(0);
+               if (!*outdata)
+               {
+                       ERR("pims_ipc_data_create fail");
+                       goto DATA_FREE;
+               }
+               if (pims_ipc_data_put(*outdata,(void*)&ret,sizeof(int)) != 0)
+               {
+                       pims_ipc_data_destroy(*outdata);
+                       *outdata = NULL;
+                       ERR("pims_ipc_data_put fail");
+                       goto DATA_FREE;
+               }
+       }
+       else
+       {
+               ERR("outdata is NULL");
+       }
+DATA_FREE:
+       if (record_list)
+       {
+               calendar_list_destroy(record_list,true);
+       }
+       CAL_FREE(view_uri);
+       return;
+}
diff --git a/server/cal_server_ipc.h b/server/cal_server_ipc.h
new file mode 100644 (file)
index 0000000..e48ed6c
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+#ifndef __CAL_SERVER_IPC_H__
+#define __CAL_SERVER_IPC_H__
+
+#include <pims-ipc-data.h>
+
+// calendar_service.h
+void _cal_server_ipc_connect(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_disconnect(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_check_permission(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+
+// calendar_db.h
+void _cal_server_ipc_db_insert_record(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_get_record(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_update_record(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_delete_record(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_get_all_records(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_get_records_with_query(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_clean_after_sync(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_get_count(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_get_count_with_query(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_insert_records(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_update_records(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_delete_records(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_get_changes_by_version(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_get_current_version(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_insert_vcalendars(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_replace_vcalendars(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_replace_record(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_replace_records(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+void _cal_server_ipc_db_changes_exception(pims_ipc_h ipc, pims_ipc_data_h indata, pims_ipc_data_h *outdata, void *userdata);
+
+#endif /*__CAL_SERVER_IPC_H__*/
diff --git a/server/cal_server_reminder.c b/server/cal_server_reminder.c
new file mode 100644 (file)
index 0000000..20dec7c
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#include <stdlib.h>
+#include <pims-ipc-svc.h>
+
+#include "calendar.h"
+#include "cal_internal.h" // DBG
+#include "cal_typedef.h"
+#include "cal_db.h"
+#include "cal_db_util.h"
+#include "cal_ipc.h"
+#include "cal_ipc_marshal.h"
+#include "cal_server_ipc.h"
+
+#define CAL_SUBSCRIBE_MAX_LEN 1024
+
+static gboolean __cal_server_reminder_publish_changes_with_data(char *data, int len)
+{
+       pims_ipc_data_h indata = NULL;
+       if (NULL == data)
+       {
+               ERR("Invalid parameter: data is NULL");
+               return true;
+       }
+
+       indata = pims_ipc_data_create(0);
+       if (NULL == indata)
+       {
+               ERR("pims_ipc_data_create() failed");
+               return false;
+       }
+       if (pims_ipc_data_put(indata, &len, sizeof(int)) != 0)
+       {
+               ERR("pims_ipc_data_put() failed");
+               pims_ipc_data_destroy(indata);
+               return false;
+       }
+       if (pims_ipc_data_put(indata, data, strlen(data) + 1) != 0)
+       {
+               ERR("pims_ipc_data_put() failed");
+               pims_ipc_data_destroy(indata);
+               return false;
+       }
+       if (pims_ipc_svc_publish(CAL_IPC_MODULE_FOR_SUBSCRIPTION, (char *)CAL_NOTI_REMINDER_CAHNGED, indata) != 0)
+       {
+               ERR("pims_ipc_svc_publish() failed");
+               pims_ipc_data_destroy(indata);
+               return false;
+       }
+       pims_ipc_data_destroy(indata);
+       return true;
+}
+
+void _cal_server_reminder_publish(char *p)
+{
+       retm_if (NULL == p, "Invalid parameter: p is NULL");
+       __cal_server_reminder_publish_changes_with_data(p, strlen(p));
+}
+
+int _cal_server_reminder_add_callback_data(char **p, char *key, char *value)
+{
+       int len_key = 0;
+       int len_value = 0;
+
+       if (NULL == key || NULL == value)
+       {
+               ERR("Invalid parameter");
+               return CALENDAR_ERROR_INVALID_PARAMETER;
+       }
+
+       len_key = strlen(key);
+       len_value = strlen(value);
+       DBG("key[%s]value[%s]", key, value);
+
+       if (NULL == *p)
+       {
+               int len = len_key + len_value + 2;
+               *p = calloc(len, sizeof(char));
+               if (NULL == *p) {
+                       ERR("calloc() failed");
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+               snprintf(*p, len, "%s=%s", key, value);
+
+       } else {
+               int len = strlen(*p) + len_key + len_value + 3;
+               char *temp = calloc(len, sizeof(char));
+               if (NULL == temp) {
+                       ERR("recalloc() failed");
+                       return CALENDAR_ERROR_DB_FAILED;
+               }
+               snprintf(temp, len, "%s&%s=%s", *p, key, value);
+               free(*p);
+               *p = temp;
+       }
+       return CALENDAR_ERROR_NONE;
+}
+
diff --git a/server/cal_server_reminder.h b/server/cal_server_reminder.h
new file mode 100644 (file)
index 0000000..590a3d6
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CAL_SERVER_REMINDER_H__
+#define __CAL_SERVER_REMINDER_H__
+
+void _cal_server_reminder_publish(char *p);
+int _cal_server_reminder_add_callback_data(char **p, char *key, char *value);
+
+#endif  //__CAL_SERVER_REMINDER_H__
diff --git a/server/cal_server_schema.c b/server/cal_server_schema.c
new file mode 100644 (file)
index 0000000..fd65fb4
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <sqlite3.h>
+#include <db-util.h>
+
+#include "cal_internal.h"
+#include "schema.h"
+
+#define CALS_DB_NAME ".calendar-svc.db"
+#define CALS_DB_JOURNAL_NAME ".calendar-svc.db-journal"
+#define CALS_DB_PATH "/opt/usr/dbspace/"CALS_DB_NAME
+#define CALS_DB_JOURNAL_PATH "/opt/usr/dbspace/"CALS_DB_JOURNAL_NAME
+
+// For Security
+#define CALS_SECURITY_FILE_GROUP 5000
+#define CALS_SECURITY_DEFAULT_PERMISSION 0660
+#define CALS_SECURITY_DIR_DEFAULT_PERMISSION 0770
+
+static inline int __remake_db_file(char* db_path)
+{
+       int ret, fd;
+       char *errmsg;
+       sqlite3 *db;
+       char db_file[256]={0,};
+       char db_journal_file[256]={0,};
+
+       if(db_path == NULL)
+       {
+               snprintf(db_file,sizeof(db_file),CALS_DB_PATH);
+               snprintf(db_journal_file,sizeof(db_journal_file),CALS_DB_JOURNAL_PATH);
+       }
+       else
+       {
+               snprintf(db_file,sizeof(db_file),"%s%s",db_path, CALS_DB_NAME);
+               snprintf(db_journal_file,sizeof(db_journal_file),"%s%s", db_path, CALS_DB_JOURNAL_NAME);
+       }
+
+       ret = db_util_open(db_file, &db, 0);
+
+       if (SQLITE_OK != ret)
+       {
+               ERR("db_util_open() Failed(%d) ", ret);
+               return -1;
+       }
+
+       ret = sqlite3_exec(db, schema_query, NULL, 0, &errmsg);
+       if (SQLITE_OK != ret) {
+               ERR("remake calendar DB file is Failed : %s ", errmsg);
+               sqlite3_free(errmsg);
+       }
+
+       db_util_close(db);
+
+       fd = open(db_file, O_CREAT | O_RDWR, 0660);
+       if (-1 == fd)
+       {
+               ERR("open Failed ");
+               return -1;
+       }
+
+       ret = fchown(fd, getuid(), CALS_SECURITY_FILE_GROUP);
+       if (-1 == ret)
+       {
+               ERR("Failed to fchown ");
+               close(fd);
+               return -1;
+       }
+       fchmod(fd, CALS_SECURITY_DEFAULT_PERMISSION);
+       close(fd);
+
+       fd = open(db_journal_file, O_CREAT | O_RDWR, 0660);
+
+       if (-1 == fd)
+       {
+               ERR("open Failed ");
+               return -1;
+       }
+
+       ret = fchown(fd, getuid(), CALS_SECURITY_FILE_GROUP);
+       if (-1 == ret)
+       {
+               ERR("Failed to fchown ");
+               close(fd);
+               return -1;
+       }
+       fchmod(fd, CALS_SECURITY_DEFAULT_PERMISSION);
+       close(fd);
+
+       return 0;
+}
+
+static inline int __check_db_file(char* db_path)
+{
+       int fd = -1;
+
+       char db_file[256]={0,};
+       if(db_path == NULL)
+       {
+               snprintf(db_file,sizeof(db_file),CALS_DB_PATH);
+       }
+       else
+       {
+               snprintf(db_file,sizeof(db_file),"%s%s",db_path, CALS_DB_NAME);
+       }
+
+       fd = open(db_file, O_RDONLY);
+       if (fd < 0)
+       {
+               ERR("DB file(%s) is not exist(err:%d) ", db_file, fd);
+               return -1;
+       }
+       close(fd);
+       return 0;
+}
+
+int _cal_server_schema_check(void)
+{
+       if (__check_db_file(NULL))
+               __remake_db_file(NULL);
+       return 0;
+}
diff --git a/server/cal_server_schema.h b/server/cal_server_schema.h
new file mode 100644 (file)
index 0000000..3ba809a
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CAL_SERVER_SCHEMA_H__
+#define __CAL_SERVER_SCHEMA_H__
+
+int _cal_server_schema_check(void);
+
+#endif // __CAL_SERVER_SCHEMA_H__
diff --git a/server/cal_server_update.c b/server/cal_server_update.c
new file mode 100644 (file)
index 0000000..32990e2
--- /dev/null
@@ -0,0 +1,296 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <sqlite3.h>
+#include <db-util.h>
+#include <stdlib.h>
+
+#include "cal_internal.h"
+#include "cal_typedef.h"
+#include "cal_db.h"
+
+#define __USER_VERSION 105
+
+static int __cal_server_update_get_db_version(sqlite3 *db, int *version)
+{
+       int ret = CALENDAR_ERROR_NONE;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+       sqlite3_stmt *stmt = NULL;
+
+       snprintf(query, sizeof(query), "PRAGMA user_version;");
+       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
+       if (SQLITE_OK != ret)
+       {
+               ERR("sqlite3_prepare_v2() failed[%s]", sqlite3_errmsg(db));
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       ret = sqlite3_step(stmt);
+       if (SQLITE_ROW != ret)
+       {
+               ERR("sqlite3_step() failed[%s]", sqlite3_errmsg(db));
+               sqlite3_finalize(stmt);
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       if (version) *version = (int)sqlite3_column_int(stmt, 0);
+       sqlite3_finalize(stmt);
+       return CALENDAR_ERROR_NONE;
+}
+
+int _cal_server_update(void)
+{
+       ENTER();
+
+       int ret = CALENDAR_ERROR_NONE;
+       int old_version = 0;
+       char *errmsg = NULL;
+       sqlite3 *__db;
+       char query[CAL_DB_SQL_MAX_LEN] = {0};
+
+       ret = db_util_open(CAL_DB_PATH, &__db, 0);
+       if (SQLITE_OK != ret)
+       {
+               ERR("db_util_open() failed");
+               return CALENDAR_ERROR_DB_FAILED;
+       }
+       __cal_server_update_get_db_version(__db, &old_version);
+       DBG("old version(%d)", old_version);
+
+       if (old_version < 100)
+       {
+               /* ----------------------- start modified 2013/08/22
+                * added attendee_table(cutype, delegatee_uri, member), alarm_table(summary, action, attach).
+                */
+               ret = sqlite3_exec(__db, "DROP VIEW event_calendar_attendee_view", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret)
+               {
+                       ERR("sqlite3_exec() failed: DROP VIEW event_calendar_attendee_view(%d) [%s]", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+
+               ret = sqlite3_exec(__db, "ALTER TABLE attendee_table ADD COLUMN attendee_cutype INTEGER", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret)
+               {
+                       ERR("sqlite3_exec() failed: ALTER TABLE attendee_table ADD COLUMN attendee_cutype(%d) [%s]", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               ret = sqlite3_exec(__db, "ALTER TABLE attendee_table ADD COLUMN attendee_delegatee_uri TEXT", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret)
+               {
+                       ERR("sqlite3_exec() failed: ALTER TABLE attendee_table ADD COLUMN attendee_delegatee_uri(%d) [%s]", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               ret = sqlite3_exec(__db, "ALTER TABLE attendee_table ADD COLUMN attendee_member TEXT", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret)
+               {
+                       ERR("sqlite3_exec() failed: ALTER TABLE attendee_table ADD COLUMN attendee_member(%d) [%s]", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+
+               ret = sqlite3_exec(__db, "ALTER TABLE alarm_table ADD COLUMN alarm_summary TEXT", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret)
+               {
+                       ERR("sqlite3_exec() failed: ALTER TABLE alarm_table ADD COLUMN alarm_summary(%d) [%s]", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               ret = sqlite3_exec(__db, "ALTER TABLE alarm_table ADD COLUMN alarm_action INTEGER", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret)
+               {
+                       ERR("sqlite3_exec() failed: ALTER TABLE alarm_table ADD COLUMN alarm_action(%d) [%s]", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               ret = sqlite3_exec(__db, "ALTER TABLE alarm_table ADD COLUMN alarm_attach TEXT", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret)
+               {
+                       ERR("sqlite3_exec() failed: ALTER TABLE alarm_table ADD COLUMN alarm_attach(%d) [%s]", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               old_version = 100;
+               /* ----------------------- end modified 2013/08/22
+                */
+       }
+       if (old_version == 100)
+       {
+               /* ----------------------- start modified 2013/09/22
+                * added schedule_table(freq) for view table parameter.
+                */
+               ret = sqlite3_exec(__db, "ALTER TABLE schedule_table ADD COLUMN freq INTEGER DEFAULT 0", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret)
+               {
+                       ERR("sqlite3_exec() failed: ALTER TABLE schedule_table ADD COLUMN freq(%d) [%s]", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               old_version = 101;
+               /* ----------------------- end modified 2013/09/22
+                */
+       }
+       if (old_version == 101)
+       {
+               /* ----------------------- start modified 2014/07/02
+                * added trigger depeding on schedule_table
+                * added original_event_id in deleted_table to check exception event.
+                */
+
+               // rename trig -> trg
+               ret = sqlite3_exec(__db, "DROP TRIGGER trig_original_mod", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret) {
+                       ERR("DROP TRIGGER trig_original_mod failed(%d:%s)", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               ret = sqlite3_exec(__db,
+                               "CREATE TRIGGER trg_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;",
+                               NULL, 0, &errmsg);
+               if (SQLITE_OK != ret) {
+                       ERR("CREATE TRIGGER trg_original_mod failed(%d:%s)", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+
+               // rename trg_sch_del -> trg_schedule_del
+               ret = sqlite3_exec(__db, "DROP TRIGGER trg_sch_del", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret) {
+                       ERR("DROP TRIGGER trg_sch_del failed(%d:%s)", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               ret = sqlite3_exec(__db,
+                               "CREATE TRIGGER trg_schedule_del AFTER DELETE ON schedule_table "
+                               "BEGIN "
+                               "  DELETE FROM rrule_table WHERE event_id = old.id;"
+                               "  DELETE FROM alarm_table WHERE event_id = old.id;"
+                               "  DELETE FROM schedule_table WHERE original_event_id = old.id;"
+                               "  DELETE FROM normal_instance_table WHERE event_id = old.id;"
+                               "  DELETE FROM allday_instance_table WHERE event_id = old.id;"
+                               "  DELETE FROM attendee_table WHERE event_id = old.id;"
+                               "  DELETE FROM extended_table WHERE record_id = old.id AND record_type = 2;"
+                               "  DELETE FROM extended_table WHERE record_id = old.id AND record_type = 3;"
+                               "END;",
+                               NULL, 0, &errmsg);
+               if (SQLITE_OK != ret) {
+                       ERR("CREATE TRIGGER trg_schedule_del failed(%d:%s)", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+
+               // add trigger
+               ret = sqlite3_exec(__db,
+                               "CREATE TRIGGER trg_schedule_del2 AFTER DELETE ON schedule_table "
+                               " WHEN old.is_deleted = 0 AND old.calendar_id = (SELECT id FROM calendar_table WHERE id = old.calendar_id) "
+                               " BEGIN "
+                               "   INSERT INTO deleted_table VALUES(old.id, old.type + 1, old.calendar_id, (SELECT ver FROM version_table) + 1, old.created_ver, old.original_event_id);"
+                               " END;",
+                               NULL, 0, &errmsg);
+               if (SQLITE_OK != ret) {
+                       ERR("CREATE TRIGGER trg_schedule_del2 failed(%d:%s)", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+
+               // add trigger
+               ret = sqlite3_exec(__db,
+                               "CREATE TRIGGER trg_schedule_del3 AFTER DELETE ON schedule_table "
+                               " WHEN old.is_deleted = 1 AND old.calendar_id = (SELECT id FROM calendar_table WHERE id = old.calendar_id) "
+                               " BEGIN "
+                               "   INSERT INTO deleted_table VALUES(old.id, old.type + 1, old.calendar_id, old.changed_ver, old.created_ver, old.original_event_id);"
+                               " END;",
+                               NULL, 0, &errmsg);
+               if (SQLITE_OK != ret) {
+                       ERR("CREATE TRIGGER trg_schedule_del3 failed(%d:%s)", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+
+               // add field: original_event_id in deleted_table
+               ret = sqlite3_exec(__db, "ALTER TABLE deleted_table ADD COLUMN original_event_id INTEGER", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret) {
+                       ERR("ALTER TABLE deleted_table failed(%d:%s)", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               /* ----------------------- end modified 2014/07/02
+                */
+               old_version = 102;
+       }
+       if (old_version == 102)
+       {
+               /* ----------------------- start modified 2014/10/24
+                * added field is_alldy on schedule_table
+                */
+
+               // add field: is_allday in deleted_table
+               ret = sqlite3_exec(__db, "ALTER TABLE schedule_table ADD COLUMN is_allday INTEGER DEFAULT 0", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret) {
+                       ERR("ALTER TABLE schedule_table failed(%d:%s)", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               /* ----------------------- end modified 2014/10/24
+                */
+               old_version = 103;
+       }
+
+       if (old_version == 103)
+       {
+               ret = sqlite3_exec(__db, "DROP TABLE reminder_table", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret) {
+                       ERR("DROP TABLE reminder_table failed(%d:%s)", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               old_version = 104;
+       }
+       if (old_version == 104)
+       {
+               ret = sqlite3_exec(__db, "ALTER TABLE alarm_table ADD COLUMN alarm_utime INTEGER", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret) {
+                       ERR("ALTER TABLE schedule_table failed(%d:%s)", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               ret = sqlite3_exec(__db, "ALTER TABLE alarm_table ADD COLUMN alarm_datetime DATE", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret) {
+                       ERR("ALTER TABLE schedule_table failed(%d:%s)", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               ret = sqlite3_exec(__db, "DROP VIEW allday_instance_view", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret)
+               {
+                       ERR("sqlite3_exec() failed: DROP VIEW allday_instance_view(%d) [%s]", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               ret = sqlite3_exec(__db, "DROP VIEW allday_instance_view_extended", NULL, 0, &errmsg);
+               if (SQLITE_OK != ret)
+               {
+                       ERR("sqlite3_exec() failed: DROP VIEW allday_instance_view_extended(%d) [%s]", ret, errmsg);
+                       sqlite3_free(errmsg);
+               }
+               old_version = 105;
+       }
+
+       // update DB user_version
+       snprintf(query, sizeof(query), "PRAGMA user_version = %d", __USER_VERSION);
+       ret = sqlite3_exec(__db, query, NULL, 0, &errmsg);
+       if (SQLITE_OK != ret)
+       {
+               ERR("sqlite3_exec() failed(%d) [%s]", ret, errmsg);
+               sqlite3_free(errmsg);
+       }
+       db_util_close(__db);
+       __db = NULL;
+
+       LEAVE();
+       return CALENDAR_ERROR_NONE;
+}
+
+
diff --git a/server/cal_server_update.h b/server/cal_server_update.h
new file mode 100644 (file)
index 0000000..768e8c6
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Calendar Service
+ *
+ * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __CAL_SERVER_UPDATE_H__
+#define __CAL_SERVER_UPDATE_H__
+
+int _cal_server_update(void);
+
+#endif  //__CAL_SERVER_UPDATE_H__
diff --git a/src/cals-alarm.c b/src/cals-alarm.c
deleted file mode 100755 (executable)
index bca858e..0000000
+++ /dev/null
@@ -1,372 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <stdlib.h>
-#include <errno.h>
-#include <alarm.h>
-#include <appsvc.h>
-
-#include "cals-internal.h"
-#include "cals-typedef.h"
-#include "cals-db-info.h"
-#include "cals-sqlite.h"
-#include "cals-utils.h"
-#include "cals-alarm.h"
-#include "cals-time.h"
-
-#define PKG_CALENDAR_APP "org.tizen.calendar"
-
-
-int cals_alarm_remove(int type, int related_id)
-{
-       int ret;
-       sqlite3_stmt *stmt = NULL;
-       char query[CALS_SQL_MAX_LEN] = {0};
-
-       switch (type) {
-       case CALS_ALARM_REMOVE_BY_EVENT_ID:
-               sprintf(query, "SELECT alarm_id FROM %s "
-                       "WHERE event_id = %d AND alarm_id <> 0", CALS_TABLE_ALARM, related_id);
-               break;
-       case CALS_ALARM_REMOVE_BY_CALENDAR_ID:
-               sprintf(query, "SELECT alarm_id FROM %s A, %s B ON A.id = B.event_id "
-                       "WHERE A.calendar_id = %d AND B.alarm_id <> 0",
-                       CALS_TABLE_SCHEDULE, CALS_TABLE_ALARM, related_id);
-               break;
-       case CALS_ALARM_REMOVE_BY_ACC_ID:
-               sprintf(query, "SELECT alarm_id FROM %s A, %s B ON A.id = B.event_id "
-                       "WHERE A.account_id = %d AND B.alarm_id <> 0",
-                       CALS_TABLE_SCHEDULE, CALS_TABLE_ALARM, related_id);
-               break;
-       case CALS_ALARM_REMOVE_ALL:
-               sprintf(query, "SELECT alarm_id FROM %s WHERE alarm_id <> 0", CALS_TABLE_ALARM);
-               break;
-       }
-
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       ret = cals_stmt_step(stmt);
-       if (ret < CAL_SUCCESS) {
-               sqlite3_finalize(stmt);
-               ERR("sqlite3_step() Failed(%d)", ret);
-               return CAL_ERR_DB_FAILED;
-       }
-
-       while (CAL_TRUE == ret) {
-               alarmmgr_remove_alarm(sqlite3_column_int(stmt,0));
-               ret = cals_stmt_step(stmt);
-       }
-       sqlite3_finalize(stmt);
-
-       // TODO: If calendar service use delete_table not delete_flag, below procedure can handle by trigger.
-       switch (type) {
-       case CALS_ALARM_REMOVE_BY_EVENT_ID:
-               sprintf(query, "DELETE FROM %s WHERE event_id = %d", CALS_TABLE_ALARM, related_id);
-               break;
-       case CALS_ALARM_REMOVE_BY_CALENDAR_ID:
-               sprintf(query, "DELETE FROM %s "
-                       "WHERE event_id IN (SELECT id FROM %s WHERE calendar_id = %d)",
-                       CALS_TABLE_ALARM, CALS_TABLE_SCHEDULE, related_id);
-               break;
-       case CALS_ALARM_REMOVE_BY_ACC_ID:
-               sprintf(query, "DELETE FROM %s "
-                       "WHERE event_id IN (SELECT id FROM %s WHERE account_id = %d)",
-                       CALS_TABLE_ALARM, CALS_TABLE_SCHEDULE, related_id);
-               break;
-       case CALS_ALARM_REMOVE_ALL:
-               sprintf(query, "DELETE FROM %s", CALS_TABLE_ALARM);
-               break;
-       }
-
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       ret = cals_stmt_step(stmt);
-       if (CAL_SUCCESS != ret) {
-               sqlite3_finalize(stmt);
-               ERR("sqlite3_step(%s) Failed(%d)", query, ret);
-               return CAL_ERR_DB_FAILED;
-       }
-       sqlite3_finalize(stmt);
-
-       return CAL_SUCCESS;
-}
-
-int _cals_alarm_add_to_db(const int event_id, cal_alarm_info_t *alarm_info)
-{
-       CALS_FN_CALL;
-       int r;
-       sqlite3_stmt *stmt = NULL;
-       char query[CALS_SQL_MAX_LEN] = {0};
-
-       sprintf(query, "INSERT INTO %s ("
-                       "event_id, "
-                       "alarm_time, remind_tick, remind_tick_unit, alarm_tone, "
-                       "alarm_description, alarm_type, alarm_id "
-                       ") VALUES ( "
-                       "%d, "
-                       "%lld, %d, %d, ?, "
-                       "?, %d, %d )",
-                       CALS_TABLE_ALARM,
-                       event_id,
-                       alarm_info->alarm_time, alarm_info->remind_tick, alarm_info->remind_tick_unit,
-                       alarm_info->alarm_type, alarm_info->alarm_id);
-
-       DBG("query(%s)\n", query);
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       if (alarm_info->alarm_tone)
-               cals_stmt_bind_text(stmt, 1, alarm_info->alarm_tone);
-
-       if (alarm_info->alarm_description)
-               cals_stmt_bind_text(stmt, 2, alarm_info->alarm_description);
-
-       r = cals_stmt_step(stmt);
-       sqlite3_finalize(stmt);
-
-       if (CAL_SUCCESS != r) {
-               ERR("cals_stmt_step() Failed(%d)", r);
-               return r;
-       }
-
-       return CAL_SUCCESS;
-}
-
-static long long int _cals_get_interval(cal_alarm_info_t *alarm_info, struct cals_time *start_time)
-{
-       long long int iv, diff;
-       int sec;
-       struct cals_time at;
-
-       if (alarm_info->remind_tick_unit == CAL_SCH_TIME_UNIT_SPECIFIC) {
-               at.type = CALS_TIME_UTIME;
-               at.utime = alarm_info->alarm_time;
-               return cals_time_diff_with_now(&at);
-       }
-
-       switch (alarm_info->remind_tick_unit) {
-       case CAL_SCH_TIME_UNIT_MIN:
-               sec = 60;
-               break;
-       case CAL_SCH_TIME_UNIT_HOUR:
-               sec = 3600;
-               break;
-       case CAL_SCH_TIME_UNIT_DAY:
-               sec = ONE_DAY_SECONDS;
-               break;
-       case CAL_SCH_TIME_UNIT_WEEK:
-               sec = ONE_WEEK_SECONDS;
-               break;
-       case CAL_SCH_TIME_UNIT_MONTH:
-               sec = ONE_MONTH_SECONDS;
-               break;
-       case CAL_SCH_TIME_UNIT_OFF:
-       default:
-               return 0;
-       }
-
-       sec = sec * alarm_info->remind_tick;
-       if (start_time->type == CALS_TIME_UTIME) {
-               alarm_info->alarm_time = start_time->utime - sec;
-
-       } else {
-               alarm_info->alarm_time = cals_time_convert_to_lli(start_time) - sec;
-
-       }
-
-       diff =  cals_time_diff_with_now(start_time);
-       iv = diff - (long long int)sec;
-       DBG("tick(%d) tick unit(%d) "
-                       ",so sets (%lld) = diff(%lld) - sec(%lld)",
-                       alarm_info->remind_tick, alarm_info->remind_tick_unit,
-                       iv, diff, (long long int)sec);
-
-       return iv;
-}
-
-bundle *_get_appsvc(const char *pkg)
-{
-       int r;
-       bundle *b;
-
-       b = bundle_create();
-       if (!b) {
-               ERR("bundle_create failed");
-               return NULL;
-       }
-
-       r = appsvc_set_pkgname(b, pkg);
-       appsvc_set_operation(b, APPSVC_OPERATION_DEFAULT);
-       if (r) {
-               bundle_free(b);
-               ERR("appsvc_set_pkgname failed (%d)", r);
-               return NULL;
-       }
-
-       return b;
-}
-
-int _cals_alarm_add_to_alarmmgr(struct cals_time *start_time, cal_alarm_info_t *alarm_info)
-{
-       int ret;
-       long long int iv;
-       bundle *b;
-       alarm_id_t alarm_id = 0;
-
-       iv = _cals_get_interval(alarm_info, start_time);
-       if (iv < 0) {
-               DBG("Tried to register past event, so passed registration");
-               return 0;
-
-       } else if (iv == 0) {
-               DBG("Set no alarm");
-               return 0;
-       }
-
-       b = _get_appsvc(PKG_CALENDAR_APP);
-       if (!b) {
-               ERR("_get_appsvc failed");
-               return CAL_ERR_FAIL;
-       }
-
-       ret = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, (long int)iv, 0, b, &alarm_id);
-       bundle_free(b);
-
-       if (ret) {
-               ERR("alarmmgr_add_alarm_appsvc failed (%d)", ret);
-               return CAL_ERR_ALARMMGR_FAILED;
-       }
-       DBG("Set alarm id(%d)", alarm_id);
-       alarm_info->alarm_id = alarm_id;
-
-       return 0;
-}
-
-int cals_alarm_add(int event_id, cal_alarm_info_t *alarm_info, struct cals_time *start_time)
-{
-       CALS_FN_CALL;
-       int ret;
-
-       if(alarm_info->remind_tick_unit == CAL_SCH_TIME_UNIT_OFF)
-               return CAL_SUCCESS;
-
-       ret = _cals_alarm_add_to_alarmmgr(start_time, alarm_info);
-       if (ret) {
-               ERR("Failed to register alarm");
-               return CAL_ERR_FAIL;
-       }
-
-       ret = _cals_alarm_add_to_db(event_id, alarm_info);
-       if (ret) {
-               ERR("Failed to add alarm to db");
-               return CAL_ERR_FAIL;
-       }
-
-       return CAL_SUCCESS;
-}
-
-
-int cals_alarm_get_event_id(int alarm_id)
-{
-       char query[CALS_SQL_MIN_LEN];
-
-       sprintf(query, "SELECT event_id FROM %s WHERE alarm_id=%d", CALS_TABLE_ALARM, alarm_id);
-
-       return cals_query_get_first_int_result(query);
-}
-
-
-static void _cals_alarm_value_free(gpointer data, gpointer user_data)
-{
-       if (NULL == data)
-               return;
-
-       free(((cal_alarm_info_t*)((cal_value*)data)->user_data)->alarm_tone);
-       free(((cal_alarm_info_t*)((cal_value*)data)->user_data)->alarm_description);
-       free(data);
-}
-
-
-int cals_get_alarm_info(const int event_id, GList **alarm_list)
-{
-       int ret = -1;
-       GList *result = NULL;
-       sqlite3_stmt *stmt = NULL;
-       cal_value * cvalue = NULL;
-       char query[CALS_SQL_MAX_LEN] = {0};
-       cal_alarm_info_t* alarm_info = NULL;
-
-       retv_if(NULL == alarm_list, CAL_ERR_ARG_NULL);
-
-       sprintf(query, "SELECT * FROM %s WHERE event_id=%d", CALS_TABLE_ALARM, event_id);
-
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       ret = cals_stmt_step(stmt);
-       if (ret < CAL_SUCCESS) {
-               sqlite3_finalize(stmt);
-               ERR("cals_stmt_step() Failed(%d)", ret);
-               return ret;
-       }
-
-       while (CAL_TRUE == ret)
-       {
-               cvalue = calloc(1, sizeof(cal_value));
-               if (NULL == cvalue) {
-                       sqlite3_finalize(stmt);
-                       g_list_foreach(result, _cals_alarm_value_free, NULL);
-                       g_list_free(result);
-                       ERR("calloc() Failed(%d)", errno);
-                       return CAL_ERR_OUT_OF_MEMORY;
-               }
-
-               cvalue->v_type = CAL_EVENT_ALARM;
-               cvalue->user_data = alarm_info = calloc(1, sizeof(cal_alarm_info_t));
-               if (NULL == alarm_info) {
-                       sqlite3_finalize(stmt);
-                       g_list_foreach(result, _cals_alarm_value_free, NULL);
-                       g_list_free(result);
-                       free(cvalue);
-                       ERR("calloc() Failed(%d)", errno);
-                       return CAL_ERR_OUT_OF_MEMORY;
-               }
-
-               alarm_info->event_id = sqlite3_column_int(stmt, 0);
-
-               alarm_info->alarm_time = sqlite3_column_int64(stmt, 1);
-               alarm_info->remind_tick = sqlite3_column_int(stmt, 2);
-               alarm_info->remind_tick_unit = sqlite3_column_int(stmt, 3);
-               alarm_info->alarm_tone = SAFE_STRDUP(sqlite3_column_text(stmt, 4));
-               alarm_info->alarm_description = SAFE_STRDUP(sqlite3_column_text(stmt, 5));
-               alarm_info->alarm_type = sqlite3_column_int(stmt, 6);
-               alarm_info->alarm_id = sqlite3_column_int(stmt, 7);
-
-               result = g_list_append(result, cvalue);
-
-               ret = cals_stmt_step(stmt);
-       }
-       sqlite3_finalize(stmt);
-
-       *alarm_list = result;
-
-       return CAL_SUCCESS;
-}
-
diff --git a/src/cals-calendar.c b/src/cals-calendar.c
deleted file mode 100755 (executable)
index 4bfa4b1..0000000
+++ /dev/null
@@ -1,728 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include "cals-internal.h"
-#include "cals-typedef.h"
-#include "cals-sqlite.h"
-#include "cals-db-info.h"
-#include "cals-utils.h"
-#include "cals-alarm.h"
-#include "cals-calendar.h"
-
-
-int cals_insert_calendar(const calendar_t *calendar)
-{
-       int ret;
-       sqlite3_stmt *stmt;
-       char query[CALS_SQL_MAX_LEN];
-
-       retv_if(NULL == calendar, CAL_ERR_ARG_NULL);
-
-       sprintf(query,"INSERT INTO %s(calendar_id,uid,link,updated,name,description,author,"
-                       "color,hidden,selected,location,locale,country,time_zone,timezone_label,display_all_timezones,"
-                       "date_field_order,format_24hour_time,week_start,default_cal_mode,custom_cal_mode,user_location,"
-                       "weather,show_declined_events,hide_invitations,alternate_calendar,visibility,projection,"
-                       "sequence,suppress_reply_notifications,sync_event,times_cleaned,guests_can_modify,"
-                       "guests_can_invite_others,guests_can_see_guests,access_level,sync_status,account_id,sensitivity,store_type) "
-                       "VALUES( ?, ?, ?, %ld, ?, ?, ?, ?, %d, %d, ?, %d, %d, %ld, ?, %d, %d, %d, "
-                       "%d, %d, %d, ?, ?, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)",
-                       CALS_TABLE_CALENDAR,
-                       //calendar->calendar_id,
-                       //calendar->uid,
-                       //calendar->link,
-                       calendar->updated,
-                       //calendar->name,
-                       //calendar->description,
-                       //calendar->author,
-                       //calendar->color,
-                       calendar->hidden,
-                       calendar->selected,
-                       //calendar->location,
-                       calendar->locale,
-                       calendar->country,
-                       calendar->time_zone,
-                       //calendar->timezone_label,
-                       calendar->display_all_timezones,
-                       calendar->date_field_order,
-                       calendar->format_24hour_time,
-                       calendar->week_start,
-                       calendar->default_cal_mode,
-                       calendar->custom_cal_mode,
-                       //calendar->user_location,
-                       //calendar->weather,
-                       calendar->show_declined_events,
-                       calendar->hide_invitations,
-                       calendar->alternate_calendar,
-                       calendar->visibility,
-                       calendar->projection,
-                       calendar->sequence,
-                       calendar->suppress_reply_notifications,
-                       calendar->sync_event,
-                       calendar->times_cleaned,
-                       calendar->guests_can_modify,
-                       calendar->guests_can_invite_others,
-                       calendar->guests_can_see_guests,
-                       calendar->access_level,
-                       calendar->sync_status,
-                       calendar->account_id,
-                       calendar->sensitivity,
-                       calendar->store_type);
-
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       if (calendar->calendar_id)
-               cals_stmt_bind_text(stmt, 1, calendar->calendar_id);
-
-       if (calendar->uid)
-               cals_stmt_bind_text(stmt, 2, calendar->uid);
-
-       if (calendar->link)
-               cals_stmt_bind_text(stmt, 3, calendar->link);
-
-       if (calendar->name)
-               cals_stmt_bind_text(stmt, 4, calendar->name);
-
-       if (calendar->description)
-               cals_stmt_bind_text(stmt, 5, calendar->description);
-
-       if (calendar->author)
-               cals_stmt_bind_text(stmt, 6, calendar->author);
-
-       if (calendar->color)
-               cals_stmt_bind_text(stmt, 7, calendar->color);
-
-       if (calendar->location)
-               cals_stmt_bind_text(stmt, 8, calendar->location);
-
-       if (calendar->timezone_label)
-               cals_stmt_bind_text(stmt, 9, calendar->timezone_label);
-
-       if (calendar->user_location)
-               cals_stmt_bind_text(stmt, 10, calendar->user_location);
-
-       if (calendar->weather)
-               cals_stmt_bind_text(stmt, 11, calendar->weather);
-
-       ret = cals_stmt_step(stmt);
-       if (CAL_SUCCESS != ret) {
-               sqlite3_finalize(stmt);
-               ERR("cals_stmt_step() Failed(%d)", ret);
-               return ret;
-       }
-
-       ret = cals_last_insert_id();
-       sqlite3_finalize(stmt);
-
-       cals_notify(CALS_NOTI_TYPE_CALENDAR);
-
-       return ret;
-}
-
-int cals_update_calendar(const calendar_t *calendar)
-{
-       int rc = -1;
-       char query[CALS_SQL_MAX_LEN] = {0};
-       sqlite3_stmt *stmt = NULL;
-
-       retv_if(NULL == calendar, CAL_ERR_ARG_NULL);
-
-       snprintf(query, sizeof(query), "UPDATE %s SET "
-                       "calendar_id = ?,"
-                       "link = ?,"
-                       "updated = %ld,"
-                       "name = ?,"
-                       "description = ?,"
-                       "author = ?,"
-                       "color = ?,"
-                       "hidden= %d,"
-                       "selected = %d,"
-                       "location = ?,"
-                       "locale = %d,"
-                       "country = %d,"
-                       "time_zone = %ld,"
-                       "timezone_label = ?,"
-                       "display_all_timezones = %d,"
-                       "date_field_order = %d,"
-                       "format_24hour_time = %d,"
-                       "week_start = %d,"
-                       "default_cal_mode = %d,"
-                       "custom_cal_mode = %d,"
-                       "user_location = ?,"
-                       "weather = ?,"
-                       "show_declined_events = %d,"
-                       "hide_invitations = %d,"
-                       "alternate_calendar = %d,"
-                       "visibility = %d,"
-                       "projection = %d,"
-                       "sequence = %d,"
-                       "suppress_reply_notifications = %d,"
-                       "sync_event = %d,"
-                       "times_cleaned = %d,"
-                       "guests_can_modify = %d,"
-                       "guests_can_invite_others = %d,"
-                       "guests_can_see_guests = %d,"
-                       "access_level = %d,"
-                       "sync_status = %d,"
-                       "account_id = %d,"
-                       "sensitivity = %d, "
-                       "store_type = %d "
-                       "WHERE rowid = %d",
-               CALS_TABLE_CALENDAR,
-               calendar->updated,
-               calendar->hidden,
-               calendar->selected,
-               calendar->locale,
-               calendar->country,
-               calendar->time_zone,
-               calendar->display_all_timezones,
-               calendar->date_field_order,
-               calendar->format_24hour_time,
-               calendar->week_start,
-               calendar->default_cal_mode,
-               calendar->custom_cal_mode,
-               calendar->show_declined_events,
-               calendar->hide_invitations,
-               calendar->alternate_calendar,
-               calendar->visibility,
-               calendar->projection,
-               calendar->sequence,
-               calendar->suppress_reply_notifications,
-               calendar->sync_event,
-               calendar->times_cleaned,
-               calendar->guests_can_modify,
-               calendar->guests_can_invite_others,
-               calendar->guests_can_see_guests,
-               calendar->access_level,
-               calendar->sync_status,
-               calendar->account_id,
-               calendar->sensitivity,
-               calendar->store_type,
-               calendar->index);
-
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       if (calendar->calendar_id)
-               cals_stmt_bind_text(stmt, 1, calendar->calendar_id);
-
-       if (calendar->link)
-               cals_stmt_bind_text(stmt, 2, calendar->link);
-
-       if (calendar->name)
-               cals_stmt_bind_text(stmt, 3, calendar->name);
-
-       if (calendar->description)
-               cals_stmt_bind_text(stmt, 4, calendar->description);
-
-       if (calendar->author)
-               cals_stmt_bind_text(stmt, 5, calendar->author);
-
-       if (calendar->color)
-               cals_stmt_bind_text(stmt, 6, calendar->color);
-
-       if (calendar->location)
-               cals_stmt_bind_text(stmt, 7, calendar->location);
-
-       if (calendar->timezone_label)
-               cals_stmt_bind_text(stmt, 8, calendar->timezone_label);
-
-       if (calendar->user_location)
-               cals_stmt_bind_text(stmt, 9, calendar->user_location);
-
-       if (calendar->weather)
-               cals_stmt_bind_text(stmt, 10, calendar->weather);
-
-       rc = cals_stmt_step(stmt);
-       if (CAL_SUCCESS != rc) {
-               sqlite3_finalize(stmt);
-               ERR("cals_stmt_step() Failed(%d)", rc);
-               return rc;
-       }
-
-       sqlite3_finalize(stmt);
-
-       cals_notify(CALS_NOTI_TYPE_CALENDAR);
-
-       return CAL_SUCCESS;
-}
-
-int cals_delete_calendar(int calendar_id)
-{
-       int ret = 0;
-       char query[CALS_SQL_MIN_LEN] = {0};
-
-       ret = cals_begin_trans();
-       retvm_if(CAL_SUCCESS != ret, ret, "cals_begin_trans() Failed(%d)", ret);
-
-       snprintf(query, sizeof(query), "DELETE FROM %s WHERE rowid = %d",
-                       CALS_TABLE_CALENDAR, calendar_id);
-       ret = cals_query_exec(query);
-       if(CAL_SUCCESS != ret) {
-               ERR("cals_query_exec() Failed(%d)", ret);
-               cals_end_trans(false);
-               return ret;
-       }
-
-       snprintf(query, sizeof(query), "DELETE FROM %s WHERE calendar_id = %d",
-               CALS_TABLE_SCHEDULE, calendar_id);
-       ret = cals_query_exec(query);
-       if (CAL_SUCCESS != ret) {
-               ERR("cals_query_exec() Failed(%d)", ret);
-               cals_end_trans(false);
-               return ret;
-       }
-
-       snprintf(query, sizeof(query), "DELETE FROM %s WHERE calendar_id = %d",
-               CALS_TABLE_DELETED, calendar_id);
-       ret = cals_query_exec(query);
-       if (CAL_SUCCESS != ret) {
-               ERR("cals_query_exec() Failed(%d)", ret);
-               cals_end_trans(false);
-               return ret;
-       }
-
-       ret = cals_alarm_remove(CALS_ALARM_REMOVE_BY_CALENDAR_ID, calendar_id);
-       if (CAL_SUCCESS != ret) {
-               ERR("cals_alarm_remove() Failed(%d)", ret);
-               cals_end_trans(false);
-               return ret;
-       }
-
-       cals_end_trans(true);
-
-       cals_notify(CALS_NOTI_TYPE_CALENDAR);
-       return CAL_SUCCESS;
-}
-
-
-int cals_delete_calendars(int account_id)
-{
-       int ret = 0;
-       char query[CALS_SQL_MIN_LEN] = {0};
-
-       if (account_id)
-               sprintf(query,"DELETE FROM calendar_table WHERE account_id = %d", account_id);
-       else
-               sprintf(query,"DELETE FROM calendar_table");
-
-       ret = cals_query_exec(query);
-       retvm_if(CAL_SUCCESS != ret, ret, "cals_query_exec() Failed(%d)", ret);
-
-       cals_notify(CALS_NOTI_TYPE_CALENDAR);
-       return CAL_SUCCESS;
-}
-
-
-void cals_stmt_get_calendar(sqlite3_stmt *stmt,calendar_t *record)
-{
-       int count = 0;
-       const unsigned char *temp;
-
-       record->index = sqlite3_column_int(stmt, count++);
-
-       temp = sqlite3_column_text(stmt, count++);
-       record->calendar_id = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       record->uid = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       record->link = SAFE_STRDUP(temp);
-
-       record->updated = sqlite3_column_int(stmt, count++);
-
-       temp = sqlite3_column_text(stmt, count++);
-       record->name = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       record->description = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       record->author = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       record->color = SAFE_STRDUP(temp);
-
-       record->hidden = sqlite3_column_int(stmt, count++);
-       record->selected = sqlite3_column_int(stmt, count++);
-
-       temp = sqlite3_column_text(stmt, count++);
-       record->location = SAFE_STRDUP(temp);
-
-       record->locale = sqlite3_column_int(stmt, count++);
-       record->country = sqlite3_column_int(stmt, count++);
-       record->time_zone = sqlite3_column_int(stmt, count++);
-
-       temp = sqlite3_column_text(stmt, count++);
-       record->timezone_label = SAFE_STRDUP(temp);
-
-       record->display_all_timezones = sqlite3_column_int(stmt, count++);
-       record->date_field_order = sqlite3_column_int(stmt, count++);
-       record->format_24hour_time = sqlite3_column_int(stmt, count++);
-       record->week_start = sqlite3_column_int(stmt, count++);
-       record->default_cal_mode = sqlite3_column_int(stmt, count++);
-       record->custom_cal_mode = sqlite3_column_int(stmt, count++);
-
-       temp = sqlite3_column_text(stmt, count++);
-       record->user_location = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       record->weather = SAFE_STRDUP(temp);
-
-       record->show_declined_events = sqlite3_column_int(stmt, count++);
-       record->hide_invitations = sqlite3_column_int(stmt, count++);
-       record->alternate_calendar = sqlite3_column_int(stmt, count++);
-       record->visibility = sqlite3_column_int(stmt, count++);
-       record->projection = sqlite3_column_int(stmt, count++);
-       record->sequence = sqlite3_column_int(stmt, count++);
-       record->suppress_reply_notifications = sqlite3_column_int(stmt, count++);
-       record->sync_event = sqlite3_column_int(stmt, count++);
-       record->times_cleaned = sqlite3_column_int(stmt, count++);
-       record->guests_can_modify = sqlite3_column_int(stmt, count++);
-       record->guests_can_invite_others = sqlite3_column_int(stmt, count++);
-       record->guests_can_see_guests = sqlite3_column_int(stmt, count++);
-       record->access_level = sqlite3_column_int(stmt, count++);
-       record->sync_status = sqlite3_column_int(stmt, count++);
-       record->is_deleted = sqlite3_column_int(stmt, count++);
-       record->account_id = sqlite3_column_int(stmt, count++);
-       record->sensitivity = sqlite3_column_int(stmt, count++);
-       record->store_type = sqlite3_column_int(stmt, count++);
-}
-
-int cals_rearrage_calendar_field(const char *src, char *dest, int dest_size)
-{
-       int ret = 0;
-       if (strstr(src,CAL_TABLE_TXT_CALENDAR_ID))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_TXT_CALENDAR_ID);
-
-       if (strstr(src,CAL_TABLE_TXT_UID))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_TXT_UID);
-
-       if (strstr(src,CAL_TABLE_TXT_LINK))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_TXT_LINK);
-
-       if (strstr(src,CAL_TABLE_INT_UPDATED))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_UPDATED);
-
-       if (strstr(src,CAL_TABLE_TXT_NAME))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_TXT_NAME);
-
-       if (strstr(src,CAL_TABLE_TXT_DESCRIPTION))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_TXT_DESCRIPTION);
-
-       if(strstr(src,CAL_TABLE_TXT_AUTHOR))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_TXT_AUTHOR);
-
-       if(strstr(src,CAL_TABLE_TXT_COLOR))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_TXT_COLOR);
-
-       if(strstr(src, CAL_TABLE_INT_HIDDEN))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_HIDDEN);
-
-       if(strstr(src, CAL_TABLE_INT_SELECTED))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_SELECTED);
-
-       if(strstr(src, CAL_TABLE_TXT_LOCATION))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_TXT_LOCATION);
-
-       if(strstr(src, CAL_TABLE_INT_LOCALE))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_LOCALE);
-
-       if(strstr(src,CAL_TABLE_INT_COUNTRY))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_COUNTRY);
-
-       if(strstr(src,CAL_TABLE_INT_TIME_ZONE))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_TIME_ZONE);
-
-       if(strstr(src,CAL_TABLE_TXT_TIME_ZONE_LABEL))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_TXT_TIME_ZONE_LABEL);
-
-       if(strstr(src,CAL_TABLE_INT_DISPLAY_ALL_TIMEZONES))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_DISPLAY_ALL_TIMEZONES);
-
-       if(strstr(src,CAL_TABLE_INT_DATE_FIELD_ORDER))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_DATE_FIELD_ORDER);
-
-       if(strstr(src,CAL_TABLE_INT_FROMAT_24HOUR_TIME))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_FROMAT_24HOUR_TIME);
-
-       if(strstr(src,CAL_TABLE_INT_WEEK_START))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_WEEK_START);
-
-       if(strstr(src,CAL_TABLE_INT_DEFAULT_CAL_MODE))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_DEFAULT_CAL_MODE);
-
-       if(strstr(src,CAL_TABLE_INT_CUSTOM_CAL_MODE))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_CUSTOM_CAL_MODE);
-
-       if(strstr(src,CAL_TABLE_TXT_USER_LOCATION))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_TXT_USER_LOCATION);
-
-       if(strstr(src,CAL_TABLE_TXT_WEATHER))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_TXT_WEATHER);
-
-       if(strstr(src,CAL_TABLE_INT_SHOW_DECLINED_EVENTS))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_SHOW_DECLINED_EVENTS);
-
-       if(strstr(src,CAL_TABLE_INT_HIDE_INVITATIONS))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_HIDE_INVITATIONS);
-
-       if(strstr(src,CAL_TABLE_INT_ALTERNATE_CALENDAR))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_ALTERNATE_CALENDAR);
-
-       if(strstr(src,CAL_TABLE_INT_VISIBILITY))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_VISIBILITY);
-
-       if(strstr(src,CAL_TABLE_INT_PROJECTION))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_PROJECTION);
-
-       if(strstr(src,CAL_TABLE_INT_SEQUENCE))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_SEQUENCE);
-
-       if(strstr(src,CAL_TABLE_INT_SUPRESS_REPLY_NOTIFICATIONS))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_SUPRESS_REPLY_NOTIFICATIONS);
-
-       if(strstr(src, CAL_TABLE_INT_SYNC_EVENT))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_SYNC_EVENT);
-
-       if(strstr(src,CAL_TABLE_INT_TIMES_CLEANED))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_TIMES_CLEANED);
-
-       if(strstr(src,CAL_TABLE_INT_GUESTS_CAN_MODIFY))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_GUESTS_CAN_MODIFY);
-
-       if(strstr(src,CAL_TABLE_INT_GUESTS_CAN_INVITE_OTHERS))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_GUESTS_CAN_INVITE_OTHERS);
-
-       if(strstr(src,CAL_TABLE_INT_GUESTS_CAN_SEE_GUESTS))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_GUESTS_CAN_SEE_GUESTS);
-
-       if(strstr(src,CAL_TABLE_INT_ACCESS_LEVEL))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_ACCESS_LEVEL);
-
-       if(strstr(src,CAL_TABLE_INT_SYNC_STATUS))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_SYNC_STATUS);
-
-       if(strstr(src,CAL_TABLE_INT_IS_DELETED))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_IS_DELETED);
-
-       if(strstr(src,CAL_TABLE_INT_ACCOUNT_ID))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_ACCOUNT_ID);
-
-       if(strstr(src,CAL_TABLE_INT_SENSITIVITY))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_SENSITIVITY);
-
-       if(strstr(src, CAL_TABLE_INT_STORE_TYPE))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_TABLE_INT_STORE_TYPE);
-
-       return CAL_SUCCESS;
-}
-
-int cals_stmt_get_filted_calendar(sqlite3_stmt *stmt,
-       calendar_t *record, const char *select_field)
-{
-       int count = 0;
-       const unsigned char *temp;
-       const char *start, *result;
-
-       retv_if(NULL == stmt, CAL_ERR_ARG_NULL);
-       retv_if(NULL == record, CAL_ERR_ARG_NULL);
-       retv_if(NULL == select_field, CAL_ERR_ARG_NULL);
-
-       record->index = sqlite3_column_int(stmt, count++);
-
-       start = select_field;
-       if((result = strstr(start, CAL_TABLE_TXT_CALENDAR_ID))) {
-               temp = sqlite3_column_text(stmt, count++);
-               record->calendar_id = SAFE_STRDUP(temp);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_TXT_UID))) {
-               temp = sqlite3_column_text(stmt, count++);
-               record->uid = SAFE_STRDUP(temp);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_TXT_LINK))) {
-               temp = sqlite3_column_text(stmt, count++);
-               record->link = SAFE_STRDUP(temp);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_UPDATED))) {
-               record->updated = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_TXT_NAME))) {
-               temp = sqlite3_column_text(stmt, count++);
-               record->name = SAFE_STRDUP(temp);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_TXT_DESCRIPTION))) {
-               temp = sqlite3_column_text(stmt, count++);
-               record->description = SAFE_STRDUP(temp);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_TXT_AUTHOR))) {
-               temp = sqlite3_column_text(stmt, count++);
-               record->author = SAFE_STRDUP(temp);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_TXT_COLOR))) {
-               temp = sqlite3_column_text(stmt, count++);
-               record->color = SAFE_STRDUP(temp);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_HIDDEN))) {
-               record->hidden = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_SELECTED))) {
-               record->selected = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_TXT_LOCATION))) {
-               temp = sqlite3_column_text(stmt, count++);
-               record->location = SAFE_STRDUP(temp);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_LOCALE))) {
-               record->locale = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_COUNTRY))) {
-               record->country = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_TIME_ZONE))) {
-               record->time_zone = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_TXT_TIME_ZONE_LABEL))) {
-               temp = sqlite3_column_text(stmt, count++);
-               record->timezone_label = SAFE_STRDUP(temp);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_DISPLAY_ALL_TIMEZONES))) {
-               record->display_all_timezones = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_DATE_FIELD_ORDER))) {
-               record->date_field_order = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_FROMAT_24HOUR_TIME))) {
-               record->format_24hour_time = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_WEEK_START))) {
-               record->week_start = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_DEFAULT_CAL_MODE))) {
-               record->default_cal_mode = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_CUSTOM_CAL_MODE))) {
-               record->custom_cal_mode = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_TXT_USER_LOCATION))) {
-               temp = sqlite3_column_text(stmt, count++);
-               record->user_location = SAFE_STRDUP(temp);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_TXT_WEATHER))) {
-               temp = sqlite3_column_text(stmt, count++);
-               record->weather = SAFE_STRDUP(temp);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_SHOW_DECLINED_EVENTS))) {
-               record->show_declined_events = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_HIDE_INVITATIONS))) {
-               record->hide_invitations = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_ALTERNATE_CALENDAR))) {
-               record->alternate_calendar = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_VISIBILITY))) {
-               record->visibility = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_PROJECTION))) {
-               record->projection = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_SEQUENCE))) {
-               record->sequence = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_SUPRESS_REPLY_NOTIFICATIONS))) {
-               record->suppress_reply_notifications = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_SYNC_EVENT))) {
-               record->sync_event = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_TIMES_CLEANED))) {
-               record->times_cleaned = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_GUESTS_CAN_MODIFY))) {
-               record->guests_can_modify = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_GUESTS_CAN_INVITE_OTHERS))) {
-               record->guests_can_invite_others = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_GUESTS_CAN_SEE_GUESTS))) {
-               record->guests_can_see_guests = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_ACCESS_LEVEL))) {
-               record->access_level = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_SYNC_STATUS))) {
-               record->sync_status = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_IS_DELETED))) {
-               record->is_deleted = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_ACCOUNT_ID))) {
-               record->account_id = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_SENSITIVITY))) {
-               record->sensitivity = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       if((result = strstr(start, CAL_TABLE_INT_STORE_TYPE))) {
-               record->store_type = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-       return CAL_SUCCESS;
-}
-
diff --git a/src/cals-calendar.h b/src/cals-calendar.h
deleted file mode 100755 (executable)
index ee75882..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __CALENDAR_SVC_CALENDAR_H__
-#define __CALENDAR_SVC_CALENDAR_H__
-
-int cals_insert_calendar(const calendar_t *calendar);
-int cals_update_calendar(const calendar_t *calendar_info);
-
-int cals_delete_calendars(int account_id);
-int cals_delete_calendar(int index);
-
-int cals_rearrage_calendar_field(const char *src, char *dest, int dest_size);
-
-void cals_stmt_get_calendar(sqlite3_stmt *stmt, calendar_t *calendar_record);
-int cals_stmt_get_filted_calendar(sqlite3_stmt *stmt, calendar_t *calendar_record, const char *select_field);
-
-#endif /* __CALENDAR_SVC_CALENDAR_H__ */
-
diff --git a/src/cals-db.c b/src/cals-db.c
deleted file mode 100755 (executable)
index 5a897ff..0000000
+++ /dev/null
@@ -1,522 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <unistd.h>
-#include <time.h>
-#include <errno.h>
-#include <dlfcn.h>
-#include <sqlite3.h>
-#include <db-util.h>
-
-#include "cals-internal.h"
-#include "calendar-svc-provider.h"
-#include "calendar-svc-errors.h"
-#include "cals-db-info.h"
-#include "cals-typedef.h"
-#include "cals-utils.h"
-#include "cals-ical.h"
-#include "cals-alarm.h"
-#include "cals-sqlite.h"
-#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)
-{
-       if ((index < 0) || (index >= (0x7fffffff)) )
-       {
-               return false;
-       }
-       return true;
-}
-
-/************************************************************************************************
- *                                                                                               *
- *                               org engine init APIs                                            *
- *                                                                                               *
- ************************************************************************************************/
-
-
-bool cal_db_service_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;
-}
-
-int cals_db_free_alarm(cal_sch_full_t *record)
-{
-       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;
-               }
-
-               CAL_FREE(ai->alarm_tone);
-               CAL_FREE(ai->alarm_description);
-               CAL_FREE(ai);
-
-               CAL_FREE(cv);
-
-               l = g_list_next(l);
-       }
-       g_list_free(record->alarm_list);
-       record->alarm_list = NULL;
-
-       return 0;
-}
-
-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;
-}
-
-/************************************************************************************************
- *                                                                                               *
- *                           calendar event table add/edit APIs                                  *
- *                                                                                               *
- ************************************************************************************************/
-int cal_service_add_participant_info(const int event_id, const cal_participant_info_t* current_record)
-{
-       int ret = -1;
-       sqlite3_stmt *stmt = NULL;
-       char sql_value[CALS_SQL_MAX_LEN];
-
-       //check if db opened
-
-       sprintf(sql_value,"INSERT INTO %s(event_id,attendee_name,attendee_email,attendee_number,attendee_status,attendee_type,attendee_ct_index,"
-                       "attendee_role,attendee_rsvp,attendee_group,attendee_delegator_uri,attendee_delegate_uri,attendee_uid) "
-                       "VALUES(%d, ?, ?, ?, %d, %d, %d,%d,%d,?,?,?,?)", CALS_TABLE_PARTICIPANT,
-                       event_id,
-                       current_record->attendee_status,
-                       current_record->attendee_type,
-                       current_record->attendee_ct_index,
-                       current_record->attendee_role,
-                       current_record->attendee_rsvp);
-
-       stmt = cals_query_prepare(sql_value);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       if (current_record->attendee_name)
-               cals_stmt_bind_text(stmt, 1, current_record->attendee_name);
-
-       if (current_record->attendee_email)
-               cals_stmt_bind_text(stmt, 2, current_record->attendee_email);
-
-       if (current_record->attendee_number)
-               cals_stmt_bind_text(stmt, 3, current_record->attendee_number);
-
-       if (current_record->attendee_group)
-               cals_stmt_bind_text(stmt, 4, current_record->attendee_group);
-
-       if (current_record->attendee_delegator_uri)
-               cals_stmt_bind_text(stmt, 5, current_record->attendee_delegator_uri);
-
-       if (current_record->attendee_delegate_uri)
-               cals_stmt_bind_text(stmt, 6, current_record->attendee_delegate_uri);
-
-       if (current_record->attendee_uid)
-               cals_stmt_bind_text(stmt, 7, current_record->attendee_uid);
-
-
-       ret = cals_stmt_step(stmt);
-       if (CAL_SUCCESS != ret) {
-               sqlite3_finalize(stmt);
-               ERR("cals_stmt_step() Failed(%d)", ret);
-               return ret;
-       }
-       sqlite3_finalize(stmt);
-
-       return CAL_SUCCESS;
-}
-
-/************************************************************************************************
- *                                                                                               *
- *                               calendar event table get APIs                                   *
- *                                                                                               *
- ************************************************************************************************/
-
-bool cal_db_service_get_participant_info_by_index(const int panticipant_index, GList** record_list, int *error_code)
-{
-       int     rc = -1;
-       char sql_value[CALS_SQL_MAX_LEN] = {0};
-       cal_participant_info_t* participant_info = NULL;
-       sqlite3_stmt *stmt = NULL;
-       cal_value *cvalue = NULL;
-
-       retex_if(error_code == NULL, ,"cal_db_service_get_record_by_index: The error_code is NULL.\n");
-
-       //check input parameter
-       retex_if (!__check_record_index_valid(panticipant_index),*error_code = CAL_ERR_ARG_INVALID, "The index is invalid." );
-
-       //check if db opened
-       retex_if(NULL == calendar_db_handle, *error_code = CAL_ERR_DB_NOT_OPENED, "The calendar database hasn't been opened.");
-
-       sprintf(sql_value, "select * from cal_participant_table where event_id = %d;", panticipant_index);
-
-       rc = sqlite3_prepare_v2(calendar_db_handle, sql_value, strlen(sql_value), &stmt, NULL);
-       retex_if(rc != SQLITE_OK, *error_code = CAL_ERR_DB_FAILED, "Failed to get stmt!!");
-
-       rc = sqlite3_step(stmt);
-       retex_if(rc!= SQLITE_ROW && rc!= SQLITE_OK && rc!= SQLITE_DONE, *error_code = CAL_ERR_DB_FAILED, "[ERROR]cal_db_service_get_participant_info_by_index:Query error !!");
-       while(rc == SQLITE_ROW)
-       {
-               cvalue = (cal_value*)malloc(sizeof(cal_value));
-               retex_if(NULL == cvalue,,"[ERROR]cal_db_service_get_participant_info_by_index:Failed to malloc!\n");
-
-               cvalue->v_type = CAL_EVENT_PATICIPANT;
-               cvalue->user_data = (cal_participant_info_t*)malloc(sizeof(cal_participant_info_t));
-               retex_if(NULL == cvalue->user_data,,"[ERROR]cal_db_service_get_participant_info_by_index:Failed to malloc!\n");
-
-               participant_info = cvalue->user_data;
-               memset(participant_info, 0x00, sizeof(cal_participant_info_t));
-
-               participant_info->event_id = sqlite3_column_int(stmt, 0);
-
-               cal_db_get_text_from_stmt(stmt,&(participant_info->attendee_name),1);
-               cal_db_get_text_from_stmt(stmt,&(participant_info->attendee_email),2);
-               cal_db_get_text_from_stmt(stmt,&(participant_info->attendee_number),3);
-               participant_info->attendee_status = sqlite3_column_int(stmt, 4);
-               participant_info->attendee_type = sqlite3_column_int(stmt, 5);
-               participant_info->attendee_ct_index = sqlite3_column_int(stmt, 6);
-               participant_info->attendee_role = sqlite3_column_int(stmt, 7);
-               participant_info->attendee_rsvp = sqlite3_column_int(stmt, 8);
-               cal_db_get_text_from_stmt(stmt,&(participant_info->attendee_group),9);
-               cal_db_get_text_from_stmt(stmt,&(participant_info->attendee_delegator_uri),10);
-               cal_db_get_text_from_stmt(stmt,&(participant_info->attendee_delegate_uri),11);
-               cal_db_get_text_from_stmt(stmt,&(participant_info->attendee_uid),12);
-
-               *record_list = g_list_append(*record_list, (gpointer)cvalue);
-
-               cvalue = NULL;
-
-               rc = sqlite3_step(stmt);
-
-               if(rc == SQLITE_DONE)
-               {
-                       break;
-               }
-
-               retex_if(rc != SQLITE_ROW && rc != SQLITE_OK && rc != SQLITE_DONE, *error_code = CAL_ERR_DB_FAILED, "Query error!!");
-
-       }
-       //DBG("Get that\n");
-       if (stmt)
-       {
-               sqlite3_finalize(stmt);
-               stmt = NULL;
-       }
-
-       return true;
-
-CATCH:
-       if (cvalue)
-       {
-               if (cvalue->user_data)
-               {
-                       CAL_FREE(participant_info->attendee_name);
-                       CAL_FREE(participant_info->attendee_email);
-                       CAL_FREE(participant_info->attendee_number);
-                       CAL_FREE(cvalue->user_data);
-               }
-               CAL_FREE(cvalue);
-       }
-
-       if (stmt)
-       {
-               sqlite3_finalize(stmt);
-               stmt = NULL;
-       }
-
-       return false;
-}
-
-int __cal_service_delete_all_records(const int account_id, const cals_sch_type record_type)
-{
-       int ret = 0;
-       char query_logging[CALS_SQL_MIN_LEN] = {0};
-       char query_delete[CALS_SQL_MIN_LEN] = {0};
-
-       if (account_id == LOCAL_ACCOUNT_ID) {
-               snprintf(query_logging, sizeof(query_logging), "INSERT INTO %s "
-                               "SELECT id, type, calendar_id, %d FROM %s "
-                               "WHERE type = %d AND account_id = %d",
-                               CALS_TABLE_DELETED,
-                               cals_get_next_ver(), CALS_TABLE_SCHEDULE,
-                               record_type, account_id);
-
-               snprintf(query_delete, sizeof(query_delete), "DELETE FROM %s "
-                               "WHERE type = %d AND account_id = %d",
-                               CALS_TABLE_SCHEDULE,
-                               record_type, account_id);
-
-       } else {
-               snprintf(query_logging, sizeof(query_logging), "UPDATE %s "
-                               "SET is_deleted = 1, last_modified_time = %ld, changed_ver = %d "
-                               "WHERE type = %d AND accoutn_id = %d ",
-                               CALS_TABLE_SCHEDULE,
-                               time(NULL), cals_get_next_ver(),
-                               record_type, account_id);
-
-       }
-
-       ret = cals_begin_trans();
-       retvm_if(CAL_SUCCESS != ret, ret, "cals_begin_trans() Failed(%d)", ret);
-
-       if (CALS_SCH_TYPE_NONE == record_type || CALS_SCH_TYPE_EVENT == record_type) {
-               if (account_id)
-                       cals_alarm_remove(CALS_ALARM_REMOVE_BY_ACC_ID, account_id);
-               else
-                       cals_alarm_remove(CALS_ALARM_REMOVE_ALL, account_id);
-       }
-
-       ret = cals_query_exec(query_logging);
-       if (CAL_SUCCESS != ret) {
-               cals_end_trans(false);
-               ERR("cals_query_exec() Failed(%d)", ret);
-               return ret;
-       }
-
-       ret = cals_query_exec(query_delete);
-       if (CAL_SUCCESS != ret) {
-               cals_end_trans(false);
-               ERR("cals_query_exec() Failed(%d)", ret);
-               return ret;
-       }
-
-       cals_end_trans(true);
-
-       if(CALS_SCH_TYPE_EVENT == record_type)
-               cals_notify(CALS_NOTI_TYPE_EVENT);
-       else
-               cals_notify(CALS_NOTI_TYPE_TODO);
-
-       return CAL_SUCCESS;
-}
-
-
-int cals_insert_timezone(cal_timezone_t *timezone_info)
-{
-       int ret;
-       sqlite3_stmt *stmt;
-       char query[CALS_SQL_MAX_LEN];
-
-       retv_if(NULL == timezone_info, CAL_ERR_ARG_NULL);
-
-       sprintf(query,"INSERT INTO %s(tz_offset_from_gmt ,standard_name, "
-                       "std_start_month ,std_start_position_of_week ,std_start_day, "
-                       "std_start_hour ,standard_bias ,day_light_name ,day_light_start_month, "
-                       "day_light_start_position_of_week ,day_light_start_day, "
-                       "day_light_start_hour ,day_light_bias) "
-                       "VALUES(%d,?,%d,%d,%d,%d,%d,?,%d,%d,%d,%d,%d)", CALS_TABLE_TIMEZONE,
-                       timezone_info->tz_offset_from_gmt,
-                       timezone_info->std_start_month,
-                       timezone_info->std_start_position_of_week,
-                       timezone_info->std_start_day,
-                       timezone_info->std_start_hour,
-                       timezone_info->standard_bias,
-                       timezone_info->day_light_start_month,
-                       timezone_info->day_light_start_position_of_week,
-                       timezone_info->day_light_start_day,
-                       timezone_info->day_light_start_hour,
-                       timezone_info->day_light_bias);
-
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       if (timezone_info->standard_name)
-               cals_stmt_bind_text(stmt, 1, timezone_info->standard_name);
-
-       if (timezone_info->day_light_name)
-               cals_stmt_bind_text(stmt, 2, timezone_info->day_light_name);
-
-       ret = cals_stmt_step(stmt);
-       if (CAL_SUCCESS != ret) {
-               sqlite3_finalize(stmt);
-               ERR("cals_stmt_step() Failed(%d)", ret);
-               return ret;
-       }
-       ret = cals_last_insert_id();
-       sqlite3_finalize(stmt);
-
-       return ret;
-}
-
-
-int cals_update_timezone(cal_timezone_t *timezone_info)
-{
-       int ret;
-       sqlite3_stmt *stmt;
-       char query[CALS_SQL_MAX_LEN];
-
-       retv_if(NULL == timezone_info, CAL_ERR_ARG_NULL);
-
-       sprintf(query, "UPDATE %s SET "
-                       "tz_offset_from_gmt=%d,"
-                       "standard_name=?,"
-                       "std_start_month=%d,"
-                       "std_start_position_of_week=%d,"
-                       "std_start_day=%d,"
-                       "std_start_hour=%d,"
-                       "standard_bias=%d,"
-                       "day_light_name=?,"
-                       "day_light_start_month=%d,"
-                       "day_light_start_position_of_week=%d,"
-                       "day_light_start_day=%d,"
-                       "day_light_start_hour=%d,"
-                       "day_light_bias=%d "
-                       "WHERE rowid = %d",
-                       CALS_TABLE_TIMEZONE,
-                       timezone_info->tz_offset_from_gmt,
-                       timezone_info->std_start_month,
-                       timezone_info->std_start_position_of_week,
-                       timezone_info->std_start_day,
-                       timezone_info->std_start_hour,
-                       timezone_info->standard_bias,
-                       timezone_info->day_light_start_month,
-                       timezone_info->day_light_start_position_of_week,
-                       timezone_info->day_light_start_day,
-                       timezone_info->day_light_start_hour,
-                       timezone_info->day_light_bias,
-                       timezone_info->index);
-
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       if (timezone_info->standard_name)
-               cals_stmt_bind_text(stmt, 1, timezone_info->standard_name);
-
-       if (timezone_info->day_light_name)
-               cals_stmt_bind_text(stmt, 2, timezone_info->day_light_name);
-
-       ret = cals_stmt_step(stmt);
-       if (CAL_SUCCESS != ret) {
-               sqlite3_finalize(stmt);
-               ERR("cals_stmt_step() Failed(%d)", ret);
-               return ret;
-       }
-       sqlite3_finalize(stmt);
-
-       return CAL_SUCCESS;
-}
-
diff --git a/src/cals-db.h b/src/cals-db.h
deleted file mode 100755 (executable)
index 84e3cc2..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-/**
- * @ingroup app_engine
- * @defgroup app_cal_engine Organizer
- * @{
- */
-
-#ifndef __CALENDAR_SVC_DB_H__
-#define __CALENDAR_SVC_DB_H__
-
-#include <glib.h>
-#include <sqlite3.h>
-
-#include "cals-typedef.h"
-
-/**
- *  This function free full schedule record.
- *
- * @return             This function returns initialized record.
- * @param[in]  sch_full_record Points the field information for schedule table' s record.
- * @exception  CAL_ERR_ARG_INVALID.
- */
-int cal_db_service_free_full_record(cal_sch_full_t *sch_full_record);
-
-
-/**
- *  This function gets the participant info by participant id from the specified table.
- *
- * @return             This function returns true on success, or false on failure.
- * @param[in]          panticipant_index               participant id from org table.
- * @param[out] record_list             records of this particapant info.
- * @param[out] error_code      Points the error code.
- * @exception  CAL_ERR_DB_NOT_OPENED, CAL_ERR_ARG_INVALID, CAL_ERR_DB_FAILED
- */
-bool cal_db_service_get_participant_info_by_index(const int panticipant_index, GList** record_list, int *error_code);
-
-/**
- *  This function get record by index base on table type.
- *
- * @return             This function returns true on success, or false on failure.
- * @param[in]          index                   specified the index.
- * @param[out] returned_record Points of the full field information for schedule table' s record.
- * @param[out] error_code              Points the error code.
- * @exception   CAL_ERR_DB_NOT_OPENED, CAL_ERR_DB_FAILED,
- *                             CAL_ERR_DB_RECORD_NOT_FOUND, CAL_ERR_DB_FAILED
- */
-bool cal_db_service_get_record_full_field_by_index(const int index, cal_sch_full_t *returned_record, int *error_code);
-
-/**
- *  This function adds the participant info into the specified table.
- *
- * @return             This function returns true on success, or false on failure.
- * @param[in]          participant_id          participant id from org table.
- * @param[in]          current_record          records of this particapant info.
- * @param[out] error_code              Points the error code.
- * @exception  CAL_ERR_DB_NOT_OPENED, CAL_ERR_ARG_INVALID, CAL_ERR_DB_FAILED
- */
-int cal_service_add_participant_info(const int participant_id, const cal_participant_info_t* current_record);
-
-int cals_insert_timezone(cal_timezone_t *timezone_info);
-int cals_update_timezone(cal_timezone_t *timezone_info);
-
-int __cal_service_delete_all_records(const int account_id, const cals_sch_type record_type);
-
-/**
- * @}
- */
-
-#endif /* __CALENDAR_SVC_DB_H__ */
diff --git a/src/cals-event.c b/src/cals-event.c
deleted file mode 100755 (executable)
index 2810ed5..0000000
+++ /dev/null
@@ -1,721 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <errno.h>
-
-#include "cals-internal.h"
-#include "cals-typedef.h"
-#include "cals-sqlite.h"
-#include "cals-db-info.h"
-#include "cals-db.h"
-#include "cals-alarm.h"
-#include "cals-utils.h"
-#include "cals-schedule.h"
-#include "cals-time.h"
-
-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)
-{
-       int ret;
-
-       ret = snprintf(dest, dest_size, "type = %d", CALS_SCH_TYPE_EVENT);
-
-       if (calendar_id)
-               ret += snprintf(dest+ret, dest_size-ret, "AND calendar_id = %d", calendar_id);
-
-       if (0 < start_time)
-               ret += snprintf(dest+ret, dest_size-ret, "AND start_date_time >= %ld", start_time);
-
-       if (0 < end_time)
-               ret += snprintf(dest+ret, dest_size-ret, "AND start_date_time <= %ld", end_time);
-
-       if (0 <= all_day)
-               ret += snprintf(dest+ret, dest_size-ret, "AND all_day_event = %d", !!(all_day));
-}
-
-
-/**
- * This function gets count related with event.
- * If parameter is invalid(0, negative, etc.), it will be ignored
- * If all parameters are invalid, this function return all event count.
- *
- * @param[in] calendar_id calendar_id
- * @param[in] start_time start time
- * @param[in] end_time end time
- * @param[in] all_day TRUE(1 or positive)/FALSE(0)/IGNORE(-1 or negative)
- * @return The count number on success, Negative value(#cal_error) on error
- */
-/*
-API int calendar_svc_event_get_count(int calendar_id,
-               time_t start_time, time_t end_time, int all_day)
-{
-       char query[CALS_SQL_MIN_LEN];
-       char cond[CALS_SQL_MIN_LEN];
-
-       cals_event_make_condition(calendar_id, start_time, end_time, all_day,
-                                                                       cond, sizeof(cond));
-
-       snprintf(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE is_deleted = 0 AND %s",
-                       CALS_TABLE_SCHEDULE, cond);
-
-       return cals_query_get_first_int_result(query);
-}
-*/
-
-API cal_iter* calendar_svc_event_get_list(int calendar_id,
-       time_t start_time, time_t end_time, int all_day)
-{
-       cal_iter *iter;
-       sqlite3_stmt *stmt = NULL;
-       char query[CALS_SQL_MAX_LEN];
-       char cond[CALS_SQL_MIN_LEN];
-
-       cals_event_make_condition(calendar_id, start_time, end_time, all_day,
-                                                                       cond, sizeof(cond));
-
-       sprintf(query,"SELECT * FROM %s WHERE is_deleted = 0 AND %s ORDER BY start_date_time",
-                       CALS_TABLE_SCHEDULE, cond);
-
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, NULL,"cals_query_prepare() Failed");
-
-       iter = calloc(1, sizeof(cal_iter));
-       if (NULL == iter) {
-               sqlite3_finalize(stmt);
-               ERR("calloc() Failed(%d)", errno);
-               return NULL;
-       }
-       iter->i_type = CAL_STRUCT_TYPE_SCHEDULE;
-       iter->stmt = stmt;
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_event_search(int fields, const char *keyword, cal_iter **iter)
-{
-       int ret;
-
-       ret = cals_sch_search(CALS_SCH_TYPE_EVENT, fields, keyword, iter);
-       retvm_if(ret < 0, ret, "cals_sch_search() failed(%d)", ret);
-
-       return CAL_SUCCESS;
-}
-
-static inline int cals_event_get_changes(int calendar_id, int version, cal_iter *iter)
-{
-       char buf[64] = {0};
-       char query[CALS_SQL_MIN_LEN] = {0,};
-       sqlite3_stmt *stmt;
-       cals_updated *last;
-       cals_updated *result;
-
-       if (calendar_id > 0) {
-               snprintf(buf, sizeof(buf), "AND calendar_id = %d ", calendar_id);
-       } else {
-               memset(buf, 0x0, sizeof(buf));
-       }
-
-       snprintf(query, sizeof(query),
-                       "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, 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,
-                       CALS_TABLE_DELETED,
-                       version, CALS_SCH_TYPE_EVENT, buf);
-
-       DBG("query(%s)", query);
-       stmt = cals_query_prepare(query);
-       retvm_if (NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() failed.");
-
-       while (CAL_TRUE == cals_stmt_step(stmt)){
-               result = cals_updated_schedule_add_mempool();
-
-               result->id = sqlite3_column_int(stmt, 0);
-               result->ver = sqlite3_column_int(stmt, 1);
-               if (sqlite3_column_int(stmt, 3) == 1) {
-                       result->type = CALS_UPDATED_TYPE_DELETED;
-               } else if (sqlite3_column_int(stmt, 2) != result->ver) {
-                       result->type = CALS_UPDATED_TYPE_MODIFIED;
-               } else {
-                       result->type = CALS_UPDATED_TYPE_INSERTED;
-               }
-
-               result->calendar_id = sqlite3_column_int(stmt, 4);
-
-               if (iter->info->head == NULL) {
-                       iter->info->head = result;
-               } else {
-                       last->next = result;
-               }
-               last = result;
-               DBG("type(%d) calendar_id(%d)", result->type, result->calendar_id);
-       }
-       iter->i_type = CAL_STRUCT_TYPE_UPDATED_LIST;
-
-       sqlite3_finalize(stmt);
-
-       return CAL_SUCCESS;
-}
-
-
-API int calendar_svc_event_get_changes(int calendar_id, int version, cal_iter **iter)
-{
-       int ret;
-       cal_iter *it;
-
-       retv_if (NULL == iter, CAL_ERR_ARG_NULL);
-       retvm_if (version < 0, CAL_ERR_ARG_INVALID, "Invalid argument");
-
-       it = calloc(1, sizeof(cal_iter));
-       retvm_if (NULL == it, CAL_ERR_OUT_OF_MEMORY, "calloc() failed");
-
-       it->info = calloc(1, sizeof(cals_updated_info));
-       if (!it->info) {
-               ERR("calloc() Failed");
-               free(it);
-               return CAL_ERR_OUT_OF_MEMORY;
-       }
-
-       ret = cals_event_get_changes(calendar_id, version, it);
-       if (ret) {
-               ERR("cals_get_updated_schedules() failed(%d)", ret);
-               free(it->info);
-               free(it);
-               return ret;
-       }
-
-       *iter = it;
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_event_get_normal_list_by_period(int calendar_id, int op_code,
-               long long int stime, long long int etime, cal_iter **iter)
-{
-       /* calendar_id: -1 means searching all calendar */
-       retv_if(iter == NULL, CAL_ERR_ARG_NULL);
-
-       char query[CALS_SQL_MIN_LEN] = {0};
-       char buf[64] = {0};
-       sqlite3_stmt *stmt = NULL;
-
-       if (calendar_id > 0) {
-               snprintf(buf, sizeof(buf), "AND B.calendar_id = %d", calendar_id);
-       } else {
-               memset(buf, 0x0, sizeof(buf));
-       }
-
-       *iter = calloc(1, sizeof(cal_iter));
-       retvm_if(NULL == *iter, CAL_ERR_OUT_OF_MEMORY, "Failed to calloc(%d)", errno);
-       (*iter)->is_patched = 0;
-
-       switch (op_code) {
-       case CALS_LIST_PERIOD_NORMAL_ONOFF:
-               (*iter)->i_type = CALS_STRUCT_TYPE_PERIOD_NORMAL_ONOFF;
-               snprintf(query, sizeof(query),
-                               "SELECT A.event_id, "
-                               "B.dtstart_type, A.dtstart_utime, "
-                               "B.dtend_type, A.dtend_utime "
-                               "FROM %s as A, %s as B, %s as C "
-                               "ON A.event_id = B.id AND B.calendar_id = C.rowid "
-                               "WHERE ((A.dtstart_utime < %lld AND A.dtend_utime > %lld) "
-                               "OR A.dtstart_utime = %lld) "
-                               "AND B.type = %d AND B.is_deleted = 0 AND C.visibility = 1 %s "
-                               "ORDER BY A.dtstart_utime ",
-                               CALS_TABLE_NORMAL_INSTANCE, CALS_TABLE_SCHEDULE, CALS_TABLE_CALENDAR,
-                               etime, stime,
-                               stime,
-                               CALS_SCH_TYPE_EVENT, buf);
-               break;
-
-       case CALS_LIST_PERIOD_NORMAL_BASIC:
-               (*iter)->i_type = CALS_STRUCT_TYPE_PERIOD_NORMAL_BASIC;
-               snprintf(query, sizeof(query),
-                               "SELECT A.event_id, "
-                               "B.dtstart_type, A.dtstart_utime, "
-                               "B.dtend_type, A.dtend_utime, "
-                               "B.summary, B.location "
-                               "FROM %s as A, %s as B, %s as C "
-                               "ON A.event_id = B.id AND B.calendar_id = C.rowid "
-                               "WHERE ((A.dtstart_utime < %lld AND A.dtend_utime > %lld) "
-                               "OR A.dtstart_utime = %lld) "
-                               "AND B.type = %d AND B.is_deleted = 0 AND C.visibility = 1 %s "
-                               "ORDER BY A.dtstart_utime ",
-                               CALS_TABLE_NORMAL_INSTANCE, CALS_TABLE_SCHEDULE, CALS_TABLE_CALENDAR,
-                               etime, stime,
-                               stime,
-                               CALS_SCH_TYPE_EVENT, buf);
-               break;
-
-       case CALS_LIST_PERIOD_NORMAL_OSP:
-               (*iter)->i_type = CALS_STRUCT_TYPE_PERIOD_NORMAL_OSP;
-               snprintf(query, sizeof(query),
-                               "SELECT A.event_id, B.calendar_id, "
-                               "B.dtstart_type, A.dtstart_utime, "
-                               "B.dtend_type, A.dtend_utime, "
-                               "B.summary, B.description, B.location, B.busy_status, "
-                               "B.meeting_status, B.priority, B.sensitivity, B.rrule_id "
-                               "FROM %s as A, %s as B, %s as C "
-                               "ON A.event_id = B.id AND B.calendar_id = C.rowid "
-                               "WHERE ((A.dtstart_utime < %lld AND A.dtend_utime > %lld) "
-                               "OR A.dtstart_utime = %lld) "
-                               "AND B.type = %d AND B.is_deleted = 0 AND C.visibility = 1 %s "
-                               "ORDER BY A.dtstart_utime ",
-                               CALS_TABLE_NORMAL_INSTANCE, CALS_TABLE_SCHEDULE, CALS_TABLE_CALENDAR,
-                               etime, stime,
-                               stime,
-                               CALS_SCH_TYPE_EVENT, buf);
-               break;
-
-       case CALS_LIST_PERIOD_NORMAL_LOCATION:
-               (*iter)->i_type = CALS_STRUCT_TYPE_PERIOD_NORMAL_LOCATION;
-               snprintf(query, sizeof(query),
-                               "SELECT A.event_id, B.calendar_id, "
-                               "B.dtstart_type, A.dtstart_utime, "
-                               "B.dtend_type, A.dtend_utime, "
-                               "B.summary, B.description, B.location, B.busy_status, "
-                               "B.meeting_status, B.priority, B.sensitivity, B.rrule_id, "
-                               "B.latitude, B.longitude "
-                               "FROM %s as A, %s as B, %s as C "
-                               "ON A.event_id = B.id AND B.calendar_id = C.rowid "
-                               "WHERE ((A.dtstart_utime < %lld AND A.dtend_utime > %lld) "
-                               "OR A.dtstart_utime = %lld) "
-                               "AND B.type = %d AND B.is_deleted = 0 AND C.visibility = 1 %s "
-                               "ORDER BY A.dtstart_utime ",
-                               CALS_TABLE_NORMAL_INSTANCE, CALS_TABLE_SCHEDULE, CALS_TABLE_CALENDAR,
-                               etime, stime,
-                               stime,
-                               CALS_SCH_TYPE_EVENT, buf);
-               break;
-
-       case CALS_LIST_PERIOD_NORMAL_ALARM:
-               (*iter)->i_type = CALS_STRUCT_TYPE_PERIOD_NORMAL_ALARM;
-               snprintf(query, sizeof(query),
-                               "SELECT A.event_id, C.calendar_id, "
-                               "C.dtstart_type, A.dtstart_utime, "
-                               "C.dtend_type, A.dtend_utime, "
-                               "(A.dtstart_utime - (B.remind_tick * B.remind_tick_unit * 60)), "
-                               "B.alarm_id "
-                               "FROM %s as A, %s as B, %s as C "
-                               "ON A.event_id = B.event_id AND B.event_id = C.id "
-                               "WHERE C.type = %d AND C.is_deleted = 0 "
-                               "AND A.dtstart_utime - (B.remind_tick * B.remind_tick_unit * 60) >= %lld "
-                               "AND A.dtstart_utime - (B.remind_tick * B.remind_tick_unit * 60) < %lld "
-                               "%s "
-                               "ORDER BY B.alarm_time ",
-                               CALS_TABLE_NORMAL_INSTANCE, CALS_TABLE_ALARM, CALS_TABLE_SCHEDULE,
-                               CALS_SCH_TYPE_EVENT,
-                               stime, etime,
-                               buf);
-               break;
-
-       }
-       DBG("query(%s)", query);
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "Failed to query prepare");
-
-       (*iter)->stmt = stmt;
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_event_get_allday_list_by_period(int calendar_id, int op_code,
-               int dtstart_year, int dtstart_month, int dtstart_mday,
-               int dtend_year, int dtend_month, int dtend_mday, cal_iter **iter)
-{
-       /* calendar_id -1 means searching all calendar */
-       retv_if(iter == NULL, CAL_ERR_ARG_NULL);
-
-       sqlite3_stmt *stmt = NULL;
-       char query[CALS_SQL_MIN_LEN] = {0};
-       char buf[64] = {0};
-       char sdate[32] = {0};
-       char edate[32] = {0};
-
-       if (dtstart_year < 0 || dtstart_month < 0 || dtstart_mday < 0) {
-               ERR("Check start date(%d/%d/%d)", dtstart_year, dtstart_month, dtstart_mday);
-               return CAL_ERR_ARG_NULL;
-       }
-       if (dtend_year < 0 || dtend_month < 0 || dtend_mday < 0) {
-               ERR("Check end date(%d/%d/%d)", dtend_year, dtend_month, dtend_mday);
-               return CAL_ERR_ARG_NULL;
-       }
-
-       if (calendar_id > 0) {
-               snprintf(buf, sizeof(buf), "AND B.calendar_id = %d", calendar_id);
-       } else {
-               memset(buf, 0x0, sizeof(buf));
-       }
-
-       snprintf(sdate, sizeof(sdate), "%4d%02d%02d", dtstart_year, dtstart_month, dtstart_mday);
-       snprintf(edate, sizeof(edate), "%4d%02d%02d", dtend_year, dtend_month, dtend_mday);
-
-       *iter = calloc(1, sizeof(cal_iter));
-       retvm_if(NULL == *iter, CAL_ERR_OUT_OF_MEMORY, "Failed to calloc(%d)", errno);
-       (*iter)->is_patched = 0;
-
-       switch (op_code) {
-       case CALS_LIST_PERIOD_ALLDAY_ONOFF:
-               (*iter)->i_type = CALS_STRUCT_TYPE_PERIOD_ALLDAY_ONOFF;
-               snprintf(query, sizeof(query),
-                               "SELECT A.event_id, "
-                               "B.dtstart_type, A.dtstart_datetime, "
-                               "B.dtend_type, A.dtend_datetime "
-                               "FROM %s as A, %s as B, %s as C "
-                               "ON A.event_id = B.id AND B.calendar_id = C.rowid "
-                               "WHERE A.dtstart_datetime <= %s AND A.dtend_datetime >= %s "
-                               "AND B.type = %d AND B.is_deleted = 0 AND C.visibility = 1 %s "
-                               "ORDER BY A.dtstart_datetime ",
-                               CALS_TABLE_ALLDAY_INSTANCE, CALS_TABLE_SCHEDULE, CALS_TABLE_CALENDAR,
-                               edate, sdate,
-                               CALS_SCH_TYPE_EVENT, buf);
-               break;
-
-       case CALS_LIST_PERIOD_ALLDAY_BASIC:
-               (*iter)->i_type = CALS_STRUCT_TYPE_PERIOD_ALLDAY_BASIC;
-               snprintf(query, sizeof(query),
-                               "SELECT A.event_id, "
-                               "B.dtstart_type, A.dtstart_datetime, "
-                               "B.dtend_type, A.dtend_datetime, "
-                               "B.summary, B.location "
-                               "FROM %s as A, %s as B, %s as C "
-                               "ON A.event_id = B.id AND B.calendar_id = C.rowid "
-                               "WHERE A.dtstart_datetime <= %s AND A.dtend_datetime >= %s "
-                               "AND B.type = %d AND B.is_deleted = 0 AND C.visibility = 1 %s "
-                               "ORDER BY A.dtstart_datetime ",
-                               CALS_TABLE_ALLDAY_INSTANCE, CALS_TABLE_SCHEDULE, CALS_TABLE_CALENDAR,
-                               edate, sdate,
-                               CALS_SCH_TYPE_EVENT, buf);
-               break;
-
-       case CALS_LIST_PERIOD_ALLDAY_OSP:
-               (*iter)->i_type = CALS_STRUCT_TYPE_PERIOD_ALLDAY_OSP;
-               snprintf(query, sizeof(query),
-                               "SELECT A.event_id, B.calendar_id, "
-                               "B.dtstart_type, A.dtstart_datetime, "
-                               "B.dtend_type, A.dtend_datetime, "
-                               "B.summary, B.description, B.location, B.busy_status, "
-                               "B.meeting_status, B.priority, B.sensitivity, B.rrule_id "
-                               "FROM %s as A, %s as B, %s as C "
-                               "ON A.event_id = B.id AND B.calendar_id = C.rowid "
-                               "WHERE A.dtstart_datetime <= %s AND A.dtend_datetime >= %s "
-                               "AND B.type = %d AND B.is_deleted = 0 AND C.visibility = 1 %s "
-                               "ORDER BY A.dtstart_datetime ",
-                               CALS_TABLE_ALLDAY_INSTANCE, CALS_TABLE_SCHEDULE, CALS_TABLE_CALENDAR,
-                               edate, sdate,
-                               CALS_SCH_TYPE_EVENT, buf);
-               break;
-
-       case CALS_LIST_PERIOD_ALLDAY_LOCATION:
-               (*iter)->i_type = CALS_STRUCT_TYPE_PERIOD_ALLDAY_LOCATION;
-               snprintf(query, sizeof(query),
-                               "SELECT A.event_id, B.calendar_id, "
-                               "B.dtstart_type, A.dtstart_datetime, "
-                               "B.dtend_type, A.dtend_datetime, "
-                               "B.summary, B.description, B.location, B.busy_status, "
-                               "B.meeting_status, B.priority, B.sensitivity, B.rrule_id, "
-                               "B.latitude, B.longitude "
-                               "FROM %s as A, %s as B, %s as C "
-                               "ON A.event_id = B.id AND B.calendar_id = C.rowid "
-                               "WHERE A.dtstart_datetime <= %s AND A.dtend_datetime >= %s "
-                               "AND B.type = %d AND B.is_deleted = 0 AND C.visibility = 1 %s "
-                               "ORDER BY A.dtstart_datetime ",
-                               CALS_TABLE_ALLDAY_INSTANCE, CALS_TABLE_SCHEDULE, CALS_TABLE_CALENDAR,
-                               edate, sdate,
-                               CALS_SCH_TYPE_EVENT, buf);
-               break;
-/*
-       case CALS_LIST_PERIOD_ALLDAY_ALARM:
-               (*iter)->i_type = CALS_STRUCT_TYPE_PERIOD_ALLDAY_ALARM;
-               snprintf(query, sizeof(query),
-                               "SELECT B.event_id, B.alarm_time, B.alarm_id "
-                               "FROM %s as A, %s as B, %s as C "
-                               "ON A.event_id = B.event_id "
-                               "WHERE B.alarm_time >= %lld AND B.alarm_time < %lld "
-                               "AND C.type = %d AND C.is_deleted = 0 "
-                               "%s "
-                               "ORDER BY B.alarm_time ",
-                               CALS_TABLE_ALLDAY_INSTANCE, CALS_TABLE_ALARM, CALS_TABLE_SCHEDULE,
-                               sdate, edate,
-                               CALS_SCH_TYPE_EVENT,
-                               buf);
-               break;
-*/
-       }
-
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "Failed to query prepare");
-
-       (*iter)->stmt = stmt;
-       return CAL_SUCCESS;
-}
-
-/* delete instance from instance_table and update exdate from schedule_table */
-API int calendar_svc_event_delete_normal_instance(int event_id, long long int dtstart_utime)
-{
-       int ret, len, len_datetime;
-       char *exdate = NULL;
-       char *str_datetime = NULL;
-       char *p;
-       char query[CALS_SQL_MIN_LEN] = {0};
-       sqlite3_stmt *stmt;
-
-       ret = cals_begin_trans();
-       if (ret != CAL_SUCCESS) {
-               ERR("cals_begin_trans() Failed(%d)", ret);
-               cals_end_trans(false);
-               return ret;
-       }
-
-       len_datetime = strlen("YYYYMMDDTHHMMSSZ");
-
-       /* delete instance from normal_instance_table */
-       snprintf(query, sizeof(query), "DELETE FROM %s "
-                       "WHERE event_id = %d AND dtstart_utime = %lld ",
-                       CALS_TABLE_NORMAL_INSTANCE,
-                       event_id, dtstart_utime);
-
-       ret = cals_query_exec(query);
-       if (ret != CAL_SUCCESS) {
-               ERR("Failed to delete instance(errno:%d) [id:%d utime:%lld]",
-                               ret, event_id, dtstart_utime);
-               cals_end_trans(false);
-               return ret;
-       }
-
-       /* get exdate to append */
-       snprintf(query, sizeof(query), "SELECT %s FROM %s "
-                       "WHERE id = %d ",
-                       CAL_VALUE_TXT_EXDATE, CALS_TABLE_SCHEDULE,
-                       event_id);
-
-       stmt = cals_query_prepare(query);
-       if (stmt == NULL) {
-               ERR("cals_query_prepare() failed.");
-               cals_end_trans(false);
-               return CAL_ERR_DB_FAILED;
-       }
-
-       ret = cals_stmt_step(stmt);
-       if (ret == CAL_TRUE) {
-               exdate = (char *)sqlite3_column_text(stmt, 0);
-               DBG("exdate(%s)", exdate);
-
-       } else if (ret != CAL_SUCCESS) {
-               ERR("Failed to step(errno:%d)", ret);
-               sqlite3_finalize(stmt);
-               cals_end_trans(false);
-               return ret;
-       }
-
-       /* check whether exdate does already exist */
-       if (exdate == NULL || strlen(exdate) == 0) {
-               p = calloc(len_datetime + 1, sizeof(char));
-               if (p == NULL) {
-                       ERR("Failed to calloc");
-                       sqlite3_finalize(stmt);
-                       cals_end_trans(false);
-                       return CAL_ERR_OUT_OF_MEMORY;
-               }
-               str_datetime =  cals_time_get_str_datetime(NULL, dtstart_utime);
-               snprintf(p, len_datetime + 1, "%s", str_datetime);
-               DBG("inserted exdate firstly(%s)",  str_datetime);
-
-       } else {
-               DBG("append exdate");
-               len = strlen(exdate);
-               p = calloc(len + strlen(",") + len_datetime + 1, sizeof(char));
-               if (p == NULL) {
-                       ERR("Failed to calloc");
-                       sqlite3_finalize(stmt);
-                       cals_end_trans(false);
-                       return CAL_ERR_OUT_OF_MEMORY;
-               }
-               str_datetime =  cals_time_get_str_datetime(NULL, dtstart_utime);
-               snprintf(p, len + strlen(",") + len_datetime + 1, "%s,%s",
-                               exdate, str_datetime);
-       }
-       if (str_datetime) free(str_datetime);
-       sqlite3_finalize(stmt);
-
-       /* updaet exdate, version, last_mod from schedule table */
-       snprintf(query, sizeof(query), "UPDATE %s SET "
-                       "exdate = ?, "
-                       "changed_ver = %d, "
-                       "last_mod = strftime('%%s','now') "
-                       "WHERE id = %d ",
-                       CALS_TABLE_SCHEDULE,
-                       cals_get_next_ver(),
-                       event_id);
-
-       stmt = cals_query_prepare(query);
-       if (stmt == NULL) {
-               ERR("cals_query_prepare() failed.");
-               cals_end_trans(false);
-               return CAL_ERR_DB_FAILED;
-       }
-
-       cals_stmt_bind_text(stmt, 1, p);
-
-       ret = cals_stmt_step(stmt);
-       if (CAL_SUCCESS != ret) {
-               sqlite3_finalize(stmt);
-               ERR("sqlite3_step() Failed(%d)", ret);
-               cals_end_trans(false);
-               return ret;
-       }
-       sqlite3_finalize(stmt);
-
-       /* send noti */
-       ret = cals_notify(CALS_NOTI_TYPE_EVENT);
-       if (ret < 0) {
-               WARN("cals_notify failed (%d)", ret);
-       }
-
-       cals_end_trans(true);
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_event_delete_allday_instance(int event_id, int dtstart_year, int dtstart_month, int dtstart_mday)
-{
-       int ret, len, len_datetime;
-       char *exdate = NULL;
-       char *p;
-       char query[CALS_SQL_MIN_LEN] = {0};
-       char buf[32] = {0};
-       sqlite3_stmt *stmt;
-
-       ret = cals_begin_trans();
-       if (ret != CAL_SUCCESS) {
-               ERR("cals_begin_trans() Failed(%d)", ret);
-               cals_end_trans(false);
-               return ret;
-       }
-
-       len_datetime = strlen("YYYYMMDDTHHMMSSZ");
-
-       /* delete instance from normal_instance_table */
-       snprintf(buf, sizeof(buf), "%04d%02d%02d", dtstart_year, dtstart_month, dtstart_mday);
-       DBG("allday(%s)\n", buf);
-       snprintf(query, sizeof(query), "DELETE FROM %s "
-                       "WHERE event_id = %d AND dtstart_datetime = %s ",
-                       CALS_TABLE_ALLDAY_INSTANCE,
-                       event_id, buf);
-
-       ret = cals_query_exec(query);
-       if (ret != CAL_SUCCESS) {
-               ERR("Failed to delete instance(errno:%d) [id:%d datetime:%s]",
-                               ret, event_id, buf);
-               cals_end_trans(false);
-               return ret;
-       }
-
-       /* get exdate to append */
-       snprintf(query, sizeof(query), "SELECT %s FROM %s "
-                       "WHERE id = %d ",
-                       CAL_VALUE_TXT_EXDATE, CALS_TABLE_SCHEDULE,
-                       event_id);
-
-       stmt = cals_query_prepare(query);
-       if (stmt == NULL) {
-               ERR("cals_query_prepare() failed.");
-               cals_end_trans(false);
-               return CAL_ERR_DB_FAILED;
-       }
-
-       ret = cals_stmt_step(stmt);
-       if (ret == CAL_TRUE) {
-               exdate = (char *)sqlite3_column_text(stmt, 0);
-               DBG("exdate(%s)", exdate);
-
-       } else if (ret != CAL_SUCCESS) {
-               ERR("Failed to step(errno:%d)", ret);
-               sqlite3_finalize(stmt);
-               cals_end_trans(false);
-               return ret;
-       }
-
-       /* check whether exdate does already exist */
-       if (exdate == NULL || strlen(exdate) == 0) {
-               p = calloc(len_datetime + 1, sizeof(char));
-               if (p == NULL) {
-                       ERR("Failed to calloc");
-                       sqlite3_finalize(stmt);
-                       return CAL_ERR_OUT_OF_MEMORY;
-               }
-               snprintf(p, len_datetime + 1, "%s", buf);
-               DBG("inserted exdate firstly(%s)",  buf);
-
-       } else {
-               DBG("append exdate");
-               len = strlen(exdate);
-               p = calloc(len + strlen(",") + len_datetime + 1, sizeof(char));
-               if (p == NULL) {
-                       ERR("Failed to calloc");
-                       sqlite3_finalize(stmt);
-                       cals_end_trans(false);
-                       return CAL_ERR_OUT_OF_MEMORY;
-               }
-               snprintf(p, len + strlen(",") + len_datetime + 1, "%s,%s",
-                               exdate, buf);
-       }
-       sqlite3_finalize(stmt);
-
-       /* updaet exdate from schedule table */
-       snprintf(query, sizeof(query), "UPDATE %s SET "
-                       "exdate = ? "
-                       "WHERE id = %d ",
-                       CALS_TABLE_SCHEDULE,
-                       event_id);
-
-       stmt = cals_query_prepare(query);
-       if (stmt == NULL) {
-               ERR("cals_query_prepare() failed.");
-               cals_end_trans(false);
-               return CAL_ERR_DB_FAILED;
-       }
-
-       cals_stmt_bind_text(stmt, 1, p);
-
-       ret = cals_stmt_step(stmt);
-       if (CAL_SUCCESS != ret) {
-               sqlite3_finalize(stmt);
-               ERR("sqlite3_step() Failed(%d)", ret);
-               cals_end_trans(false);
-               return ret;
-       }
-       sqlite3_finalize(stmt);
-
-       /* send noti */
-       ret = cals_notify(CALS_NOTI_TYPE_EVENT);
-       if (ret < 0) {
-               WARN("cals_notify failed (%d)", ret);
-       }
-
-       cals_end_trans(true);
-
-       return CAL_SUCCESS;
-}
-
-
-
-
-
diff --git a/src/cals-ical.c b/src/cals-ical.c
deleted file mode 100755 (executable)
index 7bad90a..0000000
+++ /dev/null
@@ -1,3595 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <glib.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <ctype.h>
-
-#include "cals-typedef.h"
-#include "cals-ical.h"
-#include "cals-utils.h"
-#include "cals-db.h"
-#include "cals-internal.h"
-#include "cals-schedule.h"
-#include "cals-struct.h"
-#include "cals-utils.h"
-#include "cals-time.h"
-
-#define ICALENAR_BUFFER_MAX (1024*1024)
-
-
-enum {
-       ENCODE_NONE = 0x0,
-       ENCODE_BASE64,
-       ENCODE_QUOTED_PRINTABLE,
-       ENCODE_MAX,
-};
-
-
-struct _comp_func {
-       char *prop;
-       char *(*func)(GList **list_sch, void *data);
-};
-
-struct _prop_func {
-       char *prop;
-       int (*func)(GList **list_sch, void *data);
-};
-
-struct _veve_func {
-       char *prop;
-       int (*func)(int ver, cal_sch_full_t *sch, void *data);
-};
-
-struct _vala_func {
-       char *prop;
-       int (*func)(cal_sch_full_t *sch, void *data);
-};
-
-struct _rrule_func {
-       char *prop;
-       int (*func)(cal_sch_full_t *sch, void *data);
-};
-
-
-struct _val_func {
-       char *prop;
-       int (*func)(int *val, void *data);
-};
-
-
-char *cals_func_vcalendar(GList **list_sch, void *data);
-char *cals_func_vevent(int ver, GList **list_sch, void *data);
-char *cals_func_vtodo(int ver, GList **list_sch, void *data);
-char *cals_func_valarm(cal_sch_full_t *sch, void *data);
-
-enum {
-       VCAL_PRODID = 0x0,
-       VCAL_VERSION,
-//     VCAL_CALSCALE,
-//     VCAL_METHOD,
-       VCAL_MAX,
-};
-
-int cals_func_prodid(GList **list_sch, void *data);
-int cals_func_version(GList **list_sch, void *data);
-
-struct _prop_func _vcal_list[VCAL_MAX] =
-{
-       {"PRODID", cals_func_prodid },
-       {"VERSION", cals_func_version }//,
-//     {"CALSCALE", cals_func_calscale },
-//     {"METHOD", cals_func_method }
-};
-
-int cals_func_dtstamp(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_dtstart(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_uid(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_class(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_created(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_description(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_geo(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_last_mod(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_location(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_organizer(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_priority(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_seq(int ver, cal_sch_full_t *sch, void *data);
-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);
-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_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);
-int cals_func_contact(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_exdate(int ver, cal_sch_full_t *sch, void *data);
-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);
-
-enum {
-       VEVE_DTSTAMP = 0x0,
-       VEVE_DTSTART,
-//     VEVE_UID,
-//     VEVE_CLASS,
-       VEVE_CREATED,
-       VEVE_DESCRIPTION,
-//     VEVE_GEO,
-       VEVE_LAST_MOD,
-       VEVE_LOCATION,
-//     VEVE_ORGANIZER,
-       VEVE_PRIORITY,
-//     VEVE_SEQ,
-       VEVE_STATUS,
-       VEVE_SUMMARY,
-//     VEVE_TRANSP,
-//     VEVE_URL,
-//     VEVE_RECURID,
-       VEVE_RRULE,
-       VEVE_DTEND,
-//     VEVE_DURATION,
-//     VEVE_ATTACH,
-       VEVE_ATTENDEE,
-       VEVE_CATEGORIES,
-//     VEVE_COMMENT,
-//     VEVE_CONTACT,
-//     VEVE_EXDATE,
-//     VEVE_RSTATUS,
-//     VEVE_RELATED,
-//     VEVE_RESOURCES,
-//     VEVE_RDATE,
-       VEVE_AALARM,    /* for ver 1.0 */
-       VEVE_MAX,
-};
-
-struct _veve_func _veve_list[VEVE_MAX] =
-{
-       { "DTSTAMP", cals_func_dtstamp },
-       { "DTSTART", cals_func_dtstart },
-//     { "UID", cals_func_uid },
-//     { "CLASS", cals_func_class },
-       { "CREATED", cals_func_created },
-       { "DESCRIPTION", cals_func_description },
-//     { "GEO", cals_func_geo },
-       { "LAST-MOD", cals_func_last_mod },
-       { "LOCATION", cals_func_location },
-//     { "ORGANIZER", cals_func_organizer },
-       { "PRIORITY", cals_func_priority },
-//     { "SEQ", cals_func_seq },
-       { "STATUS", cals_func_status },
-       { "SUMMARY", cals_func_summary },
-//     { "TRANSP", cals_func_transp },
-//     { "URL", cals_func_url },
-//     { "RECURID", cals_func_recurid },
-       { "RRULE", cals_func_rrule1 },
-       { "DTEND", cals_func_dtend },
-//     { "DURATION", cals_func_duration },
-//     { "ATTACH", cals_func_attach },
-       { "ATTENDEE", cals_func_attendee },
-       { "CATEGORIES", cals_func_categories },
-//     { "COMMENT", cals_func_comment },
-//     { "CONTACT", cals_func_contact },
-//     { "EXDATE", cals_func_exdate },
-//     { "RSTATUS", cals_func_rstatus },
-//     { "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);
-int cals_func_trigger(cal_sch_full_t *sch, void *data);
-int cals_func_repeat(cal_sch_full_t *sch, void *data);
-int cals_func_duration_alarm(cal_sch_full_t *sch, void *data);
-int cals_func_attach_alarm(cal_sch_full_t *sch, void *data);
-int cals_func_summary_alarm(cal_sch_full_t *sch, void *data);
-
-enum {
-       VALA_ACTION = 0x0,
-       VALA_TRIGGER,
-       VALA_REPEAT,
-       VALA_DURATION,
-       VALA_ATTACH,
-//     VALA_DESCRIPTION,
-       VALA_SUMMARY,
-//     VALA_ATTENDEE,
-       VALA_MAX,
-};
-
-struct _vala_func _vala_list[VALA_MAX] =
-{
-       { "ACTION", cals_func_action },
-       { "TRIGGER", cals_func_trigger },
-       { "REPEAT", cals_func_repeat },
-       { "DURATION", cals_func_duration_alarm },
-       { "ATTACH", cals_func_attach_alarm },
-//     { "DESCRIPTION", cals_func_description },
-       { "SUMMARY", cals_func_summary_alarm },
-//     { "ATTENDEE", cals_func_attendee },
-};
-
-int cals_func_freq(cal_sch_full_t *sch, void *data);
-int cals_func_until(cal_sch_full_t *sch, void *data);
-int cals_func_count(cal_sch_full_t *sch, void *data);
-int cals_func_interval(cal_sch_full_t *sch, void *data);
-int cals_func_bysecond(cal_sch_full_t *sch, void *data);
-int cals_func_byminute(cal_sch_full_t *sch, void *data);
-int cals_func_byhour(cal_sch_full_t *sch, void *data);
-int cals_func_byday(cal_sch_full_t *sch, void *data);
-int cals_func_bymonthday(cal_sch_full_t *sch, void *data);
-int cals_func_byyearday(cal_sch_full_t *sch, void *data);
-int cals_func_byweekno(cal_sch_full_t *sch, void *data);
-int cals_func_bymonth(cal_sch_full_t *sch, void *data);
-int cals_func_bysetpos(cal_sch_full_t *sch, void *data);
-int cals_func_wkst(cal_sch_full_t *sch, void *data);
-
-enum {
-       RRULE_FREQ = 0x0,
-       RRULE_UNTIL,
-       RRULE_COUNT,
-       RRULE_INTERVAL,
-       RRULE_BYSECOND,
-       RRULE_BYMINUTE,
-       RRULE_BYHOUR,
-       RRULE_BYDAY,
-       RRULE_BYMONTHDAY,
-       RRULE_BYYEARDAY,
-       RRULE_BYWEEKNO,
-       RRULE_BYMONTH,
-       RRULE_BYSETPOS,
-       RRULE_WKST,
-       RRULE_MAX,
-};
-
-struct _rrule_func _rrule_list[RRULE_MAX] =
-{
-       { "FREQ=", cals_func_freq },
-       { "UNTIL=", cals_func_until },
-       { "COUNT=", cals_func_count },
-       { "INTERVAL=", cals_func_interval },
-       { "BYSECOND=", cals_func_bysecond },
-       { "BYMINUTE=", cals_func_byminute },
-       { "BYHOUR=", cals_func_byhour },
-       { "BYDAY=", cals_func_byday },
-       { "BYMONTHDAY=", cals_func_bymonthday },
-       { "BYYEARDAY=", cals_func_byyearday },
-       { "BYWEEKNO=", cals_func_byweekno },
-       { "BYMONTH=", cals_func_bymonth },
-       { "BYSETPOS=", cals_func_bysetpos },
-       { "WKST=", cals_func_wkst }
-};
-
-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,
-       TRIG_VALUE,
-       TRIG_MAX,
-};
-
-struct _vala_func _trig_list[TRIG_MAX] =
-{
-       { "RELATED=", cals_func_trig_related },
-       { "VALUE=", cals_func_trig_value }
-};
-
-int cals_func_charset(int *val, void *data);
-int cals_func_encoding(int *val, void *data);
-
-
-enum {
-       TEXT_CHARSET = 0x0,
-       TEXT_ENCODING,
-       TEXT_MAX,
-};
-
-struct _val_func _optional_list[TEXT_MAX] =
-{
-       { "CHARSET=", cals_func_charset },
-       { "ENCODING=", cals_func_encoding },
-};
-
-char *cals_convert_sec_from_duration(char *p, int *dur_t, char *dur);
-
-//util //////////////////////////////////////////////////////////////////////
-
-
-char *cals_skip_empty_line(char *src)
-{
-       CALS_FN_CALL;
-       while (*src) {
-               if ('\n' != *src && '\r' != *src) {
-                       break;
-               }
-               src++;
-       }
-       return src;
-}
-
-int cals_file_exist(const char *path)
-{
-       FILE *fp;
-
-       fp = fopen(path, "r");
-
-       if (fp == NULL) {
-               ERR("Failed to access path(%s)\n", path);
-               return -1;
-       }
-       fclose(fp);
-       return 0;
-}
-
-char *cals_check_word(char *src, const char *word)
-{
-       int start = 0;
-
-       src = cals_skip_empty_line(src);
-
-       while (*src) {
-               switch (*src) {
-               case ' ':
-               case ':':
-               case ';':
-                       src++;
-                       break;
-               default:
-                       start = 1;
-                       break;
-               }
-               if (start) break;
-       }
-
-       while (*src == *word) {
-               src++;
-               word++;
-
-               if ('\0' == *src || '\0' == *word)
-                       break;
-       }
-
-       if ('\0' == *word)
-               return src;
-       else
-               return NULL;
-}
-
-char cals_2hexa_to_1char(char *p)
-{
-       int i;
-       char decoded[2] = {0x00, 0x00};
-
-       for (i = 0; i < 2; i++) {
-               switch (p[i]) {
-               case '0' ... '9':
-                       decoded[i] = p[i] - '0';
-                       break;
-               case 'a' ... 'f':
-                       decoded[i] = p[i] - 'a' + 10;
-                       break;
-               case 'A' ... 'F':
-                       decoded[i] = p[i] - 'A' + 10;
-                       break;
-               }
-       }
-
-       return (char)((decoded[0] << 4) + decoded[1]);
-}
-
-int cals_quoted_printable_decode(char *p, int *len)
-{
-       CALS_FN_CALL;
-       int i = 0, j = 0;
-       char ch;
-
-       while (p[i]) {
-               if (p[i] == '=') {
-                       if (p[i+1] == 0x09 || p[i+1] == 0x20) {
-                               i +=3;
-
-                       } else if (p[i+1] == '\r' || p[i+1] == '\n') {
-                               i +=3;
-
-                       } else {
-                               if (p[i+1] == '0' && tolower(p[i+2]) == 'd' &&
-                                               p[i+3] == '=' && p[i+4] == '0' && tolower(p[i+5]) == 'a') {
-                                       p[j] = '\n';
-                                       j++;
-                                       i += 6;
-                               } else {
-                                       ch = cals_2hexa_to_1char(&p[i+1]);
-                                       p[j] = ch;
-                                       j++;
-                                       i += 3;
-                               }
-                       }
-               } else {
-                       p[j] = p[i];
-                       j++;
-                       i++;
-               }
-       }
-       p[j] = '\0';
-       *len = i;
-       return 0;
-}
-
-////////////////////////////////////////////////////////////////////////
-
-
-cal_sch_full_t *cals_add_vcalendar(void)
-{
-       cal_sch_full_t *sch;
-
-       sch = calloc(1, sizeof(cal_sch_full_t));
-       if (sch == NULL) {
-               return NULL;
-       }
-       return sch;
-}
-
-
-int cals_unfold_content(char *stream)
-{
-       CALS_FN_CALL;
-       char *p;
-
-       retv_if(stream == NULL, CAL_ERR_ARG_NULL);
-
-       p = stream;
-       while (*stream) {
-               if ('\n' == *stream && ' ' == *(stream + 1)) {
-                       stream += 2;
-                       p--;
-               } else if ('\0' == *stream) {
-                       CALS_DBG("break\n");
-                       break;
-               }
-               *p = *stream;
-               p++;
-               stream++;
-
-       }
-       return 0;
-}
-
-
-char *cals_read_line(char *stream, char **prop, char **cont)
-{
-       int i;
-       char *p, *q;
-       int out;
-
-       /* skip space */
-       p = stream;
-       q = p;
-       out = 0;
-       while (*p) {
-               switch (*p) {
-               case ' ':
-                       break;
-               default:
-                       out = 1;
-                       break;
-               }
-               if (out == 1) {
-                       break;
-               }
-               p++;
-       }
-
-       i = 0;
-       out = 0;
-       q = p;
-       while (*p) {
-               switch (*p) {
-               case ';':
-               case ':':
-                       out = 1;
-                       break;
-               default:
-                       i++;
-                       break;
-               }
-               if (out == 1) {
-                       i++;
-                       break;
-               }
-               p++;
-       }
-
-       if (0 < i) {
-               *prop = calloc(1, i);
-               snprintf(*prop, i, "%s", q);
-       } else {
-               *prop = NULL;
-               return NULL;
-       }
-
-       i = 0;
-       out = 0;
-       q = p;
-
-       while (*p) {
-               switch (*p) {
-               case '\r':
-                       if ('\n' == *(p + 1)) {
-                               out = 1;
-                       }
-                       break;
-               case '\0':
-                       break;
-               default:
-                       i++;
-                       break;
-               }
-               if (out == 1) {
-                       i++;
-                       break;
-               }
-               p++;
-       }
-
-       if (0 < i) {
-               *cont = calloc(1, i);
-               snprintf(*cont, i, "%s", q);
-               p += 2;
-       } else {
-               *cont = NULL;
-               return NULL;
-       }
-
-       DBG("%s][%s\n", *prop, *cont);
-       return p;
-}
-
-inline void cals_get_optional_parameter(char *p, int *encoding)
-{
-       int i;
-
-       for (i = 0; i < TEXT_MAX; i++) {
-               if (!strncmp(p, _optional_list[i].prop, strlen(_optional_list[i].prop))) {
-                       int j = 0;
-                       char buf[64] = {0, };
-                       p += strlen(_optional_list[i].prop);
-                       while (p[j] != ':' && p[j] != ';' && p[j] != '\n' && p[j] != '\0') {
-                               buf[j] = p[j];
-                               j++;
-                       }
-                       if (p[j] != '\0') {
-                               buf[j] = '\0';
-                       }
-
-                       p += j;
-                       _optional_list[i].func(encoding, buf);
-                       break;
-               } else {
-
-               }
-       }
-}
-
-API int calendar_svc_read_schedules(const char *stream, GList **schedules)
-{
-       CALS_FN_CALL;
-       int ret = 0;
-       char *prop, *cont;
-       char *cursor;
-       GList *l = NULL;
-
-       cursor = (char *)stream;
-
-       retv_if(stream == NULL, CAL_ERR_ARG_INVALID);
-       cursor = cals_skip_empty_line(cursor);
-       retvm_if(cursor == NULL, CAL_ERR_FAIL, "Failed to skip empty line\n");
-       cals_unfold_content(cursor);
-
-       cursor = cals_read_line(cursor, &prop, &cont);
-       retvm_if(cursor == NULL, CAL_ERR_FAIL, "Failed to read line\n");
-
-       if (strncmp(prop, "BEGIN", strlen("BEGIN")) ||
-                       strncmp(cont + 1, "VCALENDAR", strlen("VCALENDAR"))) {
-               ERR("Failed to find BEGIN:VCALDENDAR [%s][%s]", prop, cont);
-               free(prop);
-               free(cont);
-               return CAL_ERR_FAIL;
-       }
-       free(prop);
-       free(cont);
-
-       cursor = cals_func_vcalendar(&l, cursor);
-
-       if (l == NULL) {
-               ERR("No schedules");
-               return CAL_ERR_NO_DATA;
-       }
-
-       *schedules = l;
-       return ret;
-}
-#ifndef CALS_IPC_CLIENT
-int cals_do_importing(int calendar_id, char *stream, void *data)
-{
-       int ret;
-       GList *list_sch = NULL;
-       GList *l;
-       cal_struct *cs;
-       cal_sch_full_t *sch;
-
-       ret = calendar_svc_read_schedules(stream, &list_sch);
-       retvm_if(ret < 0, ret, "Failed to parse(%d)", ret);
-
-       /* calendar id validation check */
-
-       /* insert schedules to db */
-       l = list_sch;
-       while (l) {
-               sch = (cal_sch_full_t *)((cal_struct *)l->data)->user_data;
-               if (sch) {
-                       sch->calendar_id = calendar_id;
-                       ret = cals_insert_schedule(sch);
-               }
-
-               l = g_list_next(l);
-       }
-
-       /* free schedules in memory */
-       l = list_sch;
-       while (l) {
-               cs = (cal_struct *)l->data;
-               if (cs == NULL) {
-                       ERR("Not cal struct\n");
-                       break;
-               }
-               calendar_svc_struct_free(&cs);
-               l = g_list_next(l);
-       }
-       g_list_free(list_sch);
-
-       return ret;
-}
-#endif
-static const char* cals_get_stream_from_path(const char *path)
-{
-       FILE *file;
-       int buf_size, len;
-       char *stream;
-       char buf[1024];
-
-       file = fopen(path, "r");
-
-       len = 0;
-       buf_size = ICALENAR_BUFFER_MAX;
-       stream = malloc(ICALENAR_BUFFER_MAX);
-
-       while (fgets(buf, sizeof(buf), file)) {
-               if (len + sizeof(buf) < buf_size) {
-                       len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
-
-               } else {
-                       char *new_stream;
-                       buf_size *= 2;
-                       new_stream = realloc(stream, buf_size);
-                       if (new_stream) {
-                               stream = new_stream;
-                       } else {
-                               free(stream);
-                               fclose(file);
-                               ERR("out of memory\n");
-                               return NULL;
-                       }
-                       len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
-               }
-       }
-       fclose(file);
-       return stream;
-}
-
-int calendar_svc_read_schedules_from_file(const char *path, GList **schedules)
-{
-       const char *stream;
-       int ret;
-
-       ret = cals_file_exist(path);
-       if (ret < 0) {
-               ERR("Failed to access path(%s)\n", path);
-               return -1;
-       }
-
-       stream = cals_get_stream_from_path(path);
-       retvm_if(stream == NULL, -1, "Failed to get stream from path(%s)", path);
-
-       ret = calendar_svc_read_schedules(stream, schedules);
-       if (ret < 0) {
-               ERR("Failed to parse ics\n");
-               if (stream) {
-                       free((void *)stream);
-               }
-               return -1;
-       }
-
-       if (stream) {
-               free((void *)stream);
-       }
-       return 0;
-}
-#ifndef CALS_IPC_CLIENT
-int cals_import_schedules(const char *path, int calendar_id)
-{
-       FILE *file;
-       int buf_size, len;
-       char *stream;
-       char buf[1024];
-
-       file = fopen(path, "r");
-
-       len = 0;
-       buf_size = ICALENAR_BUFFER_MAX;
-       stream = malloc(ICALENAR_BUFFER_MAX);
-
-       while (fgets(buf, sizeof(buf), file)) {
-               if (len + sizeof(buf) < buf_size) {
-                       len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
-
-               } else {
-                       char *new_stream;
-                       buf_size *= 2;
-                       new_stream = realloc(stream, buf_size);
-                       if (new_stream) {
-                               stream = new_stream;
-                       } else {
-                               if (stream) free(stream);
-                               fclose(file);
-                               ERR("out of memory");
-                               return CAL_ERR_OUT_OF_MEMORY;
-                       }
-                       len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
-               }
-
-               if (!strncmp(buf, "END:VCALENDAR", strlen("END:VCALENDAR"))){
-                       DBG("end vcalendar");
-
-                       if (cals_do_importing(calendar_id, stream, NULL)) {
-                               if (stream) free(stream);
-                               fclose(file);
-                               return 0;
-                       }
-                       len = 0;
-               }
-       }
-       if (stream) free(stream);
-       fclose(file);
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_calendar_import(const char *path, int calendar_id)
-{
-       int ret;
-       retv_if(path == NULL, CAL_ERR_ARG_INVALID);
-
-       ret = cals_file_exist(path);
-       if (ret < 0) {
-               ERR("Failed to access (%s)\n", path);
-               return -1;
-       }
-
-       ret = cals_import_schedules(path, calendar_id);
-       return ret;
-}
-#endif
-
-
-// func ////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////
-
-char *cals_func_vcalendar(GList **list_sch, void *data)
-{
-       CALS_FN_CALL;
-       int ver = -1;
-       char *prop, *cont;
-       char *cursor = (char *)data;
-       char *p = cursor;
-
-       /* do until meet BEGIN */
-       while ((cursor = cals_read_line(cursor, &prop, &cont))) {
-               if (!strncmp(prop, "BEGIN", strlen("BEGIN"))) {
-                       if (prop) free(prop);
-                       if (cont) free(cont);
-
-                       break;
-
-               }
-
-               if (!strncmp(prop, "PRODID", strlen("PRODID"))) {
-                       _vcal_list[VCAL_PRODID].func(list_sch, cont);
-
-               } else if (!strncmp(prop, "VERSION", strlen("VERSION"))) {
-                       ver = _vcal_list[VCAL_VERSION].func(list_sch, cont);
-
-               } else {
-
-               }
-
-               if (prop) {
-                       free(prop);
-                       prop = NULL;
-               }
-               if (cont) {
-                       free(cont);
-                       cont = NULL;
-               }
-
-               p = cursor;
-       }
-
-       cursor = p;
-       while ((cursor = cals_read_line(cursor, &prop, &cont))) {
-               if (!strncmp(prop, "BEGIN", strlen("BEGIN"))) {
-
-                       if (!strncmp(cont + 1, "VEVENT", strlen("VEVENT"))) {
-                               cursor = cals_func_vevent(ver, list_sch, cursor);
-
-                       } else if (!strncmp(cont + 1, "VTODO", strlen("VTODO"))) {
-                               cursor = cals_func_vtodo(ver, list_sch, cursor);
-/*
-                       } else if (!strncmp(cont + 1, "VFREEBUSY", strlen("VFREEBUSY"))) {
-                       } else if (!strncmp(cont + 1, "VTIMEZONE", strlen("VTIMEZONE"))) {
-                       } else if (!strncmp(cont + 1, "STANDARD", strlen("STANDARD"))) {
-                       } else if (!strncmp(cont + 1, "DAYLIGHT", strlen("DAYLIGHT"))) {
-*/
-                       } else {
-
-                       }
-
-               } else if (!strncmp(prop, "END", strlen("END"))) {
-                       if (prop) free(prop);
-                       if (cont) free(cont);
-
-                       break;
-
-               }
-
-               if (prop) {
-                       free(prop);
-                       prop = NULL;
-               }
-               if (cont) {
-                       free(cont);
-                       cont = NULL;
-               }
-       }
-
-       return cursor;
-}
-
-char *cals_func_vevent(int ver, GList **list_sch, void *data)
-{
-       CALS_FN_CALL;
-       int i;
-       char *prop, *cont;
-       char *cursor = (char *)data;
-       GList *l;
-       cal_struct *cs;
-       cal_sch_full_t *sch;
-
-       sch = calloc(1, sizeof(cal_sch_full_t));
-       retvm_if(sch == NULL, NULL, "Failed to alloc cal_sch_full_t");
-       cals_event_init(sch);
-
-       cs = calloc(1, sizeof(cal_struct));
-       retvm_if(cs == NULL, NULL, "Failed to alloc cal_struct");
-       cs->event_type = CAL_STRUCT_TYPE_SCHEDULE;
-       cs->user_data = sch;
-
-       *list_sch = g_list_append(*list_sch, cs);
-
-       /* do until meet BEGIN */
-       while ((cursor = cals_read_line(cursor, &prop, &cont))) {
-               if (!strncmp(prop, "BEGIN", strlen("BEGIN"))) {
-
-                       if (!strncmp(cont + 1, "VALARM", strlen("VALARM"))) {
-                               cursor = cals_func_valarm(sch, cursor);
-                       } else {
-                               break;
-                       }
-
-               } else if (!strncmp(prop, "END", strlen("END"))) {
-                       break;
-
-               } else {
-                       for (i = 0; i < VEVE_MAX; i++) {
-                               if (!strncmp(prop, _veve_list[i].prop, strlen(_veve_list[i].prop))) {
-                                       l = g_list_last(*list_sch);
-                                       _veve_list[i].func(ver, ((cal_struct *)(l->data))->user_data, cont);
-                                       break;
-                               }
-                       }
-               }
-
-               if (prop) free(prop);
-               prop = NULL;
-               if (cont) free(cont);
-               cont = NULL;
-
-       }
-
-       if (prop) free(prop);
-       if (cont) free(cont);
-       return cursor;
-}
-
-/*TODO: vtodo is same as vevent */
-char *cals_func_vtodo(int ver, GList **list_sch, void *data)
-{
-       int i;
-       char *prop, *cont;
-       char *cursor = (char *)data;
-       GList *l;
-       cal_struct *cs;
-       cal_sch_full_t *sch;
-
-       sch = calloc(1, sizeof(cal_sch_full_t));
-       retvm_if(sch == NULL, NULL, "Failed to alloc cal_sch_full_t");
-       cals_todo_init(sch);
-
-       cs = calloc(1, sizeof(cal_struct));
-       retvm_if(cs == NULL, NULL, "Failed to alloc cal_struct");
-       cs->event_type = CAL_STRUCT_TYPE_SCHEDULE;
-       cs->user_data = sch;
-
-       *list_sch = g_list_append(*list_sch, cs);
-
-       /* do until meet BEGIN */
-       while ((cursor = cals_read_line(cursor, &prop, &cont))) {
-               if (!strncmp(prop, "BEGIN", strlen("BEGIN"))) {
-
-                       if (!strncmp(cont + 1, "VALARM", strlen("VALARM"))) {
-                               cursor = cals_func_valarm(sch, cursor);
-                       } else {
-                               break;
-                       }
-
-               } else if (!strncmp(prop, "END", strlen("END"))) {
-                       break;
-
-               } else {
-                       for (i = 0; i < VEVE_MAX; i++) {
-                               if (!strncmp(prop, _veve_list[i].prop, strlen(_veve_list[i].prop))) {
-                                       l = g_list_last(*list_sch);
-                                       _veve_list[i].func(ver, ((cal_struct *)(l->data))->user_data, cont);
-                                       break;
-                               }
-                       }
-               }
-
-               if (prop) free(prop);
-               prop = NULL;
-               if (cont) free(cont);
-               cont = NULL;
-
-       }
-
-       if (prop) free(prop);
-       if (cont) free(cont);
-       return cursor;
-}
-
-char *cals_func_valarm(cal_sch_full_t *sch, void *data)
-{
-       int i;
-       char *prop, *cont;
-       char *cursor = (char *)data;
-
-       cal_value *val;
-       val = calendar_svc_value_new(CAL_VALUE_LST_ALARM);
-       sch->alarm_list = g_list_append(sch->alarm_list, val);
-
-       while ((cursor = cals_read_line(cursor, &prop, &cont))) {
-               if (!strncmp(prop, "BEGIN", strlen("BEGIN"))) {
-                       break;
-
-               } else if (!strncmp(prop, "END", strlen("END"))) {
-                       break;
-
-               }
-
-               for (i = 0; i < VALA_MAX; i++) {
-                       if (!strncmp(prop, _vala_list[i].prop, strlen(_vala_list[i].prop))) {
-                               _vala_list[i].func(sch, cont);
-                               break;
-                       }
-               }
-               if (prop) {
-                       free(prop);
-                       prop = NULL;
-               }
-               if (cont) {
-                       free(cont);
-                       cont = NULL;
-               }
-       }
-
-       if (prop) free(prop);
-       if (cont) free(cont);
-
-       return cursor;
-}
-
-
-/* vcalendar */////////////////////////////////////////////////
-
-int cals_func_prodid(GList **list_sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_version(GList **list_sch, void *data)
-{
-       char *p = (char *)data;
-
-       p++;
-       if (!strncmp(p, "1.0", strlen("1.0"))) {
-               return 1;
-       } else if (!strncmp(p, "2.0", strlen("2.0"))) {
-               return 2;
-       } else {
-               return -1;
-       }
-       return 0;
-}
-
-/* vevnt */////////////////////////////////////////////////
-int cals_func_dtstamp(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_dtstart(int ver, cal_sch_full_t *sch, void *data)
-{
-       char *p = (char *)data;
-       int k = 0, j;
-       int y, mon, d, h, min, s;
-       char buf[64] = {0, };
-       char tmp[64] = {0, };
-
-       p++;
-
-       if (!strncmp(p, "TZID=", strlen("TZID="))) {
-               k = 0;
-               j = 0;
-               while (p[j] != ':' && p[j] != ';' && p[j] != '\n' && p[j] != '\0') {
-                       buf[k] = p[j];
-                       k++;
-                       j++;
-               }
-               if (p[j] != '\0') {
-                       buf[k] = '\0';
-               }
-               p += j;
-               p++;
-               sch->dtstart_tzid = strdup(buf);
-       } else {
-               sch->dtstart_tzid = strdup(CALS_TZID_0);
-       }
-
-       if (!strncmp(p, "VALUE=", strlen("VALUE="))) {
-               k = 0;
-               j = strlen("VALUE=");
-               while (p[j] != ':' && p[j] != ';' && p[j] != '\n' && p[j] != '\0') {
-                       buf[k] = p[j];
-                       k++;
-                       j++;
-               }
-               if (p[j] != '\0') {
-                       buf[k] = '\0';
-               }
-               p += j;
-               p++;
-       }
-
-       if (!strncmp(buf, "DATE", strlen("DATE"))){
-               snprintf(tmp, 5, "%s", p);
-               sch->dtstart_year = atoi(tmp);
-               snprintf(tmp, 3, "%s", p + 4);
-               sch->dtstart_month = atoi(tmp);
-               snprintf(tmp, 3, "%s", p + 6);
-               sch->dtstart_mday = atoi(tmp);
-
-       } else {
-               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);
-               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);
-               sch->dtstart_utime = cals_time_date_to_utime(sch->dtstart_tzid,
-                               y, mon, d, h, min, s);
-       }
-       return 0;
-}
-
-int cals_func_uid(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_class(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_created(int ver, cal_sch_full_t *sch, void *data)
-{
-       char *p = (char *)data;
-
-       p++;
-       sch->created_time = _datetime_to_utime(p);
-       return 0;
-}
-
-int _work_description_property(cal_sch_full_t *sch, char *buf)
-{
-       int i;
-       int ret = 0;
-
-       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;
-}
-
-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 {
-
-               }
-               mode = 0;
-               break;
-       default:
-               mode = me;
-               break;
-       }
-       return mode;
-}
-
-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;
-
-       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;
-}
-
-int cals_func_geo(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_last_mod(int ver, cal_sch_full_t *sch, void *data)
-{
-       char *p = (char *)data;
-
-       p++;
-       sch->last_mod = _datetime_to_utime(p);
-       return 0;
-}
-
-int cals_func_location(int ver, cal_sch_full_t *sch, void *data)
-{
-       char *p = (char *)data;
-       int encoding = 0;
-
-       while (*p != '\n' && *p != '\r' && *p != '\0') {
-               if ( *p == ':') {
-                       p++;
-                       if (encoding == ENCODE_BASE64) {
-                               gsize len;
-                               sch->location = 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->location = strdup(p);
-                               } else {
-                                       CALS_DBG("only ver1.0 supports quoted printable\n");
-                                       sch->summary = strdup(p);
-                               }
-
-                       } else {
-                               sch->location = strdup(p);
-
-                       }
-
-               } else if (*p == ';') {
-                       p++;
-                       cals_get_optional_parameter(p, &encoding);
-
-               } else {
-                       p++;
-               }
-       }
-       return 0;
-}
-
-int cals_func_organizer(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_priority(int ver, cal_sch_full_t *sch, void *data)
-{
-       char *p = (char *)data;
-
-       p++;
-       sch->priority = 0;      /* default */
-       if (p[0] >= '0' && p[0] <= '9') {
-               sch->priority = atoi(p);
-       } else {
-               CALS_DBG("warning check range\n");
-       }
-       return 0;
-}
-
-int cals_func_seq(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_status(int ver, cal_sch_full_t *sch, void *data)
-{
-       char *p = (char *)data;
-
-       p++;
-       if (sch->cal_type == CALS_SCH_TYPE_TODO) {
-               if (!strncmp(p, "NEEDS-ACTION", strlen("NEEDS-ACTION"))) {
-               } else if (!strncmp(p, "COMPLETED", strlen("COMPLETED"))) {
-                       sch->task_status = CALS_TODO_STATUS_NEEDS_ACTION;
-               } else if (!strncmp(p, "IN-PROCESS", strlen("IN-PROCESS"))) {
-                       sch->task_status = CALS_TODO_STATUS_IN_PROCESS;
-               } else if (!strncmp(p, "CANCELLED", strlen("CANCELLED"))) {
-                       sch->task_status = CALS_TODO_STATUS_CANCELLED;
-               } else {
-                       sch->task_status = CALS_TODO_STATUS_NONE;
-               }
-       } else if (sch->cal_type == CALS_SCH_TYPE_EVENT ) {
-               if (!strncmp(p, "TENTATIVE", strlen("TENTATIVE"))) {
-                       sch->task_status = CALS_EVENT_STATUS_TENTATIVE;
-               } else if (!strncmp(p, "CONFIRMED", strlen("CONFIRMED"))) {
-                       sch->task_status = CALS_EVENT_STATUS_CONFIRMED;
-               } else if (!strncmp(p, "CANCELLED", strlen("CANCELLED"))) {
-                       sch->task_status = CALS_EVENT_STATUS_CANCELLED;
-               } else {
-                       sch->task_status = CALS_EVENT_STATUS_NONE;
-               }
-       }
-
-       return 0;
-}
-
-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;
-
-       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) {
-                       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;
-}
-
-int cals_func_transp(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_url(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_recurid(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_rrule(int ver, cal_sch_full_t *sch, void *data)
-{
-       int i = 0, k = 0;
-       char *p = (char *)data;
-
-       p++;
-       while (*p != '\n' && *p != '\r' && *p != '\0') {
-               if (*p == ':' || *p == ';' || k == 0) {
-                       p += k;
-                       k = 1;
-
-                       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;
-                                               char buf[64] = {0, };
-                                               p += strlen(_rrule_list[i].prop);
-                                               while (p[j] != ';' && p[j] != '\n' && p[j] != '\0') {
-                                                       buf[j] = p[j];
-                                                       j++;
-                                               }
-                                               if (p[j] != '\0') {
-                                                       buf[j] = '\0';
-                                               }
-                                               p += j;
-                                               _rrule_list[i].func(sch, buf);
-                                               break;
-                                       }
-                               }
-                               break;
-
-                       case 2:
-                               DBG("version 1");
-                               /* Suppose vcalendar 1.0, if p == data */
-                               if ((p - 1) == (char *)data) {
-                                       cals_ver1_func_rrule(sch, p);
-                               }
-                               break;
-                       }
-               } else {
-                       p++;
-               }
-       }
-
-       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;
-       int k = 0, j;
-       int y, mon, d, h, min, s;
-       char buf[64] = {0, };
-       char tmp[64] = {0, };
-
-       p++;
-
-       if (!strncmp(p, "TZID=", strlen("TZID="))) {
-               k = 0;
-               j = 0;
-               while (p[j] != ':' && p[j] != ';' && p[j] != '\n' && p[j] != '\0') {
-                       buf[k] = p[j];
-                       k++;
-                       j++;
-               }
-               if (p[j] != '\0') {
-                       buf[k] = '\0';
-               }
-               p += j;
-               p++;
-               sch->dtend_tzid = strdup(buf);
-       } else {
-               sch->dtend_tzid = strdup(CALS_TZID_0);
-       }
-
-       if (!strncmp(p, "VALUE=", strlen("VALUE="))) {
-               k = 0;
-               j = strlen("VALUE=");
-               while (p[j] != ':' && p[j] != ';' && p[j] != '\n' && p[j] != '\0') {
-                       buf[k] = p[j];
-                       k++;
-                       j++;
-               }
-               if (p[j] != '\0') {
-                       buf[k] = '\0';
-               }
-               p += j;
-               p++;
-       }
-
-       if (!strncmp(buf, "DATE", strlen("DATE"))){
-               snprintf(tmp, 5, "%s", p);
-               sch->dtend_year = atoi(tmp);
-               snprintf(tmp, 3, "%s", p + 4);
-               sch->dtend_month = atoi(tmp);
-               snprintf(tmp, 3, "%s", p + 6);
-               sch->dtend_mday = atoi(tmp);
-
-       } else {
-               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);
-               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);
-               sch->dtend_utime = cals_time_date_to_utime(sch->dtend_tzid,
-                               y, mon, d, h, min, s);
-       }
-       return 0;
-}
-
-int cals_func_duration(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-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;
-       char *p = (char *)data;
-       int encoding = 0;
-
-       while (*p != '\n' && *p != '\r' && *p != '\0') {
-               if ( *p == ':') {
-                       p++;
-                       if (encoding == ENCODE_BASE64) {
-                               gsize len;
-                               sch->categories = 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->categories = strdup(p);
-                               } else {
-                                       CALS_DBG("only ver1.0 supports quoted printable\n");
-                                       sch->categories = strdup(p);
-                               }
-
-                       } else {
-                               sch->categories = strdup(p);
-                       }
-                       break;
-
-               } else if (*p == ';') {
-                       p++;
-                       cals_get_optional_parameter(p, &encoding);
-
-               } else {
-                       p++;
-               }
-       }
-       DBG("ver(%d)categories(%s)\n", ver, sch->categories);
-
-       return 0;
-}
-
-
-int cals_func_comment(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_contact(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_exdate(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-/*
-int cals_func_status(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-*/
-int cals_func_related(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_resources(int ver, cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-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,
-       WEEKNAME2_TH,
-       WEEKNAME2_WE,
-       WEEKNAME2_TU,
-       WEEKNAME2_MO,
-       WEEKNAME2_SU,
-       WEEKNAME2_MAX,
-};
-const char weekname2[WEEKNAME2_MAX][3] = {"SA", "FR", "TH", "WE", "TU", "MO", "SU"};
-
-/* 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;
-       int byint = -1; /* for by day:1 or by position:0 */
-       int y, mon, d, h, min, s;
-       char buf[64] = {0, };
-       char tmp[8] = {0, };
-
-       while(loop) {
-               /* parse sentence */
-               i = 0;
-               while(p[i] != '\n' && p[i] != '\0' && p[i] != ' ') {
-                       buf[i] = p[i];
-                       i++;
-               }
-               buf[i] = '\n';
-
-               /* exit when sentence ends */
-               if (p[i] == '\n' || p[i] == '\0') {
-                       loop = 0;
-               }
-
-
-               if (column == 0) {
-                       column++;
-
-                       /* freq */
-                       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;
-
-                       }
-
-                       /* interval */
-                       if (buf[1] == 'P') {
-                               byint = 0;
-                               sch->interval = atoi(&buf[2]);
-
-                       } else if (buf[1] == 'D') {
-                               byint = 1;
-                               sch->interval = atoi(&buf[2]);
-
-                       } else {
-                               sch->interval = atoi(&buf[1]);
-
-                       }
-                       DBG("interval(%d)\n", sch->interval);
-
-               } else {
-                       if (buf[0] == '#') {
-                               /* occurrences */
-                               sch->count = atoi(&buf[1]);
-                               DBG("occur(%d)\n", sch->count);
-
-                       } else if (strlen(buf) < 3) {
-                               /* get by-day: TODO:not supported byday*/
-                               if (byint == 0) {
-
-                               } else if (byint == 1) {
-
-                               } else {
-
-                               }
-
-                       } else if (strlen(buf) >= strlen("YYYYMMDDTHHMMSS")) {
-                               sch->until_type = CALS_TIME_UTIME;
-                               snprintf(tmp, 5, "%s", buf);
-                               y = atoi(tmp);
-                               snprintf(tmp, 3, "%s", buf + 4);
-                               mon = atoi(tmp);
-                               snprintf(tmp, 3, "%s", buf + 6);
-                               d = atoi(tmp);
-                               snprintf(tmp, 3, "%s", buf + 9);
-                               h = atoi(tmp);
-                               snprintf(tmp, 3, "%s", buf + 11);
-                               min = atoi(tmp);
-                               snprintf(tmp, 3, "%s", buf + 13);
-                               s = atoi(tmp);
-                               sch->until_utime = cals_time_date_to_utime(sch->dtstart_tzid,
-                               y, mon, d, h, min, s);
-                               DBG("until(%s)\n", buf);
-
-                       } else {
-                               /* get repeat week day */
-                               char buf_w[64] = {0};
-                               for (j = 0; j < WEEKNAME2_MAX; j++) {
-                                       if(!strncmp(buf, weekname2[j], strlen(weekname2[j]))) {
-                                               if (strlen(buf_w) != 0) {
-                                                       strcat(buf_w, ", ");
-                                               }
-                                               strcat(buf_w, weekname2[j]);
-                                       }
-                               }
-                               sch->byday = strdup(buf_w);
-                       }
-               }
-
-               p += i;
-               p++;
-       }
-       return 0;
-}
-
-//alarm////////////////////////////////////////////////////////////
-int cals_func_action(cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-char *cals_convert_sec_from_duration(char *p, int *dur_t, char *dur)
-{
-       char du = '0';
-       char buf[8] = {0, };
-       int i = 0, c, d = 1;
-       int t = 0;
-
-       CALS_DBG("%s", p);
-       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':
-                       du = 'W';
-                       c = atoi(buf);
-                       t += c * 7 * 24 * 60 * 60;
-                       memset(buf, 0x0, sizeof(buf));
-                       i = 0;
-                       break;
-               case 'D':
-                       du = 'D';
-                       c = atoi(buf);
-                       t += c * 24 * 60 * 60;
-                       memset(buf, 0x0, sizeof(buf));
-                       i = 0;
-                       break;
-               case 'H':
-                       du = 'H';
-                       c = atoi(buf);
-                       t += c * 60 * 60;
-                       memset(buf, 0x0, sizeof(buf));
-                       i = 0;
-                       break;
-               case 'M':
-                       du = 'M';
-                       c = atoi(buf);
-                       t += c * 60;
-                       memset(buf, 0x0, sizeof(buf));
-                       i = 0;
-                       break;
-               case 'S':
-                       du = 'S';
-                       c = atoi(buf);
-                       t += c;
-                       memset(buf, 0x0, sizeof(buf));
-                       i = 0;
-                       break;
-               default:
-                       buf[i] = *p;
-                       i++;
-                       break;
-
-               }
-               p++;
-       }
-       t *= d;
-       *dur_t = t;
-
-       if (dur) {
-               *dur = du;
-       }
-
-       return p;
-}
-
-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;
-       cal_value *val;
-       cal_alarm_info_t *alarm;
-       GList *l;
-
-       p++;
-       l = g_list_last(sch->alarm_list);
-       if (l == NULL) {
-               return -1;
-       }
-       val = (cal_value *)l->data;
-       alarm = (cal_alarm_info_t *)val->user_data;
-       dtstart_utime = sch->dtstart_utime;
-
-       while (*p != '\n' && *p != '\r' && *p != '\0') {
-
-               for (i = 0; i < TRIG_MAX; i++) {
-                       if (!strncmp(p, _trig_list[i].prop, strlen(_trig_list[i].prop))) {
-                               out = 1;
-                               int j = 0;
-                               char buf[64] = {0, };
-                               p += strlen(_trig_list[i].prop);
-                               while (p[j] != ';' && p[j] != '\n' && p[j] != '\0') {
-                                       buf[j] = p[j];
-                                       j++;
-                               }
-                               if (p[j] != '\0') {
-                                       buf[j] = '\0';
-                               }
-
-                               p += j;
-                               _trig_list[i].func(sch, buf);
-                               break;
-                       }
-               }
-               if (out == 1) {
-                       break;
-               }
-               cals_func_trig_related(sch, p);
-               break;
-       }
-       return 0;
-}
-
-int cals_func_repeat(cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_duration_alarm(cal_sch_full_t *sch, void *data)
-{
-       char *p = (char *)data;
-       char dur;
-       int dur_t;
-       cal_value *val;
-       cal_alarm_info_t *alarm = NULL;
-       GList *l;
-
-       p++;
-       l = g_list_last(sch->alarm_list);
-       if (l) {
-               val = (cal_value *)l->data;
-               alarm = (cal_alarm_info_t *)val->user_data;
-
-               cals_convert_sec_from_duration(p, &dur_t, &dur);
-               switch (dur) {
-                       case 'W':
-                               alarm->remind_tick = dur_t/(7 *24 *60 *60);
-                               alarm->remind_tick_unit = CAL_SCH_TIME_UNIT_WEEK;
-                               break;
-                       case 'D':
-                               alarm->remind_tick = dur_t/(24 *60 *60);
-                               alarm->remind_tick_unit = CAL_SCH_TIME_UNIT_DAY;
-                               break;
-                       case 'H':
-                               alarm->remind_tick = dur_t/(60 *60);
-                               alarm->remind_tick_unit = CAL_SCH_TIME_UNIT_HOUR;
-                               break;
-                       case 'M':
-                               alarm->remind_tick = dur_t/(60);
-                               alarm->remind_tick_unit = CAL_SCH_TIME_UNIT_MIN;
-                               break;
-                       default:
-                               alarm->remind_tick = 1;
-                               alarm->remind_tick_unit = 0;
-                               break;
-               }
-       }
-       DBG("tick:%d\n", alarm->remind_tick);
-       DBG("unit:%c\n", dur);
-       return 0;
-}
-
-int cals_func_attach_alarm(cal_sch_full_t *sch, void *data)
-{
-       return 0;
-}
-
-int cals_func_summary_alarm(cal_sch_full_t *sch, void *data)
-{
-       char *p = (char *)data;
-       cal_value *val;
-       cal_alarm_info_t *alarm;
-       GList *l;
-
-       p++;
-       l = g_list_last(sch->alarm_list);
-       if (l) {
-               val = (cal_value *)l->data;
-               alarm = (cal_alarm_info_t *)val->user_data;
-
-               alarm->alarm_description = strdup(p);
-       }
-       return 0;
-}
-
-
-//rrule////////////////////////////////////////////////////////////
-int cals_func_freq(cal_sch_full_t *sch, void *data)
-{
-       char *p = (char *)data;
-
-       DBG("%s\n", (char *)data);
-       if (!strncmp(p, "YEARLY", strlen("YEARLY"))) {
-               sch->freq = CALS_FREQ_YEARLY;
-
-       } else if (!strncmp(p, "MONTHLY", strlen("MONTHLY"))) {
-               sch->freq = CALS_FREQ_MONTHLY;
-
-       } else if (!strncmp(p, "WEEKLY", strlen("WEEKLY"))) {
-               sch->freq = CALS_FREQ_WEEKLY;
-
-       } else if (!strncmp(p, "DAILY", strlen("DAILY"))) {
-               sch->freq = CALS_FREQ_DAILY;
-
-       } else if (!strncmp(p, "HOURLY", strlen("HOURLY"))) {
-               sch->freq = CALS_FREQ_ONCE;
-
-       } else if (!strncmp(p, "MINUTELY", strlen("MINUTELY"))) {
-               sch->freq = CALS_FREQ_ONCE;
-
-       } else if (!strncmp(p, "SECONDLY", strlen("SECONDLY"))) {
-               sch->freq = CALS_FREQ_ONCE;
-
-       } else {
-               sch->freq = CALS_FREQ_ONCE;
-
-       }
-       return 0;
-}
-
-int cals_func_until(cal_sch_full_t *sch, void *data)
-{
-       int y, mon, d, h, min, s;
-       char *p = (char *)data;
-       char buf[8] = {0};
-
-       /* until value type has the same value as the dtstart */
-       sch->range_type = CALS_RANGE_UNTIL;
-       if (sch->dtstart_utime) {
-               sch->until_type = CALS_TIME_UTIME;
-               snprintf(buf, 5, "%s", p);
-               y = atoi(buf);
-               snprintf(buf, 3, "%s", p + 4);
-               mon = atoi(buf);
-               snprintf(buf, 3, "%s", p + 6);
-               d = atoi(buf);
-               snprintf(buf, 3, "%s", p + 9);
-               h = atoi(buf);
-               snprintf(buf, 3, "%s", p + 11);
-               min = atoi(buf);
-               snprintf(buf, 3, "%s", p + 13);
-               s = atoi(buf);
-               sch->until_utime = cals_time_date_to_utime(sch->dtstart_tzid,
-                               y, mon, d, h, min, s);
-
-       } else {
-               sch->until_type = CALS_TIME_LOCALTIME;
-               snprintf(buf, strlen("YYYY") + 1, "%s", p);
-               sch->until_year = atoi(buf);
-               snprintf(buf, strlen("MM") + 1, "%s", p + 4);
-               sch->until_month = atoi(buf);
-               snprintf(buf, strlen("DD") + 1, "%s", p + 6);
-               sch->until_mday = atoi(buf);
-
-       }
-       return 0;
-}
-
-int cals_func_count(cal_sch_full_t *sch, void *data)
-{
-       int c;
-       char *p = (char *)data;
-
-       DBG("%s\n", (char *)data);
-       sch->range_type = CALS_RANGE_COUNT;
-       c = atoi(p);
-       sch->count = c < 0 ? 0 : c;
-       return 0;
-}
-
-int cals_func_interval(cal_sch_full_t *sch, void *data)
-{
-       int c;
-       char *p = (char *)data;
-
-       DBG("%s\n", (char *)data);
-       c = atoi(p);
-       sch->interval = c < 0 ? 0 : c;
-       return 0;
-}
-
-int cals_func_bysecond(cal_sch_full_t *sch, void *data)
-{
-       CALS_DBG("%s\n", (char *)data);
-       char *p = (char *)data;
-       sch->bysecond = strdup(p);
-       return 0;
-}
-
-int cals_func_byminute(cal_sch_full_t *sch, void *data)
-{
-       CALS_DBG("%s\n", (char *)data);
-       char *p = (char *)data;
-       sch->byminute = strdup(p);
-       return 0;
-}
-
-int cals_func_byhour(cal_sch_full_t *sch, void *data)
-{
-       CALS_DBG("%s\n", (char *)data);
-       char *p = (char *)data;
-       sch->byhour = strdup(p);
-       return 0;
-}
-
-int cals_func_byday(cal_sch_full_t *sch, void *data)
-{
-       CALS_DBG("%s\n", (char *)data);
-       char *p = (char *)data;
-       sch->byday = strdup(p);
-       return 0;
-}
-
-int cals_func_bymonthday(cal_sch_full_t *sch, void *data)
-{
-       CALS_DBG("%s\n", (char *)data);
-       char *p = (char *)data;
-       sch->bymonthday = strdup(p);
-       return 0;
-}
-
-int cals_func_byyearday(cal_sch_full_t *sch, void *data)
-{
-       CALS_DBG("%s\n", (char *)data);
-       char *p = (char *)data;
-       sch->byyearday = strdup(p);
-       return 0;
-}
-
-int cals_func_byweekno(cal_sch_full_t *sch, void *data)
-{
-       CALS_DBG("%s\n", (char *)data);
-       char *p = (char *)data;
-       sch->byweekno = strdup(p);
-       return 0;
-}
-
-int cals_func_bymonth(cal_sch_full_t *sch, void *data)
-{
-       CALS_DBG("%s\n", (char *)data);
-       char *p = (char *)data;
-       sch->bymonth = strdup(p);
-       return 0;
-}
-
-int cals_func_bysetpos(cal_sch_full_t *sch, void *data)
-{
-       CALS_DBG("%s\n", (char *)data);
-       char *p = (char *)data;
-       sch->bysetpos = strdup(p);
-       return 0;
-}
-
-int cals_func_wkst(cal_sch_full_t *sch, void *data)
-{
-       CALS_DBG("%s\n", (char *)data);
-
-       char *p = (char *)data;
-
-       if (!strncmp(p, "SU", strlen("SU"))) {
-               sch->wkst = CALS_SUNDAY;
-
-       } else if (!strncmp(p, "MO", strlen("MO"))) {
-               sch->wkst = CALS_MONDAY;
-
-       } else if (!strncmp(p, "TU", strlen("TU"))) {
-               sch->wkst = CALS_TUESDAY;
-
-       } else if (!strncmp(p, "WE", strlen("WE"))) {
-               sch->wkst = CALS_WEDNESDAY;
-
-       } else if (!strncmp(p, "TH", strlen("TH"))) {
-               sch->wkst = CALS_THURSDAY;
-
-       } else if (!strncmp(p, "FR", strlen("FR"))) {
-               sch->wkst = CALS_FRIDAY;
-
-       } else if (!strncmp(p, "SA", strlen("SA"))) {
-               sch->wkst = CALS_SATURDAY;
-
-       }
-       return 0;
-}
-
-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;
-}
-
-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;
-}
-
-int cals_func_charset(int *val, void *data)
-{
-       CALS_DBG("%s\n", (char *)data);
-       return 0;
-}
-
-int cals_func_encoding(int *val, void *data)
-{
-       char *p = (char *)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;
-
-       }
-       return 0;
-}
-
-struct buf {
-       int size;
-       char *data;
-       char lbuf[76];
-};
-
-#define _strlen(s) (((s) && *(s)) ? strlen(s) : 0)
-
-static inline int _alloc(struct buf *b, int n)
-{
-       b->data = realloc(b->data, b->size + n);
-
-       retvm_if(!b->data, CAL_ERR_OUT_OF_MEMORY, "Out of memory error");
-       b->size += n;
-
-       return CAL_SUCCESS;
-}
-
-
-static struct buf *cal_svc_buf_new()
-{
-       struct buf *b;
-
-       b = calloc(1, sizeof(struct buf));
-       if (!b) {
-               return NULL;
-       }
-
-       b->data = malloc(sizeof(char));
-       if (!b->data) {
-               free(b);
-               return NULL;
-       }
-
-       *b->data = '\0';
-       b->size = 1;
-
-       return b;
-}
-
-
-static void cal_svc_buf_free(struct buf **b)
-{
-       if (!b || !*b)
-               return;
-
-       if ((*b)->data)
-               free((*b)->data);
-
-       free(*b);
-       b = NULL;
-}
-
-static inline int _flush(struct buf *b)
-{
-       int r;
-       r = _alloc(b, _strlen(b->lbuf) + 2);
-       retv_if(r < CAL_SUCCESS, r);
-
-       strncat(b->data, b->lbuf, b->size - _strlen(b->data) - 1);
-       strncat(b->data, "\r\n", b->size - _strlen(b->data) - 1);
-       *b->lbuf = '\0';
-       return CAL_SUCCESS;
-}
-
-static inline int _fold(struct buf *b)
-{
-       int r;
-       r = _alloc(b, _strlen(b->lbuf) + 3);
-       retv_if(r < CAL_SUCCESS, r);
-
-       strncat(b->data, b->lbuf, b->size - _strlen(b->data) - 1);
-       strncat(b->data, "\r\n ", b->size - _strlen(b->data) - 1);
-       *b->lbuf = '\0';
-       return CAL_SUCCESS;
-}
-
-static inline int _set_str(struct buf *b, const char *s)
-{
-       int remain_lbuf;
-       int remain_str;
-       int k;
-       int r;
-
-       remain_lbuf = sizeof(b->lbuf) - _strlen(b->lbuf);
-       remain_str = _strlen(s);
-
-       k = 0;
-       while ( remain_lbuf - 1 < remain_str) {
-               strncat(b->lbuf, s + k, remain_lbuf - 1);
-               k += remain_lbuf - 1;
-               remain_str -= remain_lbuf - 1;
-               r = _fold(b);
-               retv_if(r < CAL_SUCCESS, r);
-               remain_lbuf = sizeof(b->lbuf);
-       }
-
-       strncat(b->lbuf, s + k, remain_lbuf - 1);
-       return CAL_SUCCESS;
-}
-
-static inline int cal_svc_buf_flush(struct buf *b)
-{
-       return _flush(b);
-}
-
-static int cal_svc_buf_print(struct buf *b, const char *s1, const char *s2)
-{
-       int r;
-
-       if (s1) {
-               r = _set_str(b, s1);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-
-       if (s2) {
-               r = _set_str(b, s2);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-
-       return CAL_SUCCESS;
-}
-
-
-static int cal_svc_buf_printline(struct buf *b, const char *s1, const char *s2)
-{
-       int r;
-
-       if (s1) {
-               r = _set_str(b, s1);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-
-       if (s2) {
-               r = _set_str(b, s2);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-
-       return _flush(b);
-}
-
-
-static char *cal_svc_buf_get_data(struct buf *b)
-{
-       if (!b || !b->data)
-               return NULL;
-       return strdup(b->data);
-}
-
-static const char *vl_datetime(int y, int m, int d)
-{
-       static char buf[9];
-       snprintf(buf, sizeof(buf), "%04d%02d%02d", y, m, d);
-       return buf;
-}
-
-static const char *vl_dur(cal_sch_remind_tick_unit_t unit, int dur)
-{
-       static char buf[8];
-       int i = 0;
-       char d[5];
-
-       if (dur < 0) {
-               *buf = '-';
-               i++;
-               dur = -dur;
-       }
-
-       snprintf(d, sizeof(d), "%d", dur);
-
-       *(buf + i) = 'P';
-       i++;
-
-       switch (unit) {
-               case CAL_SCH_TIME_UNIT_WEEK:
-                       snprintf(buf + i, sizeof(buf) - i, "%sW", d);
-                       break;
-               case CAL_SCH_TIME_UNIT_DAY:
-                       snprintf(buf + i, sizeof(buf) - i, "%sD", d);
-                       break;
-               case CAL_SCH_TIME_UNIT_HOUR:
-                       snprintf(buf + i, sizeof(buf) - i, "T%sH", d);
-                       break;
-               case CAL_SCH_TIME_UNIT_MIN:
-                       snprintf(buf + i, sizeof(buf) - i, "T%sM", d);
-                       break;
-               default:
-                       buf[0] = '\0';
-       }
-
-       return buf;
-}
-
-static inline int pr_dtstart_utime(struct buf *b, char *tzid, long long int lli)
-{
-       return cal_svc_buf_printline(b, "DTSTART:", cals_time_get_str_datetime(tzid, lli));
-}
-
-static inline int pr_dtstart_datetime(struct buf *b, int y, int m, int s)
-{
-       return cal_svc_buf_printline(b, "DTSTART:", vl_datetime(y, m, s));
-}
-
-static inline int pr_dtend_utime(struct buf *b, char *tzid, long long int lli)
-{
-       return cal_svc_buf_printline(b, "DTEND:", cals_time_get_str_datetime(tzid, lli));
-}
-
-static inline int pr_dtend_datetime(struct buf *b, int y, int m, int s)
-{
-       return cal_svc_buf_printline(b, "DTEND:", vl_datetime(y, m, s));
-}
-
-static inline int pr_created(struct buf *b, char *tzid, long long int t)
-{
-       return cal_svc_buf_printline(b, "CREATED:", cals_time_get_str_datetime(tzid, t));
-}
-
-
-static inline int pr_lastmod(struct buf *b, char *tzid, long long int lli)
-{
-       return cal_svc_buf_printline(b, "LAST-MODIFIED:", cals_time_get_str_datetime(tzid, lli));
-}
-
-/**
- * Descriptive Component Properties
- */
-
-static inline int pr_summary(struct buf *b, char *s)
-{
-       return cal_svc_buf_printline(b, "SUMMARY:", s);
-}
-
-static inline int pr_description(struct buf *b, char *s)
-{
-       return cal_svc_buf_printline(b, "DESCRIPTION:", s);
-}
-
-static inline int pr_location(struct buf *b, char *s)
-{
-       return cal_svc_buf_printline(b, "LOCATION:", s);
-}
-
-static inline int pr_priority(struct buf *b, int v)
-{
-       char tmp[2];
-       snprintf(tmp, sizeof(tmp), "%d", v);
-       return cal_svc_buf_printline(b, "PRIORITY:", tmp);
-}
-
-static inline int pr_class(struct buf *b, int v)
-{
-       const char *c;
-       // TODO : Need to define enumeration of class property
-       switch(v) {
-               case 0:
-                       c = "PUBLIC"; break;
-               case 1:
-                       c = "PRIVATE"; break;
-               case 2:
-                       c = "CONFIDENTIAL"; break;
-               default:
-                       c = "PUBLIC"; break;
-       }
-       return cal_svc_buf_printline(b, "CLASS:", c);
-}
-
-static inline int pr_transp(struct buf *b, int v)
-{
-       // TODO : Need to define enumeration of transp property
-       return cal_svc_buf_printline(b, "TRANSP:", v? "OPAQUE":"TRANSPARENT");
-}
-
-int pr_dtstamp(char *tzid, struct buf *b)
-{
-       return cal_svc_buf_printline(b, "DTSTAMP:", cals_time_get_str_datetime(tzid, cals_get_lli_now()));
-}
-
-static const char *_att_role[] = {
-       [EVENT_ATTENDEE_REQ_PARTICIPANT_ROLE] = "REQ-PARTICIPANT",
-       [EVENT_ATTENDEE_OPT_PARTICIPANT_ROLE] = "OPT-PARTICIPANT",
-       [EVENT_ATTENDEE_NON_PARTICIPANT_ROLE] = "NON-PARTICIPANT",
-       [EVENT_ATTENDEE_CHAIR_ROLE] = "CHAIR",
-};
-
-static const char *_att_st[] = {
-       [EVENT_ATTENDEE_NEEDS_ACTION_AT_STATUS] = "NEEDS-ACTION",
-       [EVENT_ATTENDEE_ACCEPTED_AT_STATUS] = "ACCEPTED",
-       [EVENT_ATTENDEE_DECLINED_AT_STATUS] = "DECLINED",
-       [EVENT_ATTENDEE_TENTATIVE_AT_STATUS] = "TENTATIVE",
-       [EVENT_ATTENDEE_DELEGATED_AT_STATUS] = "DELEGATED",
-       [EVENT_ATTENDEE_COMPLETED_AT_STATUS] = "COMPLETED",
-       [EVENT_ATTENDEE_IN_PROCESS_AT_STATUS] = "IN-PROCESS",
-};
-
-int pr_attendee(struct buf *b, cal_participant_info_t *att)
-{
-       int r;
-       if (!att->attendee_email)
-               return CAL_ERR_NO_DATA;
-
-       r = cal_svc_buf_print(b, "ATTENDEE", NULL);
-       retv_if(r < CAL_SUCCESS, r);
-
-       if (att->attendee_group && *att->attendee_group) {
-               r = cal_svc_buf_print(b, ";CUTYPE=", att->attendee_group);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-
-       // TODO : NO 'member' member in cal_participant_info_t
-
-       r = cal_svc_buf_print(b, ";ROLE=", _att_role[att->attendee_role]);
-       retv_if(r < CAL_SUCCESS, r);
-
-       r = cal_svc_buf_print(b, ";PARTSTAT=", _att_st[att->attendee_status]);
-       retv_if(r < CAL_SUCCESS, r);
-
-       r = cal_svc_buf_print(b, ";RSVP=", att->attendee_rsvp?"TRUE":"FALSE");
-       retv_if(r < CAL_SUCCESS, r);
-
-       if (att->attendee_delegator_uri && *att->attendee_delegator_uri) {
-               r = cal_svc_buf_print(b, ";DELEGATED-TO=", att->attendee_delegator_uri);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-
-       if (att->attendee_delegate_uri && *att->attendee_delegate_uri) {
-               r = cal_svc_buf_print(b, ";DELEGATED-FROM=", att->attendee_delegate_uri);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-
-       // TODO : No 'sentby' member in cal_participant_info_t
-
-       if (att->attendee_name && *att->attendee_name) {
-               r = cal_svc_buf_print(b, ";CN=", att->attendee_name);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-
-       return cal_svc_buf_printline(b, ":", att->attendee_email);
-}
-
-int pr_organizer(struct buf *b, char *cn, char *address)
-{
-       int r;
-
-       r = cal_svc_buf_print(b, "ORGANIZER", NULL);
-       retv_if(r < CAL_SUCCESS, r);
-       if (cn && *cn) {
-               r = cal_svc_buf_print(b, ";CN=", cn);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-
-       return cal_svc_buf_printline(b, ":", address);
-}
-
-int pr_trigger(struct buf *b, cal_sch_remind_tick_unit_t unit, int dur, long long int t)
-{
-       retvm_if(unit == CAL_SCH_TIME_UNIT_OFF, CAL_ERR_NO_DATA, "tick unit is invalid");
-
-       if (unit == CAL_SCH_TIME_UNIT_SPECIFIC)
-               return cal_svc_buf_printline(b, "TRIGGER;VALUE=DATE-TIME:",cals_time_get_str_datetime(NULL, t));
-       else
-               return cal_svc_buf_printline(b, "TRIGGER:", vl_dur(unit, dur));
-}
-
-int pr_action(struct buf *b)
-{
-       return cal_svc_buf_printline(b, "ACTION:", "AUDIO");
-}
-
-
-int pr_audio(struct buf *b, cal_alarm_info_t *alm)
-{
-       int r;
-
-       r = pr_action(b);
-       retv_if(r < CAL_SUCCESS, r);
-
-       r = pr_trigger(b, alm->remind_tick_unit, alm->remind_tick, alm->alarm_time);
-       retv_if(r < CAL_SUCCESS, r);
-
-       // TODO : Support duration
-       // TODO : Support repeat (snooze)
-       return CAL_SUCCESS;
-}
-
-
-int cp_alarm(struct buf *b, cal_alarm_info_t *alm)
-{
-       int r;
-       // TODO : No action type is defined
-       r = cal_svc_buf_printline(b, "BEGIN:VALARM", NULL);
-       retv_if(r < CAL_SUCCESS, r);
-
-       r = pr_audio(b, alm);
-       retv_if(r < CAL_SUCCESS, r);
-
-       // TODO : Display
-       // TODO : Email
-       // TODO : Proc
-
-       return cal_svc_buf_printline(b, "END:VALARM", NULL);
-}
-
-int cp_schedule(struct buf *b, cal_sch_full_t *s)
-{
-       int r;
-       GList *l;
-       cal_participant_info_t *att;
-       cal_alarm_info_t *alm;
-
-       r = cal_svc_buf_printline(b, "BEGIN:VEVENT", NULL);
-       retv_if(r < CAL_SUCCESS, r);
-
-       r = pr_class(b, s->sensitivity);
-       retv_if(r < CAL_SUCCESS, r);
-
-       r = pr_transp(b, s->busy_status);
-       retv_if(r < CAL_SUCCESS, r);
-
-       r = pr_created(b, s->dtstart_tzid, s->created_time);
-       retv_if(r < CAL_SUCCESS, r);
-
-       if (s->description) {
-               r = pr_description(b, s->description);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-
-       switch (s->dtstart_type) {
-       case CALS_TIME_UTIME:
-               r = pr_dtstart_utime(b, s->dtstart_tzid, s->dtstart_utime);
-               retv_if(r < CAL_SUCCESS, r);
-               break;
-
-       case CALS_TIME_LOCALTIME:
-               r = pr_dtstart_datetime(b, s->dtstart_year, s->dtstart_month, s->dtstart_mday);
-               retv_if(r < CAL_SUCCESS, r);
-               break;
-
-       }
-
-       // TODO : geo
-
-       r = pr_lastmod(b, s->dtstart_tzid, s->last_mod);
-       retv_if(r < CAL_SUCCESS, r);
-
-       if (s->location) {
-               r = pr_location(b, s->location);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-       if (s->organizer_email) {
-               r = pr_organizer(b, s->organizer_name, s->organizer_email);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-
-       r = pr_priority(b, s->priority);
-       retv_if(r < CAL_SUCCESS, r);
-
-       // TODO : seq
-
-       r = pr_dtstamp(s->dtstart_tzid, b);
-       retv_if(r < CAL_SUCCESS, r);
-
-       if (s->summary) {
-               r = pr_summary(b, s->summary);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-
-       switch (s->dtend_type) {
-       case CALS_TIME_UTIME:
-               r = pr_dtend_utime(b, s->dtstart_tzid, s->dtend_utime);
-               retv_if(r < CAL_SUCCESS, r);
-               break;
-
-       case CALS_TIME_LOCALTIME:
-               r = pr_dtend_datetime(b, s->dtend_year, s->dtend_month, s->dtend_mday);
-               retv_if(r < CAL_SUCCESS, r);
-               break;
-
-       }
-
-       if (s->attendee_list) {
-               for (l = s->attendee_list; l; l = g_list_next(l)) {
-                       if (!l->data || ((cal_value *)(l->data))->v_type != CAL_EVENT_PATICIPANT
-                                       || !((cal_value *)(l->data))->user_data) {
-                               ERR("The attendee entry has no attendee data");
-                               return CAL_ERR_NO_DATA;
-                       }
-                       att = ((cal_value *)(l->data))->user_data;
-                       r = pr_attendee(b, att);
-                       retv_if(r < CAL_SUCCESS, r);
-               }
-       }
-
-       if (s->alarm_list) {
-               for (l = s->alarm_list; l; l = g_list_next(l)) {
-                       if (!l->data || ((cal_value *)(l->data))->v_type != CAL_EVENT_ALARM
-                                       || !((cal_value *)(l->data))->user_data) {
-                               ERR("The alarm entry has no alarm data");
-                               return CAL_ERR_NO_DATA;
-                       }
-                       alm = ((cal_value *)(l->data))->user_data;
-                       r = cp_alarm(b, alm);
-                       retv_if(r < CAL_SUCCESS, r);
-               }
-       }
-
-       return cal_svc_buf_printline(b, "END:VEVENT", NULL);
-}
-
-
-int cp_vcalendar(struct buf *b, GList *sch_l)
-{
-       int r;
-       cal_sch_full_t *s;
-       GList *l;
-
-       r = cal_svc_buf_printline(b, "BEGIN:VCALENDAR", NULL);
-       retv_if(r < CAL_SUCCESS, r);
-
-       r = cal_svc_buf_printline(b, "CALSCALE:GREGORIAN", NULL);
-       retv_if(r < CAL_SUCCESS, r);
-
-       r = cal_svc_buf_printline(b, "PRODID:-//Samsung Electronics//Calendar//EN", NULL);
-       retv_if(r < CAL_SUCCESS, r);
-
-       r = cal_svc_buf_printline(b, "VERSION:2.0", NULL);
-       retv_if(r < CAL_SUCCESS, r);
-
-       for (l = sch_l; l; l = g_list_next(l)) {
-               if (!l->data || !((cal_struct *)(l->data))->user_data) {
-                       ERR("The schedule entry has no event data");
-                       return CAL_ERR_NO_DATA;
-               }
-               s = (cal_sch_full_t *)((cal_struct *)(l->data))->user_data;
-               r = cp_schedule(b, s);
-               retv_if(r < CAL_SUCCESS, r);
-       }
-
-       return cal_svc_buf_printline(b, "END:VCALENDAR", NULL);
-}
-
-
-API int calendar_svc_write_schedules(GList *schedules, char **stream)
-{
-       int r;
-       struct buf *b;
-       char *ical;
-
-       retvm_if(!schedules || !stream, CAL_ERR_ARG_NULL, "Invalid parameter");
-
-       b = cal_svc_buf_new();
-       retvm_if(!b, CAL_ERR_OUT_OF_MEMORY, "Failed to create a buffer");
-
-       r = cp_vcalendar(b, schedules);
-
-       if (r < 0) {
-               cal_svc_buf_free(&b);
-               return r;
-       }
-
-       ical = cal_svc_buf_get_data(b);
-       cal_svc_buf_free(&b);
-
-       if (!ical) {
-               ERR("Failed to get ical data");
-               return CAL_ERR_OUT_OF_MEMORY;
-       }
-
-       if (!*ical) {
-               ERR("No ical data");
-               return CAL_ERR_NO_DATA;
-       }
-
-       *stream = ical;
-
-       return CAL_SUCCESS;
-}
-
-#ifndef CALS_IPC_CLIENT
-API int calendar_svc_calendar_export(int calendar_id, const char *path)
-{
-       int fd, r;
-       char *stream = NULL;
-       cal_iter *it;
-       cal_struct *cs;
-       GList *schedules = NULL;
-       GList *l;
-
-       if (calendar_id < 0 || path == NULL) {
-               ERR("Invalid argument: calendar id(%d) path(%s)", calendar_id, path);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       /* get schedules from DB */
-       r = calendar_svc_get_all(0, calendar_id, CAL_STRUCT_SCHEDULE, &it);
-       if (r != CAL_SUCCESS) {
-               ERR("Failed to get calendar(id:%d errno:%d)", calendar_id, r);
-               return CAL_ERR_FAIL;
-       }
-       while (calendar_svc_iter_next(it) == CAL_SUCCESS) {
-               r = calendar_svc_iter_get_info(it, &cs);
-               if (r != CAL_SUCCESS) {
-                       ERR("Failed to get cal_struct");
-                       break;
-               }
-
-               if (cs == NULL) {
-                       ERR("cal_struct is NULL");
-                       break;
-               }
-               schedules = g_list_append(schedules, cs);
-       }
-       calendar_svc_iter_remove(&it);
-       /* end getting schedules and close DB */
-
-       if (schedules == NULL) {
-               ERR("No schedules");
-               return CAL_ERR_FAIL;
-       }
-
-       /* get stream from schedules */
-       r = calendar_svc_write_schedules(schedules, &stream);
-
-       /* free schedules in memory */
-       l = schedules;
-       while (l) {
-               cs = (cal_struct *)l->data;
-               if (cs == NULL) {
-                       ERR("Not cal struct");
-                       break;
-               }
-               calendar_svc_struct_free(&cs);
-               l = g_list_next(l);
-       }
-       g_list_free(schedules);
-
-       if (r < 0) {
-               ERR("Failed to write schedules(errno:%d)", r);
-               return CAL_ERR_FAIL;
-       }
-
-       if (stream == NULL) {
-               ERR("stream is NULL");
-               return CAL_ERR_FAIL;
-       }
-
-       fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0660);
-       if (fd < 0) {
-               ERR("Failed to open path(%s)\n", path);
-               free(stream);
-               return CAL_ERR_IO_ERR;
-       }
-
-       r = write(fd, stream, strlen(stream));
-       free(stream);
-       close(fd);
-
-       if (r < 0) {
-               ERR("Failed to write stream(errno:%d)\n", r);
-               return CAL_ERR_IO_ERR;
-       }
-
-       return CAL_SUCCESS;
-}
-#endif
diff --git a/src/cals-ical.h b/src/cals-ical.h
deleted file mode 100755 (executable)
index c925927..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __CALENDAR_SVC_ICAL_H__
-#define __CALENDAR_SVC_ICAL_H__
-/**
-* @ingroup app_engine
-* @addtogroup  app_cal_engine
-* @{
-*/
-
-#define TM_YEAR_BASE 1900
-#define VCALENDAR_TIME_STR_LEN 16
-#define VCALENDAR_DATA_LEN 3000
-
-#define SCH_LIST_LEN 10
-
-//#include "org-engine-typedef.h"
-
-/**
-* @fn bool cal_convert_vdata_file_to_cal_data(const char * file_path, cal_sch_full_t ** sch_array, int * sch_count, int* error_code );
-*  This function convert a record to vcal file.
-*
-* @return              This function returns true on success, or false on failure.
-* @param[in]           file_path       Points the file path.
-* @param[out]  sch_array               Points the field information for schedule table' s record.
-* @param[out]  sch_count                       Points the count of records.
-* @param[out]  error_code      Points the error code.
-* @exception   #CAL_ERR_FILE_OPEN_ERROR - Open file error.
-* @exception   #CAL_ERR_VOBJECT_FAILED - Decode vcal error.
-*/
-bool cal_convert_vdata_file_to_cal_data(const char * file_path, cal_sch_full_t ** sch_array, int * sch_count, int *error_code );
-
-/**
-* @}
-*/
-#endif /* __CALENDAR_SVC_ICAL_H__ */
diff --git a/src/cals-inotify.c b/src/cals-inotify.c
deleted file mode 100755 (executable)
index d02844d..0000000
+++ /dev/null
@@ -1,340 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/inotify.h>
-
-#include "cals-internal.h"
-#include "cals-typedef.h"
-
-typedef struct
-{
-       int wd;
-       void (*cb)(void *);
-       void *cb_data;
-}noti_info;
-
-static int inoti_fd = -1;
-static guint inoti_handler;
-static GSList *noti_list;
-
-static inline void _handle_callback(GSList *noti_list, int wd, uint32_t mask)
-{
-       noti_info *noti;
-       GSList *it = NULL;
-
-       for (it = noti_list;it;it=it->next)
-       {
-               noti = (noti_info *)it->data;
-               if (noti->wd == wd) {
-                       if ((mask & IN_CLOSE_WRITE) && noti->cb)
-                               noti->cb(noti->cb_data);
-               }
-       }
-}
-
-static gboolean _inotify_gio_cb(GIOChannel *src, GIOCondition cond, gpointer data)
-{
-       int fd, ret;
-       struct inotify_event ie;
-       char name[FILENAME_MAX];
-
-       fd = g_io_channel_unix_get_fd(src);
-
-       while (0 < (ret = read(fd, &ie, sizeof(ie)))) {
-               if (sizeof(ie) == ret) {
-                       if (noti_list)
-                               _handle_callback(noti_list, ie.wd, ie.mask);
-
-                       while (0 < ie.len) {
-                               ret = read(fd, name, (ie.len<sizeof(name))?ie.len:sizeof(name));
-                               if (-1 == ret) {
-                                       if (EINTR == errno)
-                                               continue;
-                                       else
-                                               break;
-                               }
-                               ie.len -= ret;
-                       }
-               }else {
-                       while (ret < sizeof(ie)) {
-                               int read_size;
-                               read_size = read(fd, name, sizeof(ie)-ret);
-                               if (-1 == read_size) {
-                                       if (EINTR == errno)
-                                               continue;
-                                       else
-                                               break;
-                               }
-                               ret += read_size;
-                       }
-               }
-       }
-
-       return TRUE;
-}
-
-static inline int _inotify_attach_handler(int fd)
-{
-       guint ret;
-       GIOChannel *channel;
-
-       retvm_if(fd < 0, CAL_ERR_ARG_INVALID, "fd is invalid");
-
-       channel = g_io_channel_unix_new(fd);
-       retvm_if(NULL == channel, CAL_ERR_INOTIFY_FAILED, "g_io_channel_unix_new() Failed");
-
-       g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL);
-
-       ret = g_io_add_watch(channel, G_IO_IN, _inotify_gio_cb, NULL);
-       g_io_channel_unref(channel);
-
-       return ret;
-}
-
-int cals_inotify_init(void)
-{
-       inoti_fd = inotify_init();
-       retvm_if(-1 == inoti_fd, CAL_ERR_INOTIFY_FAILED,
-                       "inotify_init() Failed(%d)", errno);
-
-       fcntl(inoti_fd, F_SETFD, FD_CLOEXEC);
-       fcntl(inoti_fd, F_SETFL, O_NONBLOCK);
-
-       inoti_handler = _inotify_attach_handler(inoti_fd);
-       if (inoti_handler <= 0) {
-               ERR("_inotify_attach_handler() Failed");
-               close(inoti_fd);
-               inoti_fd = -1;
-               inoti_handler = 0;
-               return CAL_ERR_INOTIFY_FAILED;
-       }
-
-       return CAL_SUCCESS;
-}
-
-static inline int _inotify_get_wd(int fd, const char *notipath)
-{
-       return inotify_add_watch(fd, notipath, IN_ACCESS);
-}
-
-static inline int _inotify_watch(int fd, const char *notipath)
-{
-       int ret;
-
-       ret = inotify_add_watch(fd, notipath, IN_CLOSE_WRITE);
-       retvm_if(-1 == ret, CAL_ERR_INOTIFY_FAILED,
-                       "inotify_add_watch() Failed(%d)", errno);
-
-       return CAL_SUCCESS;
-}
-
-int cals_inotify_subscribe(const char *path, void (*cb)(void *), void *data)
-{
-       int ret, wd;
-       noti_info *noti, *same_noti = NULL;
-       GSList *it;
-
-       retv_if(NULL==path, CAL_ERR_ARG_NULL);
-       retv_if(NULL==cb, CAL_ERR_ARG_NULL);
-       retvm_if(inoti_fd < 0, CAL_ERR_ENV_INVALID,
-                       "inoti_fd(%d) is invalid", inoti_fd);
-
-       wd = _inotify_get_wd(inoti_fd, path);
-       retvm_if(-1 == wd, CAL_ERR_INOTIFY_FAILED,
-                       "_inotify_get_wd() Failed(%d)", errno);
-
-       for (it=noti_list;it;it=it->next)
-       {
-               if (it->data)
-               {
-                       same_noti = it->data;
-                       if (same_noti->wd == wd && same_noti->cb == cb && same_noti->cb_data == data) {
-                               break;
-                       }
-                       else {
-                               same_noti = NULL;
-                       }
-               }
-       }
-
-       if (same_noti) {
-               _inotify_watch(inoti_fd, path);
-               ERR("The same callback(%s) is already exist", path);
-               return CAL_ERR_ALREADY_EXIST;
-       }
-
-       ret = _inotify_watch(inoti_fd, path);
-       retvm_if(CAL_SUCCESS != ret, ret, "_inotify_watch() Failed");
-
-       noti = calloc(1, sizeof(noti_info));
-       retvm_if(NULL == noti, CAL_ERR_OUT_OF_MEMORY, "calloc() Failed");
-
-       noti->wd = wd;
-       noti->cb_data = data;
-       noti->cb = cb;
-       noti_list = g_slist_append(noti_list, noti);
-
-       return CAL_SUCCESS;
-}
-
-static inline int _del_noti_with_data(GSList **noti_list, int wd,
-               void (*cb)(void *), void *user_data)
-{
-       int del_cnt, remain_cnt;
-       GSList *it, *result;
-
-       del_cnt = 0;
-       remain_cnt = 0;
-
-       it = result = *noti_list;
-       while (it)
-       {
-               noti_info *noti = it->data;
-               if (noti && wd == noti->wd)
-               {
-                       if (cb == noti->cb && user_data == noti->cb_data) {
-                               it = it->next;
-                               result = g_slist_remove(result , noti);
-                               free(noti);
-                               del_cnt++;
-                               continue;
-                       }
-                       else {
-                               remain_cnt++;
-                       }
-               }
-               it = it->next;
-       }
-       retvm_if(del_cnt == 0, CAL_ERR_NO_DATA, "nothing deleted");
-
-       *noti_list = result;
-
-       return remain_cnt;
-}
-
-static inline int _del_noti(GSList **noti_list, int wd, void (*cb)(void *))
-{
-       int del_cnt, remain_cnt;
-       GSList *it, *result;
-
-       del_cnt = 0;
-       remain_cnt = 0;
-
-       it = result = *noti_list;
-       while (it)
-       {
-               noti_info *noti = it->data;
-               if (noti && wd == noti->wd)
-               {
-                       if (NULL == cb || noti->cb == cb) {
-                               it = it->next;
-                               result = g_slist_remove(result, noti);
-                               free(noti);
-                               del_cnt++;
-                               continue;
-                       }
-                       else {
-                               remain_cnt++;
-                       }
-               }
-               it = it->next;
-       }
-       retvm_if(del_cnt == 0, CAL_ERR_NO_DATA, "nothing deleted");
-
-       *noti_list = result;
-
-       return remain_cnt;
-}
-
-int cals_inotify_unsubscribe(const char *path, void (*cb)(void *))
-{
-       int ret, wd;
-
-       retv_if(NULL == path, CAL_ERR_ARG_NULL);
-       retvm_if(inoti_fd < 0, CAL_ERR_ENV_INVALID,
-                       "inoti_fd(%d) is invalid", inoti_fd);
-
-       wd = _inotify_get_wd(inoti_fd, path);
-       retvm_if(-1 == wd, CAL_ERR_INOTIFY_FAILED,
-                       "_inotify_get_wd() Failed(%d)", errno);
-
-       ret = _del_noti(&noti_list, wd, cb);
-       warn_if(ret < CAL_SUCCESS, "_del_noti() Failed(%d)", ret);
-
-       if (0 == ret)
-               return inotify_rm_watch(inoti_fd, wd);
-
-       return _inotify_watch(inoti_fd, path);
-}
-
-int cals_inotify_unsubscribe_with_data(const char *path,
-               void (*cb)(void *), void *user_data)
-{
-       int ret, wd;
-
-       retv_if(NULL==path, CAL_ERR_ARG_NULL);
-       retv_if(NULL==cb, CAL_ERR_ARG_NULL);
-       retvm_if(inoti_fd < 0, CAL_ERR_ENV_INVALID,
-                       "inoti_fd(%d) is invalid", inoti_fd);
-
-       wd = _inotify_get_wd(inoti_fd, path);
-       retvm_if(-1 == wd, CAL_ERR_INOTIFY_FAILED,
-                       "_inotify_get_wd() Failed(%d)", errno);
-
-       ret = _del_noti_with_data(&noti_list, wd, cb, user_data);
-       warn_if(ret < CAL_SUCCESS, "_del_noti_with_data() Failed(%d)", ret);
-
-       if (0 == ret)
-               return inotify_rm_watch(inoti_fd, wd);
-
-       return _inotify_watch(inoti_fd, path);
-}
-
-static void _clear_nslot_list(gpointer data, gpointer user_data)
-{
-       free(data);
-}
-
-static inline gboolean _inotify_detach_handler(guint id)
-{
-       return g_source_remove(id);
-}
-
-void cals_inotify_close(void)
-{
-       if (inoti_handler) {
-               _inotify_detach_handler(inoti_handler);
-               inoti_handler = 0;
-       }
-
-       if (noti_list) {
-               g_slist_foreach(noti_list, _clear_nslot_list, NULL);
-               g_slist_free(noti_list);
-               noti_list = NULL;
-       }
-
-       if (0 <= inoti_fd) {
-               close(inoti_fd);
-               inoti_fd = -1;
-       }
-}
diff --git a/src/cals-instance.c b/src/cals-instance.c
deleted file mode 100644 (file)
index 300de70..0000000
+++ /dev/null
@@ -1,891 +0,0 @@
-#include <stdlib.h>
-#include <glib.h>
-#include <unicode/ucal.h>
-#include <unicode/ustring.h>
-#include <unicode/ustdio.h>
-#include <unicode/udat.h>
-#include <sys/types.h>
-#include "cals-typedef.h"
-#include "cals-internal.h"
-#include "cals-instance.h"
-#include "cals-sqlite.h"
-#include "cals-db-info.h"
-#include "cals-utils.h"
-
-#define ms2sec(ms) (long long int)(ms / 1000.0)
-#define sec2ms(s) (s * 1000.0)
-
-/* input order
-   UCAL_MONTH + UCAL_DAY_OF_MONTH
-   UCAL_MONTH + UCAL_WEEK_OF_MONTH + UCAL_DAY_OF_WEEK
-   UCAL_MONTH + UCAL_DAY_OF_WEEK_IN_MONTH + UCAL_DAY_OF_WEEK
-   UCAL_DAY_OF_YEAR
-   UCAL_DAY_OF_WEEK + UCAL_WEEK_OF_YEAR
-*/
-
-int _print_cal(UCalendar *cal)
-{
-       int y, m, d;
-       UErrorCode status = U_ZERO_ERROR;
-
-       y = ucal_get(cal, UCAL_YEAR, &status);
-       m = ucal_get(cal, UCAL_MONTH, &status) + 1;
-       d = ucal_get(cal, UCAL_DATE, &status);
-       DBG("PRINT CAL %04d/%02d/%02d", y, m, d);
-       return 0;
-}
-
-static int _get_max_count(cal_sch_full_t *);
-static int instance_insert_yearly(int event_id,
-               struct cals_time *st, int dr, cal_sch_full_t *sch);
-static int instance_insert_monthly(int event_id,
-               struct cals_time *st, int dr, cal_sch_full_t *sch);
-static int instance_insert_weekly(int event_id,
-               struct cals_time *st, int dr, cal_sch_full_t *sch);
-static int instance_insert_daily(int event_id,
-               struct cals_time *st, int dr, cal_sch_full_t *sch);
-static int instance_insert_once(int event_id,
-               struct cals_time *st, int dr, cal_sch_full_t *sch);
-
-struct inst_info {
-       int (*insert)(int, struct cals_time *, int duration, cal_sch_full_t *);
-       UCalendarDateFields f;
-       int max;
-};
-
-static struct inst_info inst_info[] = {
-       [CALS_FREQ_YEARLY] = {instance_insert_yearly, UCAL_YEAR, 100,},
-       [CALS_FREQ_MONTHLY] = {instance_insert_monthly, UCAL_MONTH, 120,},
-       [CALS_FREQ_WEEKLY] = {instance_insert_weekly, UCAL_WEEK_OF_YEAR, 520,},
-       [CALS_FREQ_DAILY] = {instance_insert_daily, UCAL_DATE, 3650,},
-       [CALS_FREQ_HOURLY] = {instance_insert_once, 0, 1,},
-       [CALS_FREQ_MINUTELY] = {instance_insert_once, 0, 1,},
-       [CALS_FREQ_SECONDLY] = {instance_insert_once, 0, 1,},
-       [CALS_FREQ_ONCE] = {instance_insert_once, 0, 1,},
-};
-
-struct day {
-       int uday;
-       const char *str;
-};
-
-enum cals_month {
-
-       CALS_JANUARY = 1,
-       CALS_FEBRUARY,
-       CALS_MARCH,
-       CALS_APRIL,
-       CALS_MAY,
-       CALS_JUNE,
-       CALS_JULY,
-       CALS_AUGUST,
-       CALS_SEPTEMBER,
-       CALS_OCTOBER,
-       CALS_NOVEMBER,
-       CALS_DECEMBER,
-       CALS_NOMONTH = 0x100,
-};
-
-static int months[] = {
-       [CALS_JANUARY] = UCAL_JANUARY,
-       [CALS_FEBRUARY] = UCAL_FEBRUARY,
-       [CALS_MARCH] = UCAL_MARCH,
-       [CALS_APRIL] = UCAL_APRIL,
-       [CALS_MAY] = UCAL_MAY,
-       [CALS_JUNE] = UCAL_JUNE,
-       [CALS_JULY] = UCAL_JULY,
-       [CALS_AUGUST] = UCAL_AUGUST,
-       [CALS_SEPTEMBER] = UCAL_SEPTEMBER,
-       [CALS_OCTOBER] = UCAL_OCTOBER,
-       [CALS_NOVEMBER] = UCAL_NOVEMBER,
-       [CALS_DECEMBER] = UCAL_DECEMBER,
-};
-
-static struct day wdays[] = {
-       [CALS_SUNDAY] = {UCAL_SUNDAY, "SU"},
-       [CALS_MONDAY] = {UCAL_MONDAY, "MO"},
-       [CALS_TUESDAY] = {UCAL_TUESDAY, "TU"},
-       [CALS_WEDNESDAY] = {UCAL_WEDNESDAY, "WE"},
-       [CALS_THURSDAY] = {UCAL_THURSDAY, "TH"},
-       [CALS_FRIDAY] = {UCAL_FRIDAY, "FR"},
-       [CALS_SATURDAY] = {UCAL_SATURDAY, "SA"},
-};
-
-static UCalendar *_ucal_get_cal(const char *tzid, int wkst)
-{
-       UCalendar *cal;
-       UErrorCode status = U_ZERO_ERROR;
-       UChar *_tzid;
-
-       _tzid = NULL;
-
-       if (tzid) {
-               _tzid = (UChar*)malloc(sizeof(UChar) * (strlen(tzid) +1));
-               if (_tzid)
-                       u_uastrcpy(_tzid, tzid);
-               else
-                       ERR("malloc failed");
-       }
-
-       cal = ucal_open(_tzid, u_strlen(_tzid), "en_US", UCAL_TRADITIONAL, &status);
-       if (_tzid)
-               free(_tzid);
-
-       if (U_FAILURE(status)) {
-               ERR("ucal_open failed (%s)", u_errorName(status));
-               return NULL;
-       }
-
-       if (wkst >= CALS_SUNDAY && wkst <= CALS_SATURDAY)
-               ucal_setAttribute(cal, UCAL_FIRST_DAY_OF_WEEK, wdays[wkst].uday);
-
-       return cal;
-}
-
-static void _ucal_set_time(UCalendar *cal, struct cals_time *t)
-{
-       UErrorCode status = U_ZERO_ERROR;
-
-       if (t->type == CALS_TIME_UTIME) {
-               ucal_setMillis(cal, sec2ms(t->utime), &status);
-               if (U_FAILURE(status)) {
-                       ERR("ucal_setMillis failed (%s)", u_errorName(status));
-                       return;
-               }
-       } else if (t->type == CALS_TIME_LOCALTIME) {
-               ucal_setDate(cal, t->year, months[t->month], t->mday, &status);
-               if (U_FAILURE(status)) {
-                       ERR("ucal_setDate failed (%s)", u_errorName(status));
-                       return;
-               }
-       } else
-               ERR("Invalid dtstart type. Current time is used in default");
-}
-
-static inline void _ucal_set_mday(UCalendar *cal, int mday)
-{
-       ucal_set(cal, UCAL_DATE, mday);
-}
-
-static inline void _ucal_set_month(UCalendar *cal, int month)
-{
-       if (month == CALS_NOMONTH)
-               return;
-       ucal_set(cal, UCAL_MONTH, months[month]);
-}
-
-
-static inline void _ucal_set_wday(UCalendar *cal, int wday)
-{
-       if (wday == CALS_NODAY) {
-               DBG("this is mday repeat, so pass this shift");
-               return;
-       }
-       ucal_set(cal, UCAL_DAY_OF_WEEK, wdays[wday].uday);
-}
-
-static inline void _ucal_set_week(UCalendar *cal, int week, cal_sch_full_t *sch)
-{
-       if (!week)
-               return;
-
-       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,
-               struct cals_time *st, struct cals_time *result)
-{
-       UErrorCode status = U_ZERO_ERROR;
-
-       if (st->type == CALS_TIME_UTIME) {
-               result->type = CALS_TIME_UTIME;
-               result->utime = (long long int)(ms2sec(ucal_getMillis(cal, &status)));
-               return;
-       }
-
-       result->type = CALS_TIME_LOCALTIME;
-       result->year = ucal_get(cal, UCAL_YEAR, &status);
-       result->month = ucal_get(cal, UCAL_MONTH, &status) + 1;
-       result->mday = ucal_get(cal, UCAL_DATE, &status);
-       DBG("get instance %04d/%02d/%02d", result->year, result->month, result->mday);
-
-       return;
-}
-
-static inline int _is_after(struct cals_time *t1, struct cals_time *t2)
-{
-       if (t1->type == CALS_TIME_UTIME) {
-               if (t1->utime > t2->utime)
-                       return 1;
-               else
-                       return 0;
-       }
-
-       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->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;
-                       }
-               }
-       }
-}
-
-static inline void _set_until(struct cals_time *until, cal_sch_full_t *sch)
-{
-       until->type = sch->until_type;
-
-       if (sch->range_type == CALS_RANGE_UNTIL) {
-               if (sch->until_type == CALS_TIME_UTIME) {
-                       DBG("until utime(%lld)", sch->until_utime);
-                       until->utime = sch->until_utime;
-               } else {
-                       DBG("until datetime(%04d/%02d/%02d",
-                                       sch->until_year, sch->until_month, sch->until_mday);
-                       until->year = sch->until_year;
-                       until->month = sch->until_month;
-                       until->mday = sch->until_mday;
-               }
-               return;
-       }
-
-       until->utime = 253402300799;
-       until->year = 9999;
-       until->month = 12;
-       until->mday = 31;
-}
-
-int _ucal_del_inundant(int event_id, struct cals_time *st, cal_sch_full_t *sch)
-{
-       int r;
-       int cnt;
-       char query[CALS_SQL_MIN_LEN];
-
-       if (sch->range_type != CALS_RANGE_COUNT) {
-               return 0;
-       }
-
-       cnt = _get_max_count(sch);
-
-       if (st->type == CALS_TIME_UTIME) {
-               snprintf(query, sizeof(query), "DELETE FROM %s "
-                               "WHERE event_id = %d "
-                               "AND dtstart_utime > (SELECT dtstart_utime FROM %s "
-                               "WHERE event_id = %d ORDER BY dtstart_utime LIMIT %d, 1) ",
-                               CALS_TABLE_NORMAL_INSTANCE,
-                               event_id,
-                               CALS_TABLE_NORMAL_INSTANCE,
-                               event_id, cnt -1);
-
-       } else if (st->type == CALS_TIME_LOCALTIME) {
-               snprintf(query, sizeof(query), "DELETE FROM %s "
-                               "WHERE event_id = %d "
-                               "AND dtstart_datetime > (SELECT dtstart_datetime FROM %s "
-                               "WHERE event_id = %d ORDER BY dtstart_datetime LIMIT %d, 1) ",
-                               CALS_TABLE_ALLDAY_INSTANCE,
-                               event_id,
-                               CALS_TABLE_ALLDAY_INSTANCE,
-                               event_id, cnt -1);
-       }
-
-       r = cals_query_exec(query);
-       if (r) {
-               ERR("cals_query_prepare failed (%d)", r);
-               return -1;
-               }
-       DBG("query(%s)", query);
-       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 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;
-       struct cals_time in;
-       struct cals_time until;
-       char query[CALS_SQL_MIN_LEN];
-
-       r = CAL_SUCCESS;
-
-       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++) {
-               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)) {
-                       DBG("exit in is_after");
-                       break;
-               }
-
-               if (st->type == CALS_TIME_UTIME) {
-                       snprintf(query, sizeof(query), "INSERT INTO %s "
-                                       "VALUES (%d, %lld, %lld)",
-                                       CALS_TABLE_NORMAL_INSTANCE,
-                                       event_id, in.utime, in.utime + dr);
-
-               } else if (st->type == CALS_TIME_LOCALTIME) {
-                       if (dr > 0) {
-                               e_cal = ucal_clone(cal, &status);
-                               ucal_add(e_cal, UCAL_DATE, dr, &status);
-                               e_year = ucal_get(e_cal, UCAL_YEAR, &status);
-                               e_month = ucal_get(e_cal, UCAL_MONTH, &status) + 1;
-                               e_mday = ucal_get(e_cal, UCAL_DATE, &status);
-                               ucal_close(e_cal);
-                       }
-                       else {
-                               e_year = in.year;
-                               e_month = in.month;
-                               e_mday = in.mday;
-                       }
-
-                       snprintf(query, sizeof(query), "INSERT INTO %s "
-                                       "VALUES (%d, %04d%02d%02d, %04d%02d%02d)",
-                                       CALS_TABLE_ALLDAY_INSTANCE, event_id,
-                                       in.year, in.month, in.mday,
-                                       e_year, e_month, e_mday);
-               } else {
-                       ERR("Invalid dtstart time type");
-                       return CAL_ERR_ARG_INVALID;
-               }
-
-               DBG("query(%s)", query);
-               r = cals_query_exec(query);
-               if (r) {
-                       ERR("cals_query_prepare failed (%d)", r);
-                       break;
-               }
-
-               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;
-}
-
-static int _get_duration(struct cals_time *st, struct cals_time *et)
-{
-       UErrorCode status = U_ZERO_ERROR;
-       UCalendar *cal;
-       UDate ud;
-       int dr;
-       if (st->type == CALS_TIME_UTIME)
-               return et->utime - st->utime;
-
-       cal = _ucal_get_cal(et->tzid, -1);
-
-       _ucal_set_time(cal, et);
-
-       ud = ucal_getMillis(cal, &status);
-
-       _ucal_set_time(cal, st);
-
-       dr = ucal_getFieldDifference(cal, ud, UCAL_DATE, &status);
-       if (U_FAILURE(status)) {
-               ERR("ucal_getFieldDifference failed (%s)", u_errorName(status));
-               return 0;
-       }
-
-       ucal_close(cal);
-
-       return dr;
-}
-
-static inline int _get_month(const char *str)
-{
-       int month;
-
-       DBG("[%s]", str);
-       if (!str || !*str)
-               return -1;
-
-       month = atoi(str);
-       DBG("(%d)", month);
-       if (month < CALS_JANUARY || month > CALS_DECEMBER)
-               return -1;
-
-       return month;
-}
-
-static inline int _get_mday(const char *str, int *mday)
-{
-       int d;
-
-       if (!str || !*str)
-               return -1;
-
-       d = atoi(str);
-       if (d < 1 || d > 31)
-               return -1;
-
-       *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,
-               struct cals_time *st, int dr, int month, cal_sch_full_t *sch)
-{
-       UCalendar *cal;
-       int r;
-       int i;
-       int y, m, d;
-       int mday;
-       char **t;
-       const char *dl = ",";
-       UErrorCode status = U_ZERO_ERROR;
-
-       t = g_strsplit(sch->bymonthday, dl, -1);
-
-       if (!t) {
-               ERR("g_strsplit failed");
-               return CAL_ERR_OUT_OF_MEMORY;
-       }
-
-       for (i = 0; t[i]; ++i) {
-               r = _get_mday(t[i], &mday);
-               if (r < 0) {
-                       ERR("Failed to get mday");
-                       g_strfreev(t);
-                       return CAL_ERR_ARG_INVALID;
-               }
-
-               cal = _ucal_get_cal(st->tzid, sch->wkst);
-               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);
-               if (r) {
-                       ERR("_insert_bymday failed (%d)", r);
-                       g_strfreev(t);
-                       return r;
-               }
-       }
-       _ucal_del_inundant(event_id, st, sch);
-
-       return CAL_SUCCESS;
-}
-
-static int insert_no_by(int event_id,
-               struct cals_time *st, int dr, cal_sch_full_t *sch)
-{
-       UCalendar *cal;
-
-       cal = _ucal_get_cal(st->tzid, sch->wkst);
-       if (!cal)
-               return CAL_ERR_FAIL;
-
-       _ucal_set_time(cal, st);
-
-       return _insert_instance(cal, event_id, st, dr, CALS_NODAY, 0, sch);
-}
-
-static inline int _get_wday(const char *str, int *week, int *wday)
-{
-       int i;
-       int d;
-       char buf[3];
-
-       if (!str || !*str)
-               return -1;
-
-       if (!sscanf(str, "%d", &d)) {
-               DBG("no digit in front of char, so set 1 as default");
-               if (sscanf(str, "%s", buf) != 1) {
-                       ERR("Failed to get wday[%s]", str);
-                       return -1;
-               }
-               d = 1;
-       } else {
-               if (sscanf(str, "%d%s", &d, buf) != 2) {
-                       ERR("Failed to get wday[%s]", str);
-                       return -1;
-               }
-       }
-
-       *week = d > 4 ? -1 : d;
-
-       buf[2] = '\0';
-       DBG("Sets week(%d) wday[%s]", d, buf);
-
-       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 wday;
-       int week;
-       char **t;
-       const char *d = ",";
-
-       t = g_strsplit(sch->byday, d, -1);
-
-       if (!t) {
-               ERR("g_strsplit failed");
-               return CAL_ERR_OUT_OF_MEMORY;
-       }
-
-       wday = 0;
-       week = 0;
-
-       for (i = 0; t[i]; ++i) {
-               r = _get_wday(t[i], &week, &wday);
-               if (r < 0) {
-                       ERR("Failed to get wday");
-                       g_strfreev(t);
-                       return CAL_ERR_ARG_INVALID;
-               }
-
-               cal = _ucal_get_cal(st->tzid, sch->wkst);
-               if (!cal)
-                       return CAL_ERR_FAIL;
-               _ucal_set_time(cal, st);
-               _ucal_set_month(cal, month);
-
-               r = _insert_instance(cal, event_id, st, dr, wday, week, sch);
-               if (r) {
-                       ERR("_insert_bymday failed (%d)", r);
-                       g_strfreev(t);
-                       return r;
-               }
-       }
-
-       _ucal_del_inundant(event_id, st, sch);
-       g_strfreev(t);
-
-       return CAL_SUCCESS;
-}
-
-static int instance_insert_yearly(int event_id,
-               struct cals_time *st, int dr, cal_sch_full_t *sch)
-{
-       CALS_FN_CALL;
-       int month;
-
-       month = _get_month(sch->bymonth);
-       if (month < 0) {
-               ERR("_get_month failed");
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       if (sch->bymonthday)
-               return insert_bymday(event_id, st, dr, month, sch);
-       else
-               return insert_byday(event_id, st, dr, month, sch);
-
-       return CAL_ERR_ARG_INVALID;
-}
-
-static int instance_insert_monthly(int event_id,
-               struct cals_time *st, int dr, cal_sch_full_t *sch)
-{
-       CALS_FN_CALL;
-       if (sch->bymonthday)
-               return insert_bymday(event_id, st, dr, CALS_NOMONTH, sch);
-       else if (sch->byday)
-               return insert_byday(event_id, st, dr, CALS_NOMONTH, sch);
-       return CAL_ERR_ARG_INVALID;
-}
-
-static int instance_insert_daily(int event_id,
-               struct cals_time *st, int dr, cal_sch_full_t *sch)
-{
-       CALS_FN_CALL;
-       return insert_no_by(event_id, st, dr, sch);
-}
-
-static int instance_insert_weekly(int event_id,
-               struct cals_time *st, int dr, cal_sch_full_t *sch)
-{
-       CALS_FN_CALL;
-       if (sch->byday)
-               return insert_byday(event_id, st, dr, CALS_NOMONTH, sch);
-       return CAL_ERR_ARG_INVALID;
-}
-
-static int instance_insert_once(int event_id,
-               struct cals_time *st, int dr, cal_sch_full_t *sch)
-{
-       CALS_FN_CALL;
-       return insert_no_by(event_id, st, dr, sch);
-}
-
-static int _get_max_count(cal_sch_full_t *sch)
-{
-       int cnt;
-
-       cnt = inst_info[sch->freq].max;
-
-       if (sch->range_type == CALS_RANGE_COUNT) {
-               if (sch->count < cnt)
-                       cnt = sch->count;
-       }
-       return cnt;
-}
-
-int cals_instance_insert(int event_id, struct cals_time *st,
-               struct cals_time *et, cal_sch_full_t *sch)
-{
-       if (sch->cal_type != CALS_SCH_TYPE_EVENT) {
-               DBG("Check schedule type, you're handling with type(%d)", sch->cal_type);
-               return -1;
-       }
-       int dr = _get_duration(st, et);
-       return inst_info[sch->freq].insert(event_id, st, dr, sch);
-}
-
-int cals_instance_delete(int event_id, struct cals_time *st)
-{
-       int r, ret;
-       int type;
-       sqlite3_stmt *stmt;
-       char query[CALS_SQL_MIN_LEN];
-
-       /* get type for noty */
-       snprintf(query, sizeof(query), "SELECT type FROM %s WHERE id = %d ",
-                       CALS_TABLE_SCHEDULE, event_id);
-       stmt = cals_query_prepare(query);
-       if (!stmt) {
-               ERR("cals_query_prepare failed");
-               return CAL_ERR_DB_FAILED;
-       }
-
-       r = cals_stmt_step(stmt);
-       if (r != CAL_SUCCESS) {
-               sqlite3_finalize(stmt);
-               ERR("cals_stmt_step failed (%d)", r);
-               return r;
-       }
-
-       type = sqlite3_column_int(stmt, 0);
-       sqlite3_finalize(stmt);
-
-       /* send noti */
-       ret = cals_notify(type == CALS_SCH_TYPE_EVENT ? CALS_NOTI_TYPE_EVENT : CALS_NOTI_TYPE_TODO);
-       if (ret < 0) {
-               WARN("cals_notify failed (%d)", ret);
-       }
-
-       /* delete instance from table */
-       if (st->type == CALS_TIME_UTIME) {
-               snprintf(query, sizeof(query), "DELETE FROM %s "
-                       "WHERE event_id = %d AND dtstart_utime = %lld",
-                       CALS_TABLE_NORMAL_INSTANCE, event_id, st->utime);
-
-       } else if (st->type == CALS_TIME_LOCALTIME) {
-               snprintf(query, sizeof(query), "DELETE FROM %s "
-                               "WHERE event_id = %d AND %04d%02d%02d",
-                               CALS_TABLE_ALLDAY_INSTANCE, event_id, st->year, st->month, st->mday);
-
-       } else {
-               ERR("Invalid start time type");
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       r = cals_query_exec(query);
-       if (r)
-               ERR("cals_query_exec failed");
-
-       return r;
-}
-
diff --git a/src/cals-instance.h b/src/cals-instance.h
deleted file mode 100644 (file)
index d39ad04..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "cals-typedef.h"
-#include "cals-time.h"
-
-int cals_instance_insert(int event_id, struct cals_time *st, struct cals_time *et, cal_sch_full_t *sch);
-int cals_instance_delete(int event_id, struct cals_time *st);
-
diff --git a/src/cals-provider.c b/src/cals-provider.c
deleted file mode 100755 (executable)
index f5aac9d..0000000
+++ /dev/null
@@ -1,1861 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <ctype.h>
-#include <time.h>
-#include <unistd.h>
-#include <errno.h>
-#include <glib.h>
-#include <glib-object.h>
-#include <vconf.h>
-
-#include "cals-internal.h"
-#include "cals-typedef.h"
-#include "cals-utils.h"
-#include "cals-db.h"
-#include "cals-db-info.h"
-#include "cals-ical.h"
-#include "cals-alarm.h"
-#include "cals-sqlite.h"
-#include "cals-calendar.h"
-#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
-{
-       VALUE_TYPE_TEXT,
-       VALUE_TYPE_INT,
-       VALUE_TYPE_TIME,
-       VALUE_TYPE_DOUBLE,
-       VALUE_TYPE_USER,
-} cal_value_type_t;
-
-typedef struct
-{
-       char *field_name;
-       int type;
-} __cal_field_type;
-
-static const __cal_field_type __calendar_event_type_field[]={
-       {CAL_VALUE_INT_INDEX,                           VALUE_TYPE_INT},
-       {CAL_VALUE_INT_ACCOUNT_ID,                      VALUE_TYPE_INT},
-       {CAL_VALUE_TXT_SUMMARY,                         VALUE_TYPE_TEXT},
-       {CAL_VALUE_TXT_DESCRIPTION,                     VALUE_TYPE_TEXT},
-       {CAL_VALUE_TXT_LOCATION,                        VALUE_TYPE_TEXT},
-       {CAL_VALUE_TXT_CATEGORIES,                      VALUE_TYPE_TEXT},
-       {CAL_VALUE_INT_MISSED,                          VALUE_TYPE_INT},
-       {CAL_VALUE_INT_TASK_STATUS,                     VALUE_TYPE_INT},
-       {CAL_VALUE_INT_PRIORITY,                                VALUE_TYPE_INT},
-       {CAL_VALUE_INT_TIMEZONE,                                VALUE_TYPE_INT},
-       {CAL_VALUE_INT_FILE_ID,                         VALUE_TYPE_INT},
-       {CAL_VALUE_INT_CONTACT_ID,                      VALUE_TYPE_INT},
-       {CAL_VALUE_INT_BUSY_STATUS,                     VALUE_TYPE_INT},
-       {CAL_VALUE_INT_SENSITIVITY,                     VALUE_TYPE_INT},
-       {CAL_VALUE_INT_MEETING_STATUS,          VALUE_TYPE_INT},
-       {CAL_VALUE_TXT_UID,                                     VALUE_TYPE_TEXT},
-       {CAL_VALUE_TXT_ORGANIZER_NAME,          VALUE_TYPE_TEXT},
-       {CAL_VALUE_TXT_ORGANIZER_EMAIL,         VALUE_TYPE_TEXT},
-       {CAL_VALUE_INT_CALENDAR_TYPE,           VALUE_TYPE_INT},
-       {CAL_VALUE_TXT_GCAL_ID,                         VALUE_TYPE_TEXT},
-       {CAL_VALUE_INT_DELETED,                         VALUE_TYPE_INT},
-       {CAL_VALUE_TXT_UPDATED,                         VALUE_TYPE_TEXT},
-       {CAL_VALUE_INT_LOCATION_TYPE,           VALUE_TYPE_INT},
-       {CAL_VALUE_TXT_LOCATION_SUMMARY,                VALUE_TYPE_TEXT},
-       {CAL_VALUE_TXT_ETAG,                                    VALUE_TYPE_TEXT},
-       {CAL_VALUE_INT_CALENDAR_ID,                     VALUE_TYPE_INT},
-       {CAL_VALUE_INT_SYNC_STATUS,                     VALUE_TYPE_INT},
-       {CAL_VALUE_TXT_EDIT_URL,                                VALUE_TYPE_TEXT},
-       {CAL_VALUE_TXT_GEDERID,                         VALUE_TYPE_TEXT},
-       {CAL_VALUE_INT_DST,                                     VALUE_TYPE_INT},
-       {CAL_VALUE_INT_ORIGINAL_EVENT_ID,       VALUE_TYPE_INT},
-       {CAL_VALUE_INT_CALENDAR_INDEX,          VALUE_TYPE_INT},
-       {CAL_VALUE_DBL_LATITUDE,                                VALUE_TYPE_DOUBLE},
-       {CAL_VALUE_DBL_LONGITUDE,                       VALUE_TYPE_DOUBLE},
-       {CAL_VALUE_INT_EMAIL_ID,                          VALUE_TYPE_INT},
-       {CAL_VALUE_INT_AVAILABILITY,                    VALUE_TYPE_INT},
-       {CAL_VALUE_INT_PROGRESS,                        VALUE_TYPE_INT},
-       {NULL,                                                          VALUE_TYPE_USER}
-};
-
-static const __cal_field_type __calendar_table_field[] = {
-       {CAL_TABLE_INT_INDEX,                                   VALUE_TYPE_INT},
-       {CAL_TABLE_TXT_CALENDAR_ID,                             VALUE_TYPE_TEXT},
-       {CAL_TABLE_TXT_UID,                                             VALUE_TYPE_TEXT},
-       {CAL_TABLE_TXT_LINK,                                    VALUE_TYPE_TEXT},
-       {CAL_TABLE_INT_UPDATED,                                 VALUE_TYPE_INT},
-       {CAL_TABLE_TXT_NAME,                                    VALUE_TYPE_TEXT},
-       {CAL_TABLE_TXT_DESCRIPTION,                             VALUE_TYPE_TEXT},
-       {CAL_TABLE_TXT_AUTHOR,                                  VALUE_TYPE_TEXT},
-       {CAL_TABLE_TXT_COLOR,                                   VALUE_TYPE_TEXT},
-       {CAL_TABLE_INT_HIDDEN,                                  VALUE_TYPE_INT},
-       {CAL_TABLE_INT_SELECTED,                                VALUE_TYPE_INT},
-       {CAL_TABLE_TXT_LOCATION,                                VALUE_TYPE_TEXT},
-       {CAL_TABLE_INT_LOCALE,                                  VALUE_TYPE_INT},
-       {CAL_TABLE_INT_COUNTRY,                                 VALUE_TYPE_INT},
-       {CAL_TABLE_INT_TIME_ZONE,                               VALUE_TYPE_INT},
-       {CAL_TABLE_TXT_TIME_ZONE_LABEL,                 VALUE_TYPE_TEXT},
-       {CAL_TABLE_INT_DISPLAY_ALL_TIMEZONES,   VALUE_TYPE_INT},
-       {CAL_TABLE_INT_DATE_FIELD_ORDER,                VALUE_TYPE_INT},
-       {CAL_TABLE_INT_FROMAT_24HOUR_TIME,              VALUE_TYPE_INT},
-       {CAL_TABLE_INT_WEEK_START,                              VALUE_TYPE_INT},
-       {CAL_TABLE_INT_DEFAULT_CAL_MODE,                VALUE_TYPE_INT},
-       {CAL_TABLE_INT_CUSTOM_CAL_MODE,                 VALUE_TYPE_INT},
-       {CAL_TABLE_TXT_USER_LOCATION,                   VALUE_TYPE_TEXT},
-       {CAL_TABLE_TXT_WEATHER,                                 VALUE_TYPE_TEXT},
-       {CAL_TABLE_INT_SHOW_DECLINED_EVENTS,    VALUE_TYPE_INT},
-       {CAL_TABLE_INT_HIDE_INVITATIONS,                VALUE_TYPE_INT},
-       {CAL_TABLE_INT_ALTERNATE_CALENDAR,              VALUE_TYPE_INT},
-       {CAL_TABLE_INT_VISIBILITY,                              VALUE_TYPE_INT},
-       {CAL_TABLE_INT_PROJECTION,                              VALUE_TYPE_INT},
-       {CAL_TABLE_INT_SEQUENCE,                                VALUE_TYPE_INT},
-       {CAL_TABLE_INT_SUPRESS_REPLY_NOTIFICATIONS,VALUE_TYPE_INT},
-       {CAL_TABLE_INT_SYNC_EVENT,                              VALUE_TYPE_INT},
-       {CAL_TABLE_INT_TIMES_CLEANED,                   VALUE_TYPE_INT},
-       {CAL_TABLE_INT_GUESTS_CAN_MODIFY,               VALUE_TYPE_INT},
-       {CAL_TABLE_INT_GUESTS_CAN_INVITE_OTHERS,VALUE_TYPE_INT},
-       {CAL_TABLE_INT_GUESTS_CAN_SEE_GUESTS,   VALUE_TYPE_INT},
-       {CAL_TABLE_INT_ACCESS_LEVEL,                    VALUE_TYPE_INT},
-       {CAL_TABLE_INT_SYNC_STATUS,                             VALUE_TYPE_INT},
-       {CAL_TABLE_INT_ACCOUNT_ID,                              VALUE_TYPE_INT},
-       {CAL_TABLE_INT_SENSITIVITY,                             VALUE_TYPE_INT},
-       {NULL,VALUE_TYPE_USER}
-};
-
-
-static const __cal_field_type __timezone_table_field[] = {
-
-       {CAL_TZ_VALUE_INT_INDEX, VALUE_TYPE_INT},
-       {CAL_TZ_VALUE_INT_TZ_OFFSET, VALUE_TYPE_INT},
-
-       {CAL_TZ_VALUE_TXT_STD_NAME, VALUE_TYPE_TEXT},
-       {CAL_TZ_VALUE_INT_STD_START_MONTH, VALUE_TYPE_INT},
-       {CAL_TZ_VALUE_INT_STD_START_POSITION_OF_WEEK, VALUE_TYPE_INT},
-       {CAL_TZ_VALUE_INT_STD_START_DAY, VALUE_TYPE_INT},
-       {CAL_TZ_VALUE_INT_STD_START_HOUR, VALUE_TYPE_INT},
-       {CAL_TZ_VALUE_INT_STD_BIAS, VALUE_TYPE_INT},
-
-       {CAL_TZ_VALUE_TXT_DST_NAME, VALUE_TYPE_TEXT},
-       {CAL_TZ_VALUE_INT_DST_START_MONTH, VALUE_TYPE_INT},
-       {CAL_TZ_VALUE_INT_DST_START_POSITION_OF_WEEK, VALUE_TYPE_INT},
-       {CAL_TZ_VALUE_INT_DST_START_DAY, VALUE_TYPE_INT},
-       {CAL_TZ_VALUE_INT_DST_START_HOUR, VALUE_TYPE_INT},
-       {CAL_TZ_VALUE_INT_DST_BIAS, VALUE_TYPE_INT},
-
-       {NULL,VALUE_TYPE_USER}
-};
-
-static cal_value_type_t __calendar_svc_get_type(int type, const char *field)
-{
-
-       int index = 0;
-       const __cal_field_type *field_table;
-
-       if((type == CAL_STRUCT_TYPE_SCHEDULE)||(type == CAL_STRUCT_TYPE_TODO))
-               field_table = __calendar_event_type_field;
-       else if(type == CAL_STRUCT_TYPE_CALENDAR)
-               field_table = __calendar_table_field;
-       else //(type == CAL_STRUCT_TYPE_TIMEZONE)
-               field_table = __timezone_table_field;
-
-       index = 0;
-       while ((field_table[index].field_name != NULL) &&
-                               (strcmp(field_table[index].field_name, field)!=0))
-       {
-               index++;
-       }
-
-       return field_table[index].type;
-}
-
-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--;
-
-       return CAL_SUCCESS;
-}
-
-
-API int calendar_svc_subscribe_db_change(const char *noti_type, void(*calendarNotiCb)(void *), void *user_data)
-{
-       CALS_FN_CALL;
-       int ret;
-       const char *noti_path;
-
-       retv_if(NULL == noti_type, CAL_ERR_ARG_NULL);
-
-       if(0 == strcmp(noti_type, CAL_STRUCT_SCHEDULE))
-               noti_path = cals_noti_get_file_path(CALS_NOTI_TYPE_EVENT);
-       else if(0 == strcmp(noti_type, CAL_STRUCT_TODO))
-               noti_path = cals_noti_get_file_path(CALS_NOTI_TYPE_TODO);
-       else if(0 == strcmp(noti_type, CAL_STRUCT_CALENDAR))
-               noti_path = cals_noti_get_file_path(CALS_NOTI_TYPE_CALENDAR);
-       else {
-               ERR("Invalid noti_type(%s)", noti_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       ret = cals_inotify_subscribe(noti_path, calendarNotiCb, user_data);
-       retvm_if(CAL_SUCCESS != ret, ret, "cals_inotify_subscribe() Failed(%d)", ret);
-
-       return CAL_SUCCESS;
-}
-
-
-API int calendar_svc_unsubscribe_db_change (const char *noti_type, void(*cb)(void *))
-{
-       CALS_FN_CALL;
-       int ret;
-       const char *noti_path;
-
-       retv_if(NULL == noti_type, CAL_ERR_ARG_NULL);
-       retv_if(NULL == cb, CAL_ERR_ARG_NULL);
-
-       if(0 == strcmp(noti_type, CAL_STRUCT_SCHEDULE))
-               noti_path = cals_noti_get_file_path(CALS_NOTI_TYPE_EVENT);
-       else if(0 == strcmp(noti_type, CAL_STRUCT_TODO))
-               noti_path = cals_noti_get_file_path(CALS_NOTI_TYPE_TODO);
-       else if(0 == strcmp(noti_type, CAL_STRUCT_CALENDAR))
-               noti_path = cals_noti_get_file_path(CALS_NOTI_TYPE_CALENDAR);
-       else {
-               ERR("Invalid noti_type(%s)", noti_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       ret = cals_inotify_unsubscribe(noti_path, cb);
-       retvm_if(CAL_SUCCESS != ret, ret, "cals_inotify_unsubscribe() Failed(%d)", ret);
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_subscribe_change (void(*calendarNotiCb)(void *), void *user_data)
-{
-       CALS_FN_CALL;
-       calendar_svc_subscribe_db_change(CAL_STRUCT_SCHEDULE, calendarNotiCb,user_data);
-       calendar_svc_subscribe_db_change(CAL_STRUCT_TODO, calendarNotiCb,user_data);
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_unsubscribe_change (void(*cb)(void *))
-{
-       CALS_FN_CALL;
-       calendar_svc_unsubscribe_db_change(CAL_STRUCT_SCHEDULE, cb);
-       calendar_svc_unsubscribe_db_change(CAL_STRUCT_TODO, cb);
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_insert(cal_struct *event)
-{
-       int ret, index = 0;
-       cal_sch_full_t *sch_temp = NULL;
-       calendar_t *cal_temp = NULL;
-       cal_timezone_t * tz_temp = NULL;
-       clock_t start_time=0,end_time = 0;
-
-       retv_if(NULL == event, CAL_ERR_ARG_NULL);
-
-       start_time = CAL_PROFILE_GET_TIME();
-
-       ret = cals_begin_trans();
-       retvm_if(CAL_SUCCESS != ret, ret, "cals_begin_trans() Failed(%d)", ret);
-       DBG("insert cal type(%d)", ((cal_sch_full_t*)event->user_data)->cal_type);
-
-       switch(event->event_type) {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-               sch_temp = (cal_sch_full_t*)event->user_data;
-               if (sch_temp->cal_type != CALS_SCH_TYPE_EVENT) {
-                       ERR("Invalid type check (%d)", sch_temp->cal_type);
-                       return CAL_ERR_FAIL;
-               }
-/*
-               if (sch_temp->calendar_id == DEFAULT_TODO_CALENDAR_ID) {
-                       ERR("Error, tried to insert TODO calendar id.");
-                       return CAL_ERR_FAIL;
-               }
-*/
-
-               ret = cals_insert_schedule(sch_temp);
-               if (ret < CAL_SUCCESS) {
-                       cals_end_trans(false);
-                       ERR("cals_insert_schedule() Failed(%d)", ret);
-                       return ret;
-               }
-
-               index = sch_temp->index = ret;
-               break;
-       case CAL_STRUCT_TYPE_CALENDAR:
-               cal_temp = (calendar_t*)event->user_data;
-
-               ret = cals_insert_calendar(cal_temp);
-               if (ret < CAL_SUCCESS) {
-                       cals_end_trans(false);
-                       ERR("cals_insert_calendar() Failed(%d)", ret);
-                       return ret;
-               }
-
-               index = cal_temp->index = ret;
-               break;
-       case CAL_STRUCT_TYPE_TODO:
-               sch_temp = (cal_sch_full_t*)event->user_data;
-               if (sch_temp->cal_type != CALS_SCH_TYPE_TODO) {
-                       ERR("Invalid type check (%d)", sch_temp->cal_type);
-                       return CAL_ERR_FAIL;
-               }
-/*
-               if (sch_temp->calendar_id == DEFAULT_EVENT_CALENDAR_ID) {
-                       ERR("Error, tried to insert TODO calendar id.");
-                       return CAL_ERR_FAIL;
-               }
-*/
-               ret = cals_insert_schedule(sch_temp);
-               if (ret < CAL_SUCCESS) {
-                       cals_end_trans(false);
-                       ERR("cals_insert_schedule() Failed(%d)", ret);
-                       return ret;
-               }
-
-               index = sch_temp->index = ret;
-               break;
-       case CAL_STRUCT_TYPE_TIMEZONE:
-               tz_temp = (cal_timezone_t*)event->user_data;
-
-               ret = cals_insert_timezone(tz_temp);
-               if (ret < CAL_SUCCESS) {
-                       cals_end_trans(false);
-                       ERR("cals_insert_timezone() Failed(%d)", ret);
-                       return ret;
-               }
-
-               index = tz_temp->index = ret;
-               break;
-       default:
-               cals_end_trans(false);
-               ERR("Unknown event type(%d)", event->event_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-       cals_end_trans(true);
-
-       end_time = CAL_PROFILE_GET_TIME();
-       CAL_PROFILE_PRINT(start_time,end_time);
-
-       return index;
-}
-
-
-API int calendar_svc_get(const char *data_type,int index,const char *field_list, cal_struct **record)
-{
-       CALS_FN_CALL;
-       int error_code = 0;
-       char sql_value[CALS_SQL_MIN_LEN] = {0};
-       char rearranged[CALS_SQL_MIN_LEN] = {0};
-       int rc = 0;
-       sqlite3_stmt *stmt = NULL;
-       bool malloc_inside = false;
-
-       retex_if(NULL == data_type,,"data_type is NULL");
-       retex_if(NULL == record ,,"record is NULL");
-
-       if((0 == strcmp(data_type,CAL_STRUCT_SCHEDULE)) || (0 == strcmp(data_type,CAL_STRUCT_TODO)))
-       {
-               if(NULL == *record)
-               {
-                       *record = calendar_svc_struct_new(data_type);
-                       retex_if(NULL == *record,,"calendar_svc_struct_new() Failed");
-
-                       malloc_inside = true;
-               }
-
-               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 ",
-                                       CALS_TABLE_SCHEDULE, rearranged, index);
-               } else {
-                       snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s WHERE id = %d ",
-                                       CALS_TABLE_SCHEDULE, index);
-               }
-
-               DBG("query(%s)", sql_value);
-               stmt = cals_query_prepare(sql_value);
-               retex_if(NULL == stmt,,"cals_query_prepare() Failed");
-
-               rc = cals_stmt_step(stmt);
-               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) {
-                               calendar_svc_struct_free(record);
-                       }
-                       return CAL_ERR_FAIL;
-               }
-
-               if (field_list)
-                       cals_stmt_get_filted_schedule(stmt, sch_record, field_list);
-               else
-                       cals_stmt_get_full_schedule(stmt, sch_record, true);
-
-               sqlite3_finalize(stmt);
-               stmt = NULL;
-
-               if (sch_record->rrule_id > 0) {
-
-                       snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s WHERE event_id = %d ",
-                                       CALS_TABLE_RRULE, index);
-
-                       DBG("has rrule_is query(%s)", sql_value);
-
-                       stmt = cals_query_prepare(sql_value);
-                       retex_if(NULL == stmt,,"cals_query_prepare() Failed");
-
-                       rc = cals_stmt_step(stmt);
-                       if (rc != CAL_TRUE) {
-                               ERR("Failed to step stmt(%d)", rc);
-                               sqlite3_finalize(stmt);
-                               if (malloc_inside && *record != NULL) {
-                                       calendar_svc_struct_free(record);
-                               }
-                               return CAL_ERR_FAIL;
-                       }
-
-                       cals_stmt_fill_rrule(stmt, sch_record);
-                       sqlite3_finalize(stmt);
-                       stmt = NULL;
-               }
-
-               sch_record->index = index;
-
-               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))
-       {
-               if(NULL == *record)
-               {
-                       *record = calendar_svc_struct_new(CAL_STRUCT_CALENDAR);
-                       retex_if(NULL == *record,,"calendar_svc_struct_new() Failed");
-               }
-
-               calendar_t *calendar = NULL;
-               calendar = (*record)->user_data;
-
-               if (field_list) {
-                       cals_rearrage_calendar_field(field_list, rearranged, sizeof(rearranged));
-                       snprintf(sql_value, sizeof(sql_value), "SELECT rowid %s FROM %s WHERE rowid=%d",
-                               rearranged, CALS_TABLE_CALENDAR, index);
-               }
-               else
-                       snprintf(sql_value, sizeof(sql_value), "SELECT rowid,* FROM %s WHERE rowid=%d",
-                               CALS_TABLE_CALENDAR,    index);
-
-               stmt = cals_query_prepare(sql_value);
-               retex_if(NULL == stmt,,"cals_query_prepare() Failed");
-
-               rc = cals_stmt_step(stmt);
-               if (rc != CAL_TRUE) {
-                       ERR("Failed to step stmt(%d)", rc);
-                       sqlite3_finalize(stmt);
-                       if (malloc_inside && *record != NULL) {
-                               calendar_svc_struct_free(record);
-                       }
-                       return CAL_ERR_FAIL;
-               }
-
-               if (field_list)
-                       cals_stmt_get_filted_calendar(stmt, calendar, field_list);
-               else
-                       cals_stmt_get_calendar(stmt, calendar);
-
-               calendar->index = index;
-       }
-       else if(0 == strcmp(data_type,CAL_STRUCT_TIMEZONE))
-       {
-               if(NULL == *record)
-               {
-                       *record = calendar_svc_struct_new(CAL_STRUCT_TIMEZONE);
-                       retex_if(NULL == *record,,"calendar_svc_struct_new() Failed");
-               }
-
-               cal_timezone_t *detail_record = NULL;
-               detail_record = (*record)->user_data;
-
-               /*if(NULL != field_list) - not support yet
-                 {
-                 sprintf(sql_value,"select rowid,%s from timezone_table where rowid=%d;",field_list,index);
-                 }
-                 else*/
-               {
-                       snprintf(sql_value, sizeof(sql_value), "select rowid,* from timezone_table where rowid=%d;",index);
-               }
-
-               stmt = cals_query_prepare(sql_value);
-               retex_if(NULL == stmt,,"cals_query_prepare() Failed");
-
-               rc = cals_stmt_step(stmt);
-               if (rc != CAL_TRUE) {
-                       ERR("Failed to step stmt(%d)", rc);
-                       sqlite3_finalize(stmt);
-                       if (malloc_inside && *record != NULL) {
-                               calendar_svc_struct_free(record);
-                       }
-                       return CAL_ERR_FAIL;
-               }
-
-               /*if(NULL != field_list) - not support yet
-                 {
-                 cal_db_service_convert_stmt_to_select_field_tz_info(stmt,detail_record,field_list);
-                 }
-                 else*/
-               {
-                       cal_db_service_convert_stmt_to_tz_info(stmt,detail_record);
-               }
-
-               detail_record->index = index;
-       }
-       else
-       {
-               retex_if(true,,"Can not find!\n");
-       }
-
-
-       if (stmt != NULL)
-       {
-               sqlite3_finalize(stmt);
-               stmt = NULL;
-       }
-
-       return CAL_SUCCESS;
-
-CATCH:
-
-       if (stmt != NULL)
-       {
-               sqlite3_finalize(stmt);
-               stmt = NULL;
-       }
-
-       if(malloc_inside)
-       {
-               if(NULL != *record)
-               {
-                       calendar_svc_struct_free(record);
-               }
-       }
-
-       return CAL_ERR_FAIL;
-
-}
-
-
-API int calendar_svc_get_count(int account_id, int calendar_id, const char *data_type)
-{
-       CALS_FN_CALL;
-       int count = 0;
-       char sql_value[CALS_SQL_MIN_LEN] = {0};
-       char condition_value[CALS_SQL_MIN_LEN] = {0};
-
-       retv_if(NULL == data_type, CAL_ERR_ARG_NULL);
-
-       if(0 == strcmp(data_type,CAL_STRUCT_SCHEDULE))
-       {
-               snprintf(condition_value, sizeof(condition_value), "WHERE type=%d",CALS_SCH_TYPE_EVENT);
-
-               if(account_id == ALL_VISIBILITY_ACCOUNT || calendar_id==ALL_VISIBILITY_ACCOUNT)
-               {
-                       snprintf(sql_value, sizeof(sql_value), "SELECT COUNT(*) "
-                                       "FROM %s A, %s B %s "
-                                       "AND A.calendar_id = B.rowid AND B.visibility = 1 AND A.is_deleted = 0 "
-                                       "ORDER BY A.dtstart_utime",
-                                       CALS_TABLE_SCHEDULE, CALS_TABLE_CALENDAR, condition_value);
-               }
-               else
-               {
-                       if(account_id !=0)
-                       {
-                               snprintf(condition_value, sizeof(condition_value), "%s AND account_id = %d",condition_value,account_id);
-                       }
-
-                       if(calendar_id != 0)
-                       {
-                               snprintf(condition_value, sizeof(condition_value), "%s AND calendar_id = %d",condition_value,calendar_id);
-                       }
-
-                       snprintf(sql_value, sizeof(sql_value), "SELECT COUNT(*) FROM %s %s "
-                                       "AND is_deleted = 0 "
-                                       "ORDER BY dtstart_utime",
-                                       CALS_TABLE_SCHEDULE, condition_value);
-               }
-
-       }
-       else if(0 == strcmp(data_type,CAL_STRUCT_TODO))
-       {
-               snprintf(condition_value, sizeof(condition_value), "WHERE type=%d",CALS_SCH_TYPE_TODO);
-
-               if(account_id !=0)
-               {
-                       snprintf(condition_value, sizeof(condition_value), "%s AND account_id = %d ",condition_value,account_id);
-               }
-
-               if(calendar_id != 0)
-               {
-                       snprintf(condition_value, sizeof(condition_value), "%s AND calendar_id = %d ",condition_value,calendar_id);
-               }
-
-               snprintf(sql_value, sizeof(sql_value), "SELECT COUNT(*) FROM %s %s "
-                               "AND is_deleted = 0 ",
-                               CALS_TABLE_SCHEDULE, condition_value);
-
-       }
-       else if(0 == strcmp(data_type,CAL_STRUCT_CALENDAR))
-       {
-               condition_value[0] = '\0';
-
-               if(account_id != 0)
-               {
-                       snprintf(condition_value, sizeof(condition_value), "WHERE account_id = %d ", account_id);
-               }
-
-               snprintf(sql_value, sizeof(sql_value), "SELECT COUNT(*) FROM %s %s;", CALS_TABLE_CALENDAR, condition_value);
-
-       }
-       else //not support yet
-       {
-               ERR("Invalid type(%s)", data_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       count = cals_query_get_first_int_result(sql_value);
-
-       return count;
-}
-
-/* get entry */
-API int calendar_svc_get_all(int account_id, int calendar_id,const char *data_type, cal_iter **iter)
-{
-       CALS_FN_CALL;
-       int type;
-       sqlite3_stmt *stmt = NULL;
-       char sql_value[CALS_SQL_MIN_LEN];
-
-       retvm_if(NULL == data_type, CAL_ERR_ARG_NULL, "Invalid argument: data type is NULL");
-       retvm_if(NULL == iter, CAL_ERR_ARG_NULL, "Invalid argument: iter is not NULL");
-
-       if(0 == strcmp(data_type,CAL_STRUCT_SCHEDULE))
-       {
-               if (account_id == ALL_VISIBILITY_ACCOUNT || calendar_id==ALL_VISIBILITY_ACCOUNT)
-               {
-                       snprintf(sql_value, sizeof(sql_value), "SELECT A.* "
-                                       "FROM %s A, %s B ON A.calendar_id = B.rowid "
-                                       "WHERE A.type=%d AND B.visibility = 1 AND A.is_deleted = 0 "
-                                       "ORDER BY id",
-                                       CALS_TABLE_SCHEDULE, CALS_TABLE_CALENDAR, CALS_SCH_TYPE_EVENT);
-               }
-               else
-               {
-                       if (calendar_id > 0)
-                               snprintf(sql_value, sizeof(sql_value), "SELECT * FROM %s "
-                                       "WHERE type=%d AND calendar_id = %d AND is_deleted = 0 "
-                                       "ORDER BY id",
-                                       CALS_TABLE_SCHEDULE, CALS_SCH_TYPE_EVENT, calendar_id);
-                       else if (account_id)
-                               snprintf(sql_value, sizeof(sql_value), "SELECT * FROM %s "
-                                       "WHERE type=%d AND account_id = %d AND is_deleted = 0 "
-                                       "ORDER BY id",
-                                       CALS_TABLE_SCHEDULE, CALS_SCH_TYPE_EVENT, account_id);
-                       else
-                               snprintf(sql_value, sizeof(sql_value), "SELECT * FROM %s "
-                                       "WHERE type=%d AND is_deleted = 0 "
-                                       "ORDER BY id",
-                                       CALS_TABLE_SCHEDULE, CALS_SCH_TYPE_EVENT);
-               }
-
-               type = CAL_STRUCT_TYPE_SCHEDULE;
-       }
-       else if(0 == strcmp(data_type,CAL_STRUCT_TODO))
-       {
-               if (calendar_id > 0)
-                       snprintf(sql_value, sizeof(sql_value), "SELECT * FROM %s "
-                                       "WHERE type=%d AND calendar_id = %d AND is_deleted = 0 ORDER BY id",
-                                       CALS_TABLE_SCHEDULE, CALS_SCH_TYPE_TODO, calendar_id);
-               else if (account_id)
-                       snprintf(sql_value, sizeof(sql_value), "SELECT * FROM %s "
-                                       "WHERE type=%d AND account_id = %d AND is_deleted = 0  ORDER BY id",
-                                       CALS_TABLE_SCHEDULE, CALS_SCH_TYPE_TODO, account_id);
-               else
-                       snprintf(sql_value, sizeof(sql_value), "SELECT * FROM %s "
-                                       "WHERE type=%d AND is_deleted = 0  ORDER BY id",
-                                       CALS_TABLE_SCHEDULE, CALS_SCH_TYPE_TODO);
-
-               type = CAL_STRUCT_TYPE_TODO;
-       }
-       else if(0 == strcmp(data_type,CAL_STRUCT_CALENDAR))
-       {
-               if (account_id)
-                       snprintf(sql_value, sizeof(sql_value), "SELECT rowid,* FROM %s WHERE account_id = %d", CALS_TABLE_CALENDAR, account_id);
-               else
-                       snprintf(sql_value, sizeof(sql_value), "SELECT rowid,* FROM %s", CALS_TABLE_CALENDAR);
-
-               type = CAL_STRUCT_TYPE_CALENDAR;
-       }
-       else //not support yet
-       {
-               ERR("Unknown Type(%s)", data_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       DBG("query(%s)", sql_value);
-       stmt = cals_query_prepare(sql_value);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       *iter = calloc(1, sizeof(cal_iter));
-       retvm_if(NULL == *iter, CAL_ERR_OUT_OF_MEMORY, "calloc() Failed(%d)", errno);
-
-       (*iter)->stmt = stmt;
-       (*iter)->i_type = type;
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_update(cal_struct *record)
-{
-       CALS_FN_CALL;
-       int ret = 0;
-
-       retv_if(NULL == record, CAL_ERR_ARG_NULL);
-
-       cal_sch_full_t *event_record_schedule = NULL;
-       calendar_t *event_record_calendar = NULL;
-       cal_timezone_t *tz_info = NULL;
-
-       ret = cals_begin_trans();
-       retvm_if(CAL_SUCCESS != ret, ret, "cals_begin_trans() Failed(%d)", ret);
-
-       switch(record->event_type)      {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-       case CAL_STRUCT_TYPE_TODO:
-               event_record_schedule = record->user_data;
-               ret = cals_update_schedule(event_record_schedule->index,event_record_schedule);
-               if (CAL_SUCCESS != ret) {
-                       cals_end_trans(false);
-                       ERR("cals_update_schedule() Failed(%d)", ret);
-                       return ret;
-               }
-               break;
-       case CAL_STRUCT_TYPE_CALENDAR:
-               event_record_calendar = record->user_data;
-               ret = cals_update_calendar(event_record_calendar);
-               if (CAL_SUCCESS != ret) {
-                       cals_end_trans(false);
-                       ERR("cals_update_calendar() Failed(%d)", ret);
-                       return ret;
-               }
-               break;
-       case CAL_STRUCT_TYPE_TIMEZONE:
-               tz_info = record->user_data;
-               ret = cals_update_timezone(tz_info);
-               if (CAL_SUCCESS != ret) {
-                       cals_end_trans(false);
-                       ERR("cals_update_timezone() Failed(%d)", ret);
-                       return ret;
-               }
-               break;
-       default:
-               cals_end_trans(false);
-               ERR("Unknown event type(%d)", record->event_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-       cals_end_trans(true);
-
-       return CAL_SUCCESS;
-}
-
-
-API int calendar_svc_delete(const char *data_type, int index)
-{
-       CALS_FN_CALL;
-       int ret = 0;
-
-       retv_if(NULL == data_type, CAL_ERR_ARG_NULL);
-
-       ret = cals_begin_trans();
-       retvm_if(CAL_SUCCESS != ret, ret, "cals_begin_trans() Failed(%d)", ret);
-
-       if(0 == strcmp(data_type, CAL_STRUCT_SCHEDULE) || 0 == strcmp(data_type, CAL_STRUCT_TODO)) {
-               ret = cals_delete_schedule(index);
-               if (ret) {
-                       cals_end_trans(false);
-                       ERR("cals_delete_schedule() Failed(%d)", ret);
-                       return ret;
-               }
-       } else if(0 == strcmp(data_type, CAL_STRUCT_CALENDAR)) {
-               if(DEFAULT_EVENT_CALENDAR_ID == index || (DEFAULT_TODO_CALENDAR_ID == index)) {
-                       cals_end_trans(false);
-                       return CAL_ERR_FAIL;
-               }
-
-               ret = cals_delete_calendar(index);
-               if (ret) {
-                       cals_end_trans(false);
-                       ERR("cals_delete_calendar() Failed(%d)", ret);
-                       return ret;
-               }
-       } else {
-               cals_end_trans(false);
-               ERR("Invalid data_type(%s)", data_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-       cals_end_trans(true);
-
-       return CAL_SUCCESS;
-}
-
-
-API int calendar_svc_delete_account (int account_id)
-{
-       CALS_FN_CALL;
-       int ret = 0;
-       char sql[512] = {0,};
-
-       retvm_if(account_id < 0, CAL_ERR_ARG_INVALID, "account_id(%d) is Invalid", account_id);
-
-       ret = cals_alarm_remove(CALS_ALARM_REMOVE_BY_ACC_ID, account_id);
-       retvm_if(CAL_SUCCESS != ret, ret, "cals_alarm_remove() Failed(%d)", ret);
-
-       //delete schedule
-       if (account_id)
-               sprintf(sql,"DELETE FROM %s WHERE account_id = %d", CALS_TABLE_SCHEDULE, account_id);
-       else
-               sprintf(sql,"DELETE FROM %s", CALS_TABLE_SCHEDULE);
-
-       ret = cals_query_exec(sql);
-       retvm_if(ret, ret, "cals_query_exec() Failed(%d)", ret);
-
-       calendar_svc_delete_all(account_id, CAL_STRUCT_CALENDAR);
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_clean_after_sync(int calendar_id)
-{
-       int ret;
-       int id;
-       char query[CALS_SQL_MIN_LEN] = {0};
-       sqlite3_stmt *stmt = NULL;
-
-       retvm_if(calendar_id < 0, CAL_ERR_ARG_INVALID, "calendar_id(%d) is Invalid", calendar_id);
-
-       /* delete recur table */
-       /* get event id which id_delete = 1 */
-       snprintf(query, sizeof(query), "SELECT id FROM %s "
-                       "WHERE is_deleted = 1 AND calendar_id = %d",
-                       CALS_TABLE_SCHEDULE,
-                       calendar_id);
-       stmt = cals_query_prepare(query);
-       retvm_if(stmt == NULL, CAL_ERR_DB_FAILED, "Failed to query prepare");
-
-       /* delete all recur data */
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               id = sqlite3_column_int(stmt, 0);
-               if (id < 0) {
-                       ERR("FAiled to get rruel_id");
-                       break;
-               }
-
-               snprintf(query, sizeof(query), "DELETE FROM %s WHERE rrule_id = %d",
-                               CALS_TABLE_RRULE, id);
-               ret = cals_query_exec(query);
-               if (ret != CAL_SUCCESS) {
-                       ERR("Failed to query exit");
-                       break;
-               }
-       }
-       sqlite3_finalize(stmt);
-
-       /* delete event table */
-       snprintf(query, sizeof(query), "DELETE FROM %s "
-                       "WHERE is_deleted = 1 AND calendar_id = %d",
-                       CALS_TABLE_SCHEDULE,
-                       calendar_id);
-
-       ret = cals_query_exec(query);
-       retvm_if(ret < 0, ret, "cals_query_exec() failed (%d)", ret);
-
-       /* delete delete table */
-       snprintf(query, sizeof(query), "DELETE FROM %s "
-                       "WHERE calendar_id = %d",
-                       CALS_TABLE_DELETED,
-                       calendar_id);
-
-       ret = cals_query_exec(query);
-       retvm_if(ret < 0, ret, "cals_query_exec() failed (%d)", ret);
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_delete_all(int account_id, const char *data_type)
-{
-       int ret = 0;
-
-       retvm_if(account_id < 0, CAL_ERR_ARG_INVALID, "account_id(%d) is Invalid", account_id);
-
-       if(data_type == NULL) //delete all data from db by account id
-       {
-               ret = __cal_service_delete_all_records(account_id, CALS_SCH_TYPE_NONE);
-               retvm_if(CAL_SUCCESS != ret, ret, "__cal_service_delete_all_records() Failed(%d)", ret);
-               ret = cals_delete_calendars(account_id);
-               retvm_if(CAL_SUCCESS != ret, ret, "cals_delete_calendars() Failed(%d)", ret);
-       }
-       else if(0 == strcmp(data_type,CAL_STRUCT_SCHEDULE))
-       {
-               ret = __cal_service_delete_all_records(account_id, CALS_SCH_TYPE_EVENT);
-               retvm_if(CAL_SUCCESS != ret, ret, "__cal_service_delete_all_records() Failed(%d)", ret);
-       }
-       else if(0 == strcmp(data_type,CAL_STRUCT_TODO))
-       {
-               ret = __cal_service_delete_all_records(account_id, CALS_SCH_TYPE_TODO);
-               retvm_if(CAL_SUCCESS != ret, ret, "__cal_service_delete_all_records() Failed(%d)", ret);
-       }
-       else if(0 == strcmp(data_type,CAL_STRUCT_CALENDAR))
-       {
-               ret = cals_delete_calendars(account_id);
-               retvm_if(CAL_SUCCESS != ret, ret, "cals_delete_calendars() Failed(%d)", ret);
-       }
-       else
-       {
-               ERR("Unknow data_type(%s)", data_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       return CAL_SUCCESS;
-}
-
-
-API int calendar_svc_find_event_list(int account_id,const char *search_type,const void *search_value, cal_iter **iter)
-{
-       CALS_FN_CALL;
-       int ret = 0;
-       sqlite3_stmt *stmt = NULL;
-       char sql_value[CALS_SQL_MIN_LEN] = {0};
-       cal_value_type_t value_type = 0;
-
-       retv_if(NULL == search_type, CAL_ERR_ARG_NULL);
-       retv_if(NULL == iter, CAL_ERR_ARG_NULL);
-
-       value_type = __calendar_svc_get_type(CAL_STRUCT_TYPE_SCHEDULE,search_type);
-
-       switch(value_type)
-       {
-       case VALUE_TYPE_TEXT:
-               retv_if(NULL == search_value, CAL_ERR_ARG_NULL);
-
-               if(ALL_VISIBILITY_ACCOUNT == account_id)
-               {
-                       snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s "
-                                       "WHERE %s like upper('%%%s%%') AND is_deleted = 0 "
-                                       "ORDER BY dtstart_utime;",
-                                       CALS_TABLE_SCHEDULE, search_type, (char*)search_value);
-               }
-               else if(0 != account_id)
-               {
-                       snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s "
-                                       "WHERE %s like upper('%%%s%%') AND account_id = %d AND is_deleted = 0 "
-                                       "ORDER BY dtstart_utime;",
-                                       CALS_TABLE_SCHEDULE, search_type, (char*)search_value, account_id);
-               }
-               else
-               {
-                       snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s "
-                                       "WHERE %s like upper('%%%s%%') AND is_deleted = 0 "
-                                       "ORDER BY dtstart_utime;",
-                                       CALS_TABLE_SCHEDULE, search_type, (char*)search_value);
-               }
-               break;
-       case VALUE_TYPE_INT:
-               if(ALL_VISIBILITY_ACCOUNT == account_id)
-               {
-                       snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s "
-                                       "WHERE %s = %d AND is_deleted = 0 "
-                                       "ORDER BY dtstart_utime;",
-                                       CALS_TABLE_SCHEDULE, search_type,(int)search_value);
-               }
-               else if(0 != account_id)
-               {
-                       snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s "
-                                       "WHERE %s = %d AND account_id = %d AND is_deleted = 0 "
-                                       "ORDER BY dtstart_utime;",
-                                       CALS_TABLE_SCHEDULE, search_type, (int)search_value, account_id);
-               }
-               else
-               {
-                       snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s "
-                                       "WHERE %s = %d AND is_deleted = 0 "
-                                       "ORDER BY dtstart_utime;",
-                                       CALS_TABLE_SCHEDULE, search_type, (int)search_value);
-               }
-               break;
-       case VALUE_TYPE_USER:
-               if (0 == strcmp(CAL_VALUE_INT_ALARMS_ID, search_type)) {
-                       ret = cals_alarm_get_event_id((int)search_value);
-                       snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s "
-                                       "WHERE id = %d AND is_deleted = 0 "
-                                       "ORDER BY dtstart_utime",
-                                       CALS_TABLE_SCHEDULE, ret);
-                       break;
-               }
-       case VALUE_TYPE_TIME:
-       case VALUE_TYPE_DOUBLE:
-       default:
-               ERR("Unknown Type(%s:%d)", search_type, value_type);
-               break;
-       }
-
-       stmt = cals_query_prepare(sql_value);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       if(NULL == *iter)
-       {
-               *iter = calloc(1, sizeof(cal_iter));
-               if (NULL == *iter) {
-                       sqlite3_finalize(stmt);
-                       ERR("calloc() Failed(%d)", errno);
-                       return CAL_ERR_OUT_OF_MEMORY;
-               }
-       }
-
-       (*iter)->stmt = stmt;
-       (*iter)->i_type = CAL_STRUCT_TYPE_SCHEDULE;
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_convert_id_to_uid(const char *data_type,int index,char **uid)
-{
-       int     rc = -1;
-       char    sql_value[CALS_SQL_MAX_LEN] = {0};
-       sqlite3_stmt *stmt = NULL;
-       int return_value = CAL_SUCCESS;
-
-       retex_if(uid == NULL,return_value = CAL_ERR_ARG_NULL, "The calendar database hasn't been opened.");
-
-       retex_if(NULL == calendar_db_handle, return_value = CAL_ERR_DB_NOT_OPENED, "The calendar database hasn't been opened.");
-
-       // TODO: make query!!!!
-       if((0 == strcmp(data_type,CAL_STRUCT_SCHEDULE)) || (0 == strcmp(data_type,CAL_STRUCT_TODO)))
-       {
-               snprintf(sql_value, sizeof(sql_value), "select uid from schedule_table where id=%d;",index);
-       }
-       else if(0 == strcmp(data_type,CAL_STRUCT_CALENDAR))
-       {
-               snprintf(sql_value, sizeof(sql_value), "select uid from calendar_table where rowid=%d;",index);
-       }
-
-
-       rc = sqlite3_prepare_v2(calendar_db_handle, sql_value, strlen(sql_value), &stmt, NULL);
-       retex_if(rc != SQLITE_OK, return_value = CAL_ERR_DB_FAILED, "Failed to get stmt!!");
-
-       rc = sqlite3_step(stmt);
-       retex_if(rc!= SQLITE_ROW && rc!= SQLITE_OK && rc!= SQLITE_DONE, return_value = CAL_ERR_DB_FAILED, "[ERROR]cal_db_service_get_participant_info_by_index:Query error !!");
-
-       cal_db_get_text_from_stmt(stmt,uid,0);
-
-       if (stmt != NULL)
-       {
-               sqlite3_finalize(stmt);
-               stmt = NULL;
-       }
-
-       return CAL_SUCCESS;
-
-CATCH:
-
-       if (stmt != NULL)
-       {
-               sqlite3_finalize(stmt);
-               stmt = NULL;
-       }
-
-       return return_value;
-}
-
-int calendar_svc_convert_uid_to_id(const char *data_type,char *uid,int *index)
-{
-       int     rc = -1;
-       char    sql_value[CALS_SQL_MAX_LEN] = {0};
-       sqlite3_stmt *stmt = NULL;
-       int return_value = CAL_SUCCESS;
-
-       retex_if(uid == NULL, return_value = CAL_ERR_ARG_NULL, "The calendar database hasn't been opened.");
-
-       retex_if(NULL == calendar_db_handle, return_value = CAL_ERR_DB_NOT_OPENED, "The calendar database hasn't been opened.");
-
-       // TODO: make query!!!!
-       if((0 == strcmp(data_type,CAL_STRUCT_SCHEDULE)) || (0 == strcmp(data_type,CAL_STRUCT_TODO)))
-       {
-               snprintf(sql_value, sizeof(sql_value), "select id from schedule_table where uid=%s;",uid);
-       }
-       else if(0 == strcmp(data_type,CAL_STRUCT_CALENDAR))
-       {
-               snprintf(sql_value, sizeof(sql_value), "select rowid from calendar_table where uid=%s;",uid);
-       }
-
-
-       rc = sqlite3_prepare_v2(calendar_db_handle, sql_value, strlen(sql_value), &stmt, NULL);
-       retex_if(rc != SQLITE_OK, return_value = CAL_ERR_DB_FAILED, "Failed to get stmt!!");
-
-       rc = sqlite3_step(stmt);
-       retex_if(rc!= SQLITE_ROW && rc!= SQLITE_OK && rc!= SQLITE_DONE, return_value = CAL_ERR_DB_FAILED, "[ERROR]cal_db_service_get_participant_info_by_index:Query error !!");
-
-       *index = sqlite3_column_int(stmt,0);
-
-       if (stmt != NULL)
-       {
-               sqlite3_finalize(stmt);
-               stmt = NULL;
-       }
-
-       return CAL_SUCCESS;
-
-CATCH:
-
-       if (stmt != NULL)
-       {
-               sqlite3_finalize(stmt);
-               stmt = NULL;
-       }
-
-       return return_value;
-}
-
-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;
-}
-
-
-API int calendar_svc_iter_get_info(cal_iter *iter, cal_struct **row_event)
-{
-       int cnt;
-       int rc = 0;
-       char *s_datetime;
-       char *e_datetime;
-       char buf[8] = {0};
-       char sql_value[CALS_SQL_MIN_LEN] = {0};
-       cal_sch_full_t *sch_record = NULL;
-       calendar_t *cal_record = NULL;
-       cal_timezone_t *tz_record = NULL;
-       cals_updated *cal_updated = NULL;
-       sqlite3_stmt *stmt = NULL;
-
-       retv_if(NULL == iter, CAL_ERR_ARG_NULL);
-       retv_if(NULL == iter->stmt && NULL == iter->info, CAL_ERR_ARG_INVALID);
-       retv_if(NULL == row_event, CAL_ERR_ARG_NULL);
-
-       if(iter->is_patched!=TRUE)
-       {
-               int ret = calendar_svc_iter_next(iter);
-               if(ret == CAL_ERR_FINISH_ITER)
-                       return CAL_ERR_NO_DATA;
-               else if(ret != CAL_SUCCESS)
-                       return ret;
-       }
-
-       int error_code = 0;
-
-       switch(iter->i_type)
-       {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-               if (NULL == *row_event)
-               {
-                       *row_event = calendar_svc_struct_new(CAL_STRUCT_SCHEDULE);
-                       retvm_if(NULL == *row_event, CAL_ERR_FAIL, "calendar_svc_struct_new(SCHEDULE) Failed");
-               }
-               sch_record = (cal_sch_full_t*)(*row_event)->user_data;
-               retvm_if(NULL == sch_record, CAL_ERR_FAIL, "row_event is Invalid");
-
-               cals_stmt_get_full_schedule(iter->stmt,sch_record,true);
-
-               if (sch_record->rrule_id > 0) {
-                       snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s WHERE event_id = %d ",
-                                       CALS_TABLE_RRULE, sch_record->index);
-
-                       stmt = cals_query_prepare(sql_value);
-                       retvm_if(NULL == stmt, CAL_ERR_FAIL, "cals_query_prepare() Failed");
-
-                       rc = cals_stmt_step(stmt);
-                       retvm_if(CAL_TRUE != rc, CAL_ERR_FAIL, "cals_stmt_step() Failed(%d)", rc);
-
-
-                       cals_stmt_fill_rrule(stmt, sch_record);
-                       sqlite3_finalize(stmt);
-                       stmt = NULL;
-               }
-
-               cal_db_service_get_participant_info_by_index(sch_record->index,&(sch_record->attendee_list),&error_code);
-               cals_get_alarm_info(sch_record->index, &(sch_record->alarm_list));
-               break;
-
-       case CAL_STRUCT_TYPE_TODO:
-               if (NULL == *row_event)
-               {
-                       *row_event = calendar_svc_struct_new(CAL_STRUCT_TODO);
-                       retvm_if(NULL == *row_event, CAL_ERR_FAIL, "calendar_svc_struct_new(TODO) Failed");
-               }
-               sch_record = (cal_sch_full_t*)(*row_event)->user_data;
-               retvm_if(NULL == sch_record, CAL_ERR_FAIL, "row_event is Invalid");
-
-               cals_stmt_get_full_schedule(iter->stmt,sch_record,true);
-
-               if (sch_record->rrule_id > 0) {
-                       snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s WHERE event_id = %d ",
-                                       CALS_TABLE_RRULE, sch_record->index);
-
-                       stmt = cals_query_prepare(sql_value);
-                       retvm_if(NULL == stmt, CAL_ERR_FAIL, "cals_query_prepare() Failed");
-
-                       rc = cals_stmt_step(stmt);
-                       retvm_if(CAL_TRUE != rc, CAL_ERR_FAIL, "cals_stmt_step() Failed(%d)", rc);
-
-                       cals_stmt_fill_rrule(stmt, sch_record);
-                       sqlite3_finalize(stmt);
-                       stmt = NULL;
-               }
-               break;
-
-       case CAL_STRUCT_TYPE_CALENDAR:
-               if (NULL == *row_event)
-               {
-                       *row_event = calendar_svc_struct_new(CAL_STRUCT_CALENDAR);
-                       retvm_if(NULL == *row_event, CAL_ERR_FAIL, "calendar_svc_struct_new(CALENDAR) Failed");
-               }
-               cal_record = (calendar_t*)(*row_event)->user_data;
-               retvm_if(NULL == cal_record, CAL_ERR_FAIL, "row_event is Invalid");
-
-               cals_stmt_get_calendar(iter->stmt,cal_record);
-
-               break;
-       case CAL_STRUCT_TYPE_TIMEZONE:
-               if (NULL == *row_event)
-               {
-                       *row_event = calendar_svc_struct_new(CAL_STRUCT_TIMEZONE);
-                       retvm_if(NULL == *row_event, CAL_ERR_FAIL, "calendar_svc_struct_new(TIMEZONE) Failed");
-               }
-               tz_record = (cal_timezone_t*)(*row_event)->user_data;
-               retvm_if(NULL == tz_record, CAL_ERR_FAIL, "row_event is Invalid");
-
-               cal_db_service_convert_stmt_to_tz_info(iter->stmt,tz_record);
-               break;
-
-       case CAL_STRUCT_TYPE_UPDATED_LIST:
-               if (NULL == *row_event)
-               {
-                       *row_event = calendar_svc_struct_new(CAL_STRUCT_UPDATED);
-                       retvm_if (NULL == *row_event, CAL_ERR_FAIL, "calendar_svc_struct_new(CAL_STRUCT_UPDATE) Failed");
-               }
-               cal_updated = (cals_updated *)(*row_event)->user_data;
-               retvm_if(NULL == cal_updated, CAL_ERR_FAIL, "row_event is Invalid");
-
-               cals_iter_get_info_change(iter->info->cursor, cal_updated);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_ONOFF:
-               if (NULL == *row_event) {
-                       *row_event = calendar_svc_struct_new(CALS_STRUCT_PERIOD_NORMAL_ONOFF);
-                       retvm_if(NULL == *row_event, CAL_ERR_FAIL,
-                                       "Failed to new CALS_STRUCT_PERIOD_NORMAL_ONOFF");
-               }
-               cals_struct_period_normal_onoff *nof;
-               nof = (cals_struct_period_normal_onoff *)(*row_event)->user_data;
-               retvm_if(NULL == nof, CAL_ERR_FAIL, "user_data is NULL");
-
-               cnt = 0;
-               nof->index = sqlite3_column_int(iter->stmt, cnt++);
-               nof->dtstart_type = sqlite3_column_int(iter->stmt, cnt++);
-               nof->dtstart_utime = sqlite3_column_int64(iter->stmt, cnt++);
-               nof->dtend_type = sqlite3_column_int(iter->stmt, cnt++);
-               nof->dtend_utime = sqlite3_column_int64(iter->stmt, cnt++);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_ONOFF:
-               s_datetime = NULL;
-               if (NULL == *row_event) {
-                       *row_event = calendar_svc_struct_new(CALS_STRUCT_PERIOD_ALLDAY_ONOFF);
-                       retvm_if(NULL == *row_event, CAL_ERR_FAIL,
-                                       "Failed to new CALS_STRUCT_TYPE_PERIOD_ALLDAY_ONOFF");
-               }
-               cals_struct_period_allday_onoff *aof;
-               aof = (cals_struct_period_allday_onoff *)(*row_event)->user_data;
-               retvm_if(NULL == aof, CAL_ERR_FAIL, "user_data is NULL");
-
-               cnt = 0;
-               aof->index = sqlite3_column_int(iter->stmt, cnt++);
-               aof->dtstart_type = sqlite3_column_int(iter->stmt, cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(s_datetime),cnt++);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("YYYY") + 1, "%s", &s_datetime[0]);
-               aof->dtstart_year = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("MM") + 1, "%s", &s_datetime[4]);
-               aof->dtstart_month = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("DD") + 1, "%s", &s_datetime[6]);
-               aof->dtstart_mday = atoi(buf);
-
-               aof->dtend_type = sqlite3_column_int(iter->stmt, cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(s_datetime), cnt++);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("YYYY") + 1, "%s", &s_datetime[0]);
-               aof->dtend_year = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("MM") + 1, "%s", &s_datetime[4]);
-               aof->dtend_month = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("DD") + 1, "%s", &s_datetime[6]);
-               aof->dtend_mday = atoi(buf);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_BASIC:
-               if (NULL == *row_event) {
-                       *row_event = calendar_svc_struct_new(CALS_STRUCT_PERIOD_NORMAL_BASIC);
-                       retvm_if(NULL == *row_event, CAL_ERR_FAIL,
-                                       "Failed to new CALS_STRUCT_TYPE_PERIOD_NORMAL_BASIC");
-               }
-               cals_struct_period_normal_basic *nb;
-               nb = (cals_struct_period_normal_basic *)(*row_event)->user_data;
-               retvm_if(NULL == nb, CAL_ERR_FAIL, "user_data is NULL");
-
-               cnt = 0;
-               nb->index = sqlite3_column_int(iter->stmt, 0);
-               nb->dtstart_type = sqlite3_column_int(iter->stmt, 1);
-               nb->dtstart_utime = sqlite3_column_int64(iter->stmt, 2);
-               nb->dtend_type = sqlite3_column_int(iter->stmt, 3);
-               nb->dtend_utime = sqlite3_column_int64(iter->stmt, 4);
-               cal_db_get_text_from_stmt(iter->stmt,&(nb->summary), 5);
-               cal_db_get_text_from_stmt(iter->stmt,&(nb->location), 6);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_BASIC:
-               s_datetime = NULL;
-               e_datetime = NULL;
-               if (NULL == *row_event) {
-                       *row_event = calendar_svc_struct_new(CALS_STRUCT_PERIOD_ALLDAY_BASIC);
-                       retvm_if(NULL == *row_event, CAL_ERR_FAIL,
-                                       "Failed to new CALS_STRUCT_TYPE_PERIOD_ALLDAY_BASIC");
-               }
-               cals_struct_period_allday_basic *ab;
-               ab = (cals_struct_period_allday_basic *)(*row_event)->user_data;
-               retvm_if(NULL == ab, CAL_ERR_FAIL, "user_data is NULL");
-
-               cnt = 0;
-               ab->index = sqlite3_column_int(iter->stmt, cnt++);
-               ab->dtstart_type = sqlite3_column_int(iter->stmt, cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(s_datetime), cnt++);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("YYYY") + 1, "%s", &s_datetime[0]);
-               ab->dtstart_year = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("MM") + 1, "%s", &s_datetime[4]);
-               ab->dtstart_month = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("DD") + 1, "%s", &s_datetime[6]);
-               ab->dtstart_mday = atoi(buf);
-
-               ab->dtend_type = sqlite3_column_int(iter->stmt, cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(e_datetime),cnt++);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("YYYY") + 1, "%s", &e_datetime[0]);
-               ab->dtend_year = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("MM") + 1, "%s", &e_datetime[4]);
-               ab->dtend_month = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("DD") + 1, "%s", &e_datetime[6]);
-               ab->dtend_mday = atoi(buf);
-               cal_db_get_text_from_stmt(iter->stmt,&(ab->summary), cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(ab->location), cnt++);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_OSP:
-               if (NULL == *row_event) {
-                       *row_event = calendar_svc_struct_new(CALS_STRUCT_PERIOD_NORMAL_OSP);
-                       retvm_if(NULL == *row_event, CAL_ERR_FAIL,
-                                       "Failed to new CALS_STRUCT_TYPE_PERIOD_NORMAL_OSP");
-               }
-               cals_struct_period_normal_osp *nosp;
-               nosp = (cals_struct_period_normal_osp *)(*row_event)->user_data;
-               retvm_if(NULL == nosp, CAL_ERR_FAIL, "user_data is NULL");
-
-               cnt = 0;
-               nosp->index = sqlite3_column_int(iter->stmt, cnt++);
-               nosp->calendar_id = sqlite3_column_int(iter->stmt, cnt++);
-               nosp->dtstart_type = sqlite3_column_int(iter->stmt, cnt++);
-               nosp->dtstart_utime = sqlite3_column_int64(iter->stmt, cnt++);
-               nosp->dtend_type = sqlite3_column_int(iter->stmt, cnt++);
-               nosp->dtend_utime = sqlite3_column_int64(iter->stmt, cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(nosp->summary), cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(nosp->description), cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(nosp->location), cnt++);
-               nosp->busy_status= sqlite3_column_int(iter->stmt, cnt++);
-               nosp->meeting_status= sqlite3_column_int(iter->stmt, cnt++);
-               nosp->priority= sqlite3_column_int(iter->stmt, cnt++);
-               nosp->sensitivity= sqlite3_column_int(iter->stmt, cnt++);
-               nosp->rrule_id = sqlite3_column_int(iter->stmt, cnt++);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_OSP:
-               s_datetime = NULL;
-               e_datetime = NULL;
-               if (NULL == *row_event) {
-                       *row_event = calendar_svc_struct_new(CALS_STRUCT_PERIOD_ALLDAY_OSP);
-                       retvm_if(NULL == *row_event, CAL_ERR_FAIL,
-                                       "Failed to new CALS_STRUCT_TYPE_PERIOD_ALLDAY_OSP");
-               }
-               cals_struct_period_allday_osp *aosp;
-               aosp = (cals_struct_period_allday_osp *)(*row_event)->user_data;
-               retvm_if(NULL == aosp, CAL_ERR_FAIL, "user_data is NULL");
-
-               cnt = 0;
-               aosp->index = sqlite3_column_int(iter->stmt, cnt++);
-               aosp->calendar_id = sqlite3_column_int(iter->stmt, cnt++);
-               aosp->dtstart_type = sqlite3_column_int(iter->stmt, cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(s_datetime),cnt++);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("YYYY") + 1, "%s", &s_datetime[0]);
-               aosp->dtstart_year = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("MM") + 1, "%s", &s_datetime[4]);
-               aosp->dtstart_month = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("DD") + 1, "%s", &s_datetime[6]);
-               aosp->dtstart_mday = atoi(buf);
-
-               aosp->dtend_type = sqlite3_column_int(iter->stmt, cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(e_datetime),cnt++);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("YYYY") + 1, "%s", &e_datetime[0]);
-               aosp->dtend_year = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("MM") + 1, "%s", &e_datetime[4]);
-               aosp->dtend_month = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("DD") + 1, "%s", &e_datetime[6]);
-               aosp->dtend_mday = atoi(buf);
-               cal_db_get_text_from_stmt(iter->stmt,&(aosp->summary), cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(aosp->description), cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(aosp->location), cnt++);
-               aosp->busy_status= sqlite3_column_int(iter->stmt, cnt++);
-               aosp->meeting_status= sqlite3_column_int(iter->stmt, cnt++);
-               aosp->priority= sqlite3_column_int(iter->stmt, cnt++);
-               aosp->sensitivity= sqlite3_column_int(iter->stmt, cnt++);
-               aosp->rrule_id = sqlite3_column_int(iter->stmt, cnt++);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_LOCATION:
-               if (NULL == *row_event) {
-                       *row_event = calendar_svc_struct_new(CALS_STRUCT_PERIOD_NORMAL_LOCATION);
-                       retvm_if(NULL == *row_event, CAL_ERR_FAIL,
-                                       "Failed to new CALS_STRUCT_TYPE_PERIOD_NORMAL_OSP");
-               }
-               cals_struct_period_normal_location *nosl;
-               nosl = (cals_struct_period_normal_location *)(*row_event)->user_data;
-               retvm_if(NULL == nosl, CAL_ERR_FAIL, "user_data is NULL");
-
-               cnt = 0;
-               nosl->index = sqlite3_column_int(iter->stmt, cnt++);
-               nosl->calendar_id = sqlite3_column_int(iter->stmt, cnt++);
-               nosl->dtstart_type = sqlite3_column_int(iter->stmt, cnt++);
-               nosl->dtstart_utime = sqlite3_column_int64(iter->stmt, cnt++);
-               nosl->dtend_type = sqlite3_column_int(iter->stmt, cnt++);
-               nosl->dtend_utime = sqlite3_column_int64(iter->stmt, cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(nosl->summary), cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(nosl->description), cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(nosl->location), cnt++);
-               nosl->busy_status= sqlite3_column_int(iter->stmt, cnt++);
-               nosl->meeting_status= sqlite3_column_int(iter->stmt, cnt++);
-               nosl->priority= sqlite3_column_int(iter->stmt, cnt++);
-               nosl->sensitivity= sqlite3_column_int(iter->stmt, cnt++);
-               nosl->rrule_id = sqlite3_column_int(iter->stmt, cnt++);
-               nosl->latitude = sqlite3_column_double(iter->stmt, cnt++);
-               nosl->longitude = sqlite3_column_double(iter->stmt, cnt++);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_LOCATION:
-               s_datetime = NULL;
-               e_datetime = NULL;
-               if (NULL == *row_event) {
-                       *row_event = calendar_svc_struct_new(CALS_STRUCT_PERIOD_ALLDAY_LOCATION);
-                       retvm_if(NULL == *row_event, CAL_ERR_FAIL,
-                                       "Failed to new CALS_STRUCT_TYPE_PERIOD_ALLDAY_OSP");
-               }
-               cals_struct_period_allday_location *aosl;
-               aosl = (cals_struct_period_allday_location *)(*row_event)->user_data;
-               retvm_if(NULL == aosl, CAL_ERR_FAIL, "user_data is NULL");
-
-               cnt = 0;
-               aosl->index = sqlite3_column_int(iter->stmt, cnt++);
-               aosl->calendar_id = sqlite3_column_int(iter->stmt, cnt++);
-               aosl->dtstart_type = sqlite3_column_int(iter->stmt, cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(s_datetime),cnt++);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("YYYY") + 1, "%s", &s_datetime[0]);
-               aosl->dtstart_year = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("MM") + 1, "%s", &s_datetime[4]);
-               aosl->dtstart_month = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("DD") + 1, "%s", &s_datetime[6]);
-               aosl->dtstart_mday = atoi(buf);
-
-               aosl->dtend_type = sqlite3_column_int(iter->stmt, cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(e_datetime),cnt++);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("YYYY") + 1, "%s", &e_datetime[0]);
-               aosl->dtend_year = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("MM") + 1, "%s", &e_datetime[4]);
-               aosl->dtend_month = atoi(buf);
-               memset(buf, 0x0, sizeof(buf));
-               snprintf(buf, strlen("DD") + 1, "%s", &e_datetime[6]);
-               aosl->dtend_mday = atoi(buf);
-               cal_db_get_text_from_stmt(iter->stmt,&(aosl->summary), cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(aosl->description), cnt++);
-               cal_db_get_text_from_stmt(iter->stmt,&(aosl->location), cnt++);
-               aosl->busy_status= sqlite3_column_int(iter->stmt, cnt++);
-               aosl->meeting_status= sqlite3_column_int(iter->stmt, cnt++);
-               aosl->priority= sqlite3_column_int(iter->stmt, cnt++);
-               aosl->sensitivity= sqlite3_column_int(iter->stmt, cnt++);
-               aosl->rrule_id = sqlite3_column_int(iter->stmt, cnt++);
-               aosl->latitude = sqlite3_column_double(iter->stmt, cnt++);
-               aosl->longitude = sqlite3_column_double(iter->stmt, cnt++);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_ALARM:
-               if (NULL == *row_event) {
-                       *row_event = calendar_svc_struct_new(CALS_STRUCT_PERIOD_NORMAL_ALARM);
-                       retvm_if(NULL == *row_event, CAL_ERR_FAIL,
-                                       "Failed to new CALS_STRUCT_TYPE_PERIOD_NORMAL_ALARM");
-               }
-               cals_struct_period_normal_alarm *nosa;
-               nosa = (cals_struct_period_normal_alarm *)(*row_event)->user_data;
-               retvm_if(NULL == nosa, CAL_ERR_FAIL, "user_data is NULL");
-
-               cnt = 0;
-               nosa->index = sqlite3_column_int(iter->stmt, cnt++);
-               nosa->calendar_id = sqlite3_column_int(iter->stmt, cnt++);
-               nosa->dtstart_type = sqlite3_column_int(iter->stmt, cnt++);
-               nosa->dtstart_utime = sqlite3_column_int64(iter->stmt, cnt++);
-               nosa->dtend_type = sqlite3_column_int(iter->stmt, cnt++);
-               nosa->dtend_utime = sqlite3_column_int64(iter->stmt, cnt++);
-               nosa->alarm_utime = sqlite3_column_int64(iter->stmt, cnt++);
-               nosa->alarm_id = sqlite3_column_int(iter->stmt, cnt++);
-               break;
-
-       default:
-               break;
-       }
-
-       return CAL_SUCCESS;
-}
-
-
-
-API int calendar_svc_iter_next(cal_iter *iter)
-{
-       int ret = 0;
-
-       retv_if(NULL == iter, CAL_ERR_ARG_NULL);
-
-       if (iter->is_patched == FALSE)
-               iter->is_patched = TRUE;
-
-       if (CAL_STRUCT_TYPE_UPDATED_LIST == iter->i_type) {
-               retv_if(NULL == iter->info, CAL_ERR_ARG_INVALID);
-
-               if (NULL == iter->info->cursor)
-                       iter->info->cursor = iter->info->head;
-               else
-                       iter->info->cursor = iter->info->cursor->next;
-
-               if (NULL == iter->info->cursor || 0 == iter->info->cursor->id) {
-                       iter->info->cursor = NULL;
-                       cals_updated_schedule_free_mempool(iter->info->head);
-                       iter->info->head = NULL;
-                       return CAL_ERR_FINISH_ITER;
-               }
-       }
-       else {
-               ret = cals_stmt_step(iter->stmt);
-               retvm_if(ret < CAL_SUCCESS, ret, "cals_stmt_step() Failed(%d)", ret);
-
-               if (CAL_SUCCESS == ret)
-                       return CAL_ERR_FINISH_ITER;
-       }
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_iter_remove(cal_iter **iter)
-{
-       CALS_FN_CALL;
-       retv_if(NULL == iter, CAL_ERR_ARG_NULL);
-       retv_if(NULL == *iter, CAL_ERR_ARG_NULL);
-
-       if (CAL_STRUCT_TYPE_UPDATED_LIST == (*iter)->i_type) {
-               retv_if(NULL == (*iter)->info, CAL_ERR_ARG_INVALID);
-               if ((*iter)->info->head) {
-                       cals_updated_schedule_free_mempool((*iter)->info->head);
-               }
-               free((*iter)->info);
-
-       } else {
-               if ((*iter)->stmt)
-               {
-                       sqlite3_finalize((*iter)->stmt);
-                       (*iter)->stmt = NULL;
-               }
-       }
-       free(*iter);
-       *iter = NULL;
-
-       return CAL_SUCCESS;
-}
-
-
-API int calendar_svc_iter_get_main_info (cal_iter *iter, cal_struct **row_event)
-{
-       CALS_FN_CALL;
-       int ret;
-       int rc;
-       int error_code = 0;
-       char sql_value[CALS_SQL_MIN_LEN] = {0};
-       calendar_t *cal_record = NULL;
-       cal_sch_full_t *sch_record = NULL;
-       cal_timezone_t *tz_record = NULL;
-       sqlite3_stmt *stmt = NULL;
-
-       retv_if(iter == NULL, CAL_ERR_ARG_NULL);
-       retv_if(iter->stmt == NULL, CAL_ERR_ARG_INVALID);
-       retv_if(NULL == row_event, CAL_ERR_ARG_NULL);
-
-       if(iter->is_patched!=TRUE)
-       {
-               int ret = calendar_svc_iter_next(iter);
-               if(ret == CAL_ERR_FINISH_ITER)
-               {
-                       return CAL_ERR_NO_DATA;
-               }
-               else if(ret != CAL_SUCCESS)
-               {
-                       return ret;
-               }
-       }
-
-       switch(iter->i_type)
-       {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-               if(*row_event == NULL)
-               {
-                       *row_event = calendar_svc_struct_new(CAL_STRUCT_SCHEDULE);
-                       retvm_if(NULL == *row_event, CAL_ERR_OUT_OF_MEMORY, "calendar_svc_struct_new() Failed");
-
-                       (*row_event)->event_type = CAL_STRUCT_TYPE_SCHEDULE;
-               }
-               sch_record = (cal_sch_full_t*)(*row_event)->user_data;
-               retv_if(NULL == sch_record, CAL_ERR_ARG_NULL);
-
-               cals_stmt_get_full_schedule(iter->stmt, sch_record, true);
-
-               if (sch_record->rrule_id > 0) {
-                       snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s WHERE event_id = %d ",
-                                       CALS_TABLE_RRULE, sch_record->index);
-
-                       stmt = cals_query_prepare(sql_value);
-                       retvm_if(NULL == stmt, CAL_ERR_FAIL, "cals_query_prepare() Failed");
-
-                       rc = cals_stmt_step(stmt);
-                       retvm_if(CAL_TRUE != rc, CAL_ERR_FAIL, "cals_stmt_step() Failed(%d)", rc);
-
-
-                       cals_stmt_fill_rrule(stmt, sch_record);
-                       sqlite3_finalize(stmt);
-                       stmt = NULL;
-               }
-
-               cal_db_service_get_participant_info_by_index(sch_record->index,&(sch_record->attendee_list),&error_code);
-               ret = cals_get_alarm_info(sch_record->index, &(sch_record->alarm_list));
-               retvm_if(CAL_SUCCESS != ret, ret, "cals_get_alarm_info() Failed(%d)", ret);
-               break;
-
-       case CAL_STRUCT_TYPE_TODO:
-               if(*row_event == NULL)
-               {
-                       *row_event = calendar_svc_struct_new(CAL_STRUCT_TODO);
-                       retvm_if(NULL == *row_event, CAL_ERR_OUT_OF_MEMORY, "calendar_svc_struct_new() Failed");
-
-                       (*row_event)->event_type = CAL_STRUCT_TYPE_TODO;
-               }
-               sch_record = (cal_sch_full_t*)(*row_event)->user_data;
-               retv_if(NULL == sch_record, CAL_ERR_ARG_NULL);
-
-               cals_stmt_get_full_schedule(iter->stmt, sch_record, true);
-
-               if (sch_record->rrule_id > 0) {
-                       snprintf(sql_value, sizeof(sql_value),
-                                       "SELECT * FROM %s WHERE event_id = %d ",
-                                       CALS_TABLE_RRULE, sch_record->index);
-
-                       stmt = cals_query_prepare(sql_value);
-                       retvm_if(NULL == stmt, CAL_ERR_FAIL, "cals_query_prepare() Failed");
-
-                       rc = cals_stmt_step(stmt);
-                       retvm_if(CAL_TRUE != rc, CAL_ERR_FAIL, "cals_stmt_step() Failed(%d)", rc);
-
-                       cals_stmt_fill_rrule(stmt, sch_record);
-                       sqlite3_finalize(stmt);
-                       stmt = NULL;
-               }
-
-               break;
-
-       case CAL_STRUCT_TYPE_CALENDAR:
-               if(*row_event == NULL)
-               {
-                       *row_event = calendar_svc_struct_new(CAL_STRUCT_CALENDAR);
-                       retvm_if(NULL == *row_event, CAL_ERR_OUT_OF_MEMORY, "calendar_svc_struct_new() Failed");
-
-                       (*row_event)->event_type = CAL_STRUCT_TYPE_CALENDAR;
-               }
-               cal_record = (calendar_t*)(*row_event)->user_data;
-               retv_if(NULL == cal_record, CAL_ERR_FAIL);
-
-               cals_stmt_get_calendar(iter->stmt,cal_record);
-
-               break;
-       case CAL_STRUCT_TYPE_TIMEZONE:
-               if(*row_event == NULL)
-               {
-                       *row_event = calendar_svc_struct_new(CAL_STRUCT_TIMEZONE);
-                       retvm_if(NULL == *row_event, CAL_ERR_OUT_OF_MEMORY, "calendar_svc_struct_new() Failed");
-
-                       (*row_event)->event_type = CAL_STRUCT_TYPE_TIMEZONE;
-               }
-               tz_record = (cal_timezone_t*)(*row_event)->user_data;
-               retv_if(NULL == tz_record, CAL_ERR_FAIL);
-
-               cal_db_service_convert_stmt_to_tz_info(iter->stmt,tz_record);
-
-               break;
-
-       default:
-               break;
-       }
-
-       return CAL_SUCCESS;
-}
diff --git a/src/cals-schedule.c b/src/cals-schedule.c
deleted file mode 100755 (executable)
index 36ab77a..0000000
+++ /dev/null
@@ -1,1767 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <errno.h>
-
-#include "cals-internal.h"
-#include "cals-typedef.h"
-#include "cals-sqlite.h"
-#include "cals-db-info.h"
-#include "cals-db.h"
-#include "cals-utils.h"
-#include "cals-alarm.h"
-#include "cals-schedule.h"
-#include "cals-instance.h"
-#include "cals-time.h"
-
-int _cals_clear_instances(int id);
-
-static inline int _cals_insert_schedule(cal_sch_full_t *record)
-{
-       int ret = -1;
-       char query[CALS_SQL_MAX_LEN] = {0};
-       char dtstart_datetime[32] = {0};
-       char dtend_datetime[32] = {0};
-       sqlite3_stmt *stmt = NULL;
-
-       retv_if(NULL == record, CAL_ERR_ARG_NULL);
-
-       int input_ver = cals_get_next_ver();
-
-       ret = snprintf(query, sizeof(query),
-               "INSERT INTO %s ("
-                       "account_id, type, "
-                       "created_ver, changed_ver, "
-                       "summary, description, location, categories, exdate, "
-                       "missed, "
-                       "task_status, priority, timezone, file_id, "
-                       "contact_id, busy_status, sensitivity, uid, "
-                       "calendar_type, organizer_name, organizer_email, meeting_status, "
-                       "gcal_id, updated, location_type, "
-                       "location_summary, etag, calendar_id, sync_status, "
-                       "edit_uri, gevent_id, dst, original_event_id, "
-                       "latitude, longitude, "
-                       "email_id, availability, "
-                       "created_time, completed_time, progress, "
-                       "dtstart_type, dtstart_utime, dtstart_datetime, dtstart_tzid, "
-                       "dtend_type, dtend_utime, dtend_datetime, dtend_tzid, "
-                       "last_mod, rrule_id "
-                       ") VALUES ( "
-                       "%d, %d, "
-                       "%d, %d, "
-                       "?, ?, ?, ?, ?, "
-                       "%d, "
-                       "%d, %d, %d, %d, "
-                       "%d, %d, %d, ?, "
-                       "%d, ?, ?, %d, "
-                       "?, ?, %d, "
-                       "?, ?, %d, %d, "
-                       "?, ?, %d, %d, "
-                       "%lf, %lf, "
-                       "%d, %d, "
-                       "strftime('%%s', 'now'), %lld, %d, "
-                       "%d, %lld, ?, ?, "
-                       "%d, %lld, ?, ?, "
-                       "strftime('%%s', 'now'), %d ) ",
-                       CALS_TABLE_SCHEDULE,
-                       record->account_id, record->cal_type,
-                       input_ver, input_ver,
-                       record->missed,
-                       record->task_status, record->priority,  record->timezone, record->file_id,
-                       record->contact_id, record->busy_status, record->sensitivity,
-                       record->calendar_type, record->meeting_status,
-                       record->location_type,
-                       record->calendar_id, record->sync_status,
-                       record->dst, record->original_event_id,
-                       record->latitude, record->longitude,
-                       record->email_id, record->availability,
-                       record->completed_time, record->progress,
-                       record->dtstart_type, record->dtstart_utime,
-                       record->dtend_type, record->dtend_utime,
-                       record->rrule_id);
-
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       int count = 1;
-
-       if (record->summary)
-               cals_stmt_bind_text(stmt, count, record->summary);
-       count++;
-
-       if (record->description)
-               cals_stmt_bind_text(stmt, count, record->description);
-       count++;
-
-       if (record->location)
-               cals_stmt_bind_text(stmt, count, record->location);
-       count++;
-
-       if (record->categories)
-               cals_stmt_bind_text(stmt, count, record->categories);
-       count++;
-
-       if (record->exdate)
-               cals_stmt_bind_text(stmt, count, record->exdate);
-       count++;
-
-       if (record->uid)
-               cals_stmt_bind_text(stmt, count, record->uid);
-       count++;
-
-       if (record->organizer_name)
-               cals_stmt_bind_text(stmt, count, record->organizer_name);
-       count++;
-
-       if (record->organizer_email)
-               cals_stmt_bind_text(stmt, count, record->organizer_email);
-       count++;
-
-       if (record->gcal_id)
-               cals_stmt_bind_text(stmt, count, record->gcal_id);
-       count++;
-
-       if (record->updated)
-               cals_stmt_bind_text(stmt, count, record->updated);
-       count++;
-
-       if (record->location_summary)
-               cals_stmt_bind_text(stmt, count, record->location_summary);
-       count++;
-
-       if (record->etag)
-               cals_stmt_bind_text(stmt, count, record->etag);
-       count++;
-
-       if (record->edit_uri)
-               cals_stmt_bind_text(stmt, count, record->edit_uri);
-       count++;
-
-       if (record->gevent_id)
-               cals_stmt_bind_text(stmt, count, record->gevent_id);
-       count++;
-
-       snprintf(dtstart_datetime, sizeof(dtstart_datetime), "%04d%02d%02dT000000",
-                       record->dtstart_year, record->dtstart_month, record->dtstart_mday);
-       cals_stmt_bind_text(stmt, count, dtstart_datetime);
-       count++;
-
-       if (record->dtstart_tzid)
-               cals_stmt_bind_text(stmt, count, record->dtstart_tzid);
-       count++;
-
-       snprintf(dtend_datetime, sizeof(dtend_datetime), "%04d%02d%02dT235959",
-                       record->dtend_year, record->dtend_month, record->dtend_mday);
-       cals_stmt_bind_text(stmt, count, dtend_datetime);
-       count++;
-
-       if (record->dtend_tzid)
-               cals_stmt_bind_text(stmt, count, record->dtend_tzid);
-       count++;
-
-       ret = cals_stmt_step(stmt);
-       if (CAL_SUCCESS != ret) {
-               sqlite3_finalize(stmt);
-               ERR("sqlite3_step() Failed(%d)", ret);
-               return ret;
-       }
-       sqlite3_finalize(stmt);
-
-       return cals_last_insert_id();
-}
-
-static inline int _cals_insert_rrule_id(int index, cal_sch_full_t *record)
-{
-       CALS_FN_CALL;
-       int ret = -1;
-       char query[CALS_SQL_MAX_LEN] = {0};
-
-       retv_if(NULL == record, CAL_ERR_ARG_NULL);
-
-       ret = snprintf(query, sizeof(query),
-                       "UPDATE %s SET "
-                       "rrule_id = %d "
-                       "WHERE id = %d ",
-                       CALS_TABLE_SCHEDULE,
-                       record->rrule_id,
-                       index);
-DBG("query(%s)", query);
-       ret = cals_query_exec(query);
-       if (ret) {
-               ERR("cals_query_exec() failed (%d)", ret);
-               return ret;
-       }
-       return CAL_SUCCESS;
-}
-
-static inline int _cals_insert_rrule(int index, cal_sch_full_t *record)
-{
-       int ret;
-       int cnt;
-       char query[CALS_SQL_MAX_LEN] = {0};
-       char until_datetime[32] = {0};
-       sqlite3_stmt *stmt = NULL;
-
-       snprintf(query, sizeof(query),
-                       "INSERT INTO %s ( "
-                       "event_id, freq, range_type, "
-                       "until_type, until_utime, until_datetime, "
-                       "count, interval, "
-                       "bysecond, byminute, byhour, byday, "
-                       "bymonthday, byyearday, byweekno, bymonth, "
-                       "bysetpos, wkst "
-                       ") VALUES ( "
-                       "%d, %d, %d, "
-                       "%d, %lld, ?, "
-                       "%d, %d, "
-                       "?, ?, ?, ?, "
-                       "?, ?, ?, ?, "
-                       "?, %d "
-                       ") ",
-                       CALS_TABLE_RRULE,
-                       index, record->freq, record->range_type,
-                       record->until_type, record->until_utime,
-                       record->count, record->interval,
-                       record->wkst);
-
-       stmt = cals_query_prepare(query);
-       retvm_if(stmt == NULL, CAL_ERR_DB_FAILED, "Failed to query prepare");
-
-       cnt = 1;
-       snprintf(until_datetime, sizeof(until_datetime), "%04d%02d%02dT235959",
-                       record->until_year, record->until_month, record->until_mday);
-       cals_stmt_bind_text(stmt, cnt, until_datetime);
-       cnt++;
-
-       if (record->bysecond)
-               cals_stmt_bind_text(stmt, cnt, record->bysecond);
-       cnt++;
-
-       if (record->byminute)
-               cals_stmt_bind_text(stmt, cnt, record->byminute);
-       cnt++;
-
-       if (record->byhour)
-               cals_stmt_bind_text(stmt, cnt, record->byhour);
-       cnt++;
-
-       if (record->byday)
-               cals_stmt_bind_text(stmt, cnt, record->byday);
-       cnt++;
-
-       if (record->bymonthday)
-               cals_stmt_bind_text(stmt, cnt, record->bymonthday);
-       cnt++;
-
-       if (record->byyearday)
-               cals_stmt_bind_text(stmt, cnt, record->byyearday);
-       cnt++;
-
-       if (record->byweekno)
-               cals_stmt_bind_text(stmt, cnt, record->byweekno);
-       cnt++;
-
-       if (record->bymonth)
-               cals_stmt_bind_text(stmt, cnt, record->bymonth);
-       cnt++;
-
-       if (record->bysetpos)
-               cals_stmt_bind_text(stmt, cnt, record->bysetpos);
-       cnt++;
-
-       ret = cals_stmt_step(stmt);
-       if (CAL_SUCCESS != ret) {
-               sqlite3_finalize(stmt);
-               ERR("sqlite3_step() Failed(%d)", ret);
-               return ret;
-       }
-       sqlite3_finalize(stmt);
-
-       return cals_last_insert_id();
-}
-
-int cals_insert_schedule(cal_sch_full_t *sch_record)
-{
-       int ret = 0;
-       int index = 0;
-       cal_value *cvalue = NULL;
-       bool is_success = false;
-       struct cals_time st;
-       struct cals_time et;
-
-       retvm_if(NULL == sch_record, CAL_ERR_ARG_INVALID, "sch_record is NULL");
-
-       sch_record->missed = 0;
-
-       ret = cals_begin_trans();
-       retvm_if(ret, ret, "cals_begin_trans() is Failed(%d)", ret);
-
-       ret = _cals_insert_schedule(sch_record);
-       if(ret < CAL_SUCCESS) {
-               ERR("_cals_insert_schedule() Failed(%d)", ret);
-               cals_end_trans(false);
-               return ret;
-       }
-       index = ret;
-
-       if (sch_record->freq != CALS_FREQ_ONCE) {
-               ret = _cals_insert_rrule(index, sch_record);
-               if (ret < CAL_SUCCESS) {
-                       ERR("Failed in _cals_insert_rrule(%d)\n", ret);
-                       cals_end_trans(false);
-                       return ret;
-               }
-               sch_record->rrule_id = ret;
-               DBG("added rrule_id(%d)", ret);
-               ret = _cals_insert_rrule_id(index, sch_record);
-               if (ret != CAL_SUCCESS) {
-                       ERR("Failed in _cals_insert_rrule_id(%d)\n", ret);
-               }
-               DBG("ended add");
-       }
-
-       st.type = sch_record->dtstart_type;
-       if (st.type == CALS_TIME_UTIME)
-               st.utime = sch_record->dtstart_utime;
-       else {
-               st.year = sch_record->dtstart_year;
-               st.month = sch_record->dtstart_month;
-               st.mday = sch_record->dtstart_mday;
-       }
-
-       et.type = sch_record->dtend_type;
-       if (et.type == CALS_TIME_UTIME)
-               et.utime = sch_record->dtend_utime;
-       else {
-               et.year = sch_record->dtend_year;
-               et.month = sch_record->dtend_month;
-               et.mday = sch_record->dtend_mday;
-       }
-
-       cals_instance_insert(index, &st, &et, 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;
-
-               while(list)
-               {
-                       cvalue = list->data;
-                       if(cvalue)
-                       {
-                               participant_info = cvalue->user_data;
-                               if(participant_info->is_deleted==0)
-                               {
-                                       ret = cal_service_add_participant_info(index, participant_info);
-                                       warn_if(ret, "cal_service_add_participant_info() Failed(%d)", ret);
-                               }
-                       }
-                       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 == 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)
-                       {
-                               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)
-                               {
-                                       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);
-       sch_record->index = index;
-
-       if(sch_record->cal_type == CALS_SCH_TYPE_EVENT)
-               is_success= cals_notify(CALS_NOTI_TYPE_EVENT);
-       else
-               is_success= cals_notify(CALS_NOTI_TYPE_TODO);
-       warn_if(is_success != CAL_SUCCESS, "cals_notify() Failed");
-
-       return index;
-}
-
-static int _cals_delete_participant_info(const int index)
-{
-       int ret;
-       char query[CALS_SQL_MIN_LEN];
-
-       sprintf(query, "DELETE FROM %s WHERE event_id = %d", CALS_TABLE_PARTICIPANT, index);
-
-       ret = cals_query_exec(query);
-       retvm_if(CAL_SUCCESS != ret, ret, "cals_query_exec() Failed(%d)", ret);
-
-       return CAL_SUCCESS;
-}
-
-
-static inline int _cals_update_schedule(const int index, cal_sch_full_t *current_record)
-{
-       int ret = -1;
-       char query[CALS_SQL_MAX_LEN] = {0};
-       char dtstart_datetime[32] = {0};
-       char dtend_datetime[32] = {0};
-       sqlite3_stmt *stmt = NULL;
-
-       retv_if(NULL == current_record, CAL_ERR_ARG_NULL);
-
-       if (CAL_SYNC_STATUS_UPDATED != current_record->sync_status)
-               current_record->sync_status = CAL_SYNC_STATUS_UPDATED;
-
-       snprintf(query, sizeof(query), "UPDATE %s SET "
-                       "changed_ver = %d,"
-                       "type = %d,"
-                       "summary = ?,"
-                       "description = ?,"
-                       "location = ?,"
-                       "categories = ?,"
-                       "exdate = ?,"
-                       "missed = %d,"
-                       "task_status = %d,"
-                       "priority = %d,"
-                       "timezone = %d, "
-                       "file_id = %d, "
-                       "contact_id = %d, "
-                       "busy_status = %d, "
-                       "sensitivity = %d, "
-                       "uid = ?, "
-                       "calendar_type = %d, "
-                       "organizer_name = ?, "
-                       "organizer_email = ?, "
-                       "meeting_status = %d, "
-                       "gcal_id = ?, "
-                       "updated = ?, "
-                       "location_type = %d, "
-                       "location_summary = ?, "
-                       "etag = ?, "
-                       "calendar_id = %d, "
-                       "sync_status = %d, "
-                       "edit_uri = ?, "
-                       "gevent_id = ?, "
-                       "dst = %d,"
-                       "original_event_id = %d,"
-                       "latitude = %lf,"
-                       "longitude = %lf,"
-                       "email_id = %d,"
-                       "availability = %d,"
-                       "completed_time = %lld,"
-                       "progress = %d, "
-                       "dtstart_type = %d, "
-                       "dtstart_utime = %lld, "
-                       "dtstart_datetime = ?, "
-                       "dtstart_tzid = ?, "
-                       "dtend_type = %d, "
-                       "dtend_utime = %lld, "
-                       "dtend_datetime = ?, "
-                       "dtend_tzid = ?, "
-                       "last_mod = strftime('%%s', 'now')"
-                       "WHERE id = %d;",
-               CALS_TABLE_SCHEDULE,
-               cals_get_next_ver(),
-               current_record->cal_type,
-               current_record->missed,
-               current_record->task_status,
-               current_record->priority,
-               current_record->timezone,
-               current_record->file_id,
-               current_record->contact_id,
-               current_record->busy_status,
-               current_record->sensitivity,
-               current_record->calendar_type,
-               current_record->meeting_status,
-               current_record->location_type,
-               current_record->calendar_id,
-               current_record->sync_status,
-               current_record->dst,
-               current_record->original_event_id,
-               current_record->latitude,
-               current_record->longitude,
-               current_record->email_id,
-               current_record->availability,
-               current_record->completed_time,
-               current_record->progress,
-               current_record->dtstart_type,
-               current_record->dtstart_utime,
-               current_record->dtend_type,
-               current_record->dtend_utime,
-               index);
-
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       int count = 1;
-
-       if (current_record->summary)
-               cals_stmt_bind_text(stmt, count, current_record->summary);
-       count++;
-
-       if (current_record->description)
-               cals_stmt_bind_text(stmt, count, current_record->description);
-       count++;
-
-       if (current_record->location)
-               cals_stmt_bind_text(stmt, count, current_record->location);
-       count++;
-
-       if (current_record->categories)
-               cals_stmt_bind_text(stmt, count, current_record->categories);
-       count++;
-
-       if (current_record->exdate)
-               cals_stmt_bind_text(stmt, count, current_record->exdate);
-       count++;
-
-       if (current_record->uid)
-               cals_stmt_bind_text(stmt, count, current_record->uid);
-       count++;
-
-       if (current_record->organizer_name)
-               cals_stmt_bind_text(stmt, count, current_record->organizer_name);
-       count++;
-
-       if (current_record->organizer_email)
-               cals_stmt_bind_text(stmt, count, current_record->organizer_email);
-       count++;
-
-       if (current_record->gcal_id)
-               cals_stmt_bind_text(stmt, count, current_record->gcal_id);
-       count++;
-
-       if (current_record->updated)
-               cals_stmt_bind_text(stmt, count, current_record->updated);
-       count++;
-
-       if (current_record->location_summary)
-               cals_stmt_bind_text(stmt, count, current_record->location_summary);
-       count++;
-
-       if (current_record->etag)
-               cals_stmt_bind_text(stmt, count, current_record->etag);
-       count++;
-
-       if (current_record->edit_uri)
-               cals_stmt_bind_text(stmt, count, current_record->edit_uri);
-       count++;
-
-       if (current_record->gevent_id)
-               cals_stmt_bind_text(stmt, count, current_record->gevent_id);
-       count++;
-
-       snprintf(dtstart_datetime, sizeof(dtstart_datetime), "%04d%02d%02d",
-                       current_record->dtstart_year,
-                       current_record->dtstart_month,
-                       current_record->dtstart_mday);
-       cals_stmt_bind_text(stmt, count, dtstart_datetime);
-       count++;
-
-       if (current_record->dtstart_tzid)
-               cals_stmt_bind_text(stmt, count, current_record->dtstart_tzid);
-       count++;
-
-       snprintf(dtend_datetime, sizeof(dtend_datetime), "%04d%02d%02d",
-                       current_record->dtend_year,
-                       current_record->dtend_month,
-                       current_record->dtend_mday);
-       cals_stmt_bind_text(stmt, count, dtend_datetime);
-       count++;
-
-       if (current_record->dtend_tzid)
-               cals_stmt_bind_text(stmt, count, current_record->dtend_tzid);
-       count++;
-
-       ret = cals_stmt_step(stmt);
-       if (CAL_SUCCESS != ret) {
-               sqlite3_finalize(stmt);
-               ERR("sqlite3_step() Failed(%d)", ret);
-               return ret;
-       }
-       sqlite3_finalize(stmt);
-
-       return CAL_SUCCESS;
-}
-
-static inline int _cals_update_rrule(const int index, cal_sch_full_t *record)
-{
-       int ret;
-       int cnt;
-       char query[CALS_SQL_MAX_LEN] = {0};
-       char until_datetime[32] = {0};
-       sqlite3_stmt *stmt = NULL;
-
-       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, "
-                       "until_datetime = ?, "
-                       "count = %d, "
-                       "interval = %d, "
-                       "bysecond = ?, "
-                       "byminute = ?, "
-                       "byhour = ?, "
-                       "byday = ?, "
-                       "bymonthday = ?, "
-                       "byyearday = ?, "
-                       "byweekno = ?, "
-                       "bymonth = ?, "
-                       "bysetpos = ?, "
-                       "wkst = %d "
-                       "WHERE event_id = %d",
-                       CALS_TABLE_RRULE,
-                       record->freq,
-                       record->range_type,
-                       record->until_type,
-                       record->until_utime,
-                       record->count,
-                       record->interval,
-                       record->wkst,
-                       index);
-       stmt = cals_query_prepare(query);
-       retvm_if(stmt == NULL, CAL_ERR_DB_FAILED, "Failed query prepare");
-
-       cnt = 1;
-       snprintf(until_datetime, sizeof(until_datetime), "%04d%02d%02dT235959",
-                       record->until_year, record->until_month, record->until_mday);
-       cals_stmt_bind_text(stmt, cnt, until_datetime);
-       cnt++;
-
-       if (record->bysecond)
-               cals_stmt_bind_text(stmt, cnt, record->bysecond);
-       cnt++;
-
-       if (record->byminute)
-               cals_stmt_bind_text(stmt, cnt, record->byminute);
-       cnt++;
-
-       if (record->byhour)
-               cals_stmt_bind_text(stmt, cnt, record->byhour);
-       cnt++;
-
-       if (record->byday)
-               cals_stmt_bind_text(stmt, cnt, record->byday);
-       cnt++;
-
-       if (record->bymonthday)
-               cals_stmt_bind_text(stmt, cnt, record->bymonthday);
-       cnt++;
-
-       if (record->byyearday)
-               cals_stmt_bind_text(stmt, cnt, record->byyearday);
-       cnt++;
-
-       if (record->byweekno)
-               cals_stmt_bind_text(stmt, cnt, record->byweekno);
-       cnt++;
-
-       if (record->bymonth)
-               cals_stmt_bind_text(stmt, cnt, record->bymonth);
-       cnt++;
-
-       if (record->bysetpos)
-               cals_stmt_bind_text(stmt, cnt, record->bysetpos);
-       cnt++;
-
-       ret = cals_stmt_step(stmt);
-       if (CAL_SUCCESS != ret) {
-               sqlite3_finalize(stmt);
-               ERR("sqlite3_step() Failed(%d)", ret);
-               return ret;
-       }
-       sqlite3_finalize(stmt);
-
-       return CAL_SUCCESS;
-}
-
-int _cals_get_rrule_id(int index, int *rrule_id)
-{
-       int r;
-       sqlite3_stmt *stmt;
-       char query[CALS_SQL_MAX_LEN] = {0};
-
-       snprintf(query, sizeof(query),
-                       "SELECT rrule_id "
-                       "FROM %s "
-                       "WHERE id = %d ",
-                       CALS_TABLE_SCHEDULE,
-                       index);
-       stmt = cals_query_prepare(query);
-       if (!stmt) {
-               ERR("cals_query_prepare failed");
-               return CAL_ERR_DB_FAILED;
-       }
-
-       r = cals_stmt_step(stmt);
-       if (r < 0) {
-               sqlite3_finalize(stmt);
-               ERR("cals_stmt_step failed (%d)", r);
-               return r;
-       }
-
-       if (r == CAL_SUCCESS) {
-               ERR("cals_stmt_step return no data");
-               sqlite3_finalize(stmt);
-               return CAL_ERR_NO_DATA;
-       }
-
-       *rrule_id = sqlite3_column_int(stmt, 0);
-       sqlite3_finalize(stmt);
-       return CAL_SUCCESS;
-}
-
-int cals_update_schedule(const int index, cal_sch_full_t *sch_record)
-{
-       bool is_success = false;
-       cal_value * cvalue = NULL;
-       int ret = 0;
-       int rrule_id = 0;
-
-       retv_if(NULL == sch_record, CAL_ERR_ARG_NULL);
-
-       sch_record->missed = 0;
-
-       ret = _cals_update_schedule(index, sch_record);
-       retvm_if(CAL_SUCCESS != ret, ret, "_cals_update_schedule() Failed(%d)", ret);
-
-       if (sch_record->freq != CALS_FREQ_ONCE) {
-               ret = _cals_get_rrule_id(index, &rrule_id);
-
-               if (rrule_id > 0) {
-                       ret = _cals_update_rrule(index, sch_record);
-                       retvm_if(CAL_SUCCESS != ret, ret, "Failed in update rrule(%d)", ret);
-
-               } else {
-                       ret = _cals_insert_rrule(index, sch_record);
-                       if (ret < CAL_SUCCESS) {
-                               ERR("Failed in _cals_insert_rrule(%d)\n", ret);
-                               return ret;
-                       }
-                       sch_record->rrule_id = ret;
-                       DBG("added rrule_id(%d)", ret);
-                       ret = _cals_insert_rrule_id(index, sch_record);
-                       if (ret != CAL_SUCCESS) {
-                               ERR("Failed in _cals_insert_rrule_id(%d)\n", ret);
-                       }
-                       DBG("ended add");
-               }
-       }
-
-       _cals_delete_participant_info(index);
-       if (sch_record->attendee_list)
-       {
-               GList *list = g_list_first(sch_record->attendee_list);
-               cal_participant_info_t* participant_info = NULL;
-
-               while(list)
-               {
-                       cvalue = (cal_value *)list->data;
-                       participant_info = (cal_participant_info_t*)cvalue->user_data;
-
-                       if (0 == participant_info->is_deleted) {
-                               ret = cal_service_add_participant_info(index, participant_info);
-                               warn_if(ret, "cal_service_add_participant_info() Failed(%d)", ret);
-                       }
-
-                       list = g_list_next(list);
-               }
-       }
-
-       /* delete registered alarm */
-       cals_alarm_remove(CALS_ALARM_REMOVE_BY_EVENT_ID, index);
-       if (sch_record->alarm_list)
-       {
-               GList *list = sch_record->alarm_list;
-               cal_alarm_info_t *alarm_info = NULL;
-               struct cals_time dtstart;
-
-               while (list)
-               {
-                       cvalue = (cal_value *)list->data;
-                       alarm_info = (cal_alarm_info_t*)cvalue->user_data;
-
-                       if (alarm_info->is_deleted==0) {
-                               if (alarm_info->remind_tick != CALS_INVALID_ID) {
-                                       dtstart.type = sch_record->dtstart_type;
-                                       dtstart.utime = sch_record->dtstart_utime;
-                                       dtstart.year = sch_record->dtstart_year;
-                                       dtstart.month = sch_record->dtstart_month;
-                                       dtstart.mday = sch_record->dtstart_mday;
-                                       ret = cals_alarm_add(index, alarm_info, &dtstart);
-                                       warn_if(CAL_SUCCESS != ret, "cals_alarm_add() Failed(%d)", ret);
-                               }
-                       }
-
-                       list = g_list_next(list);
-               }
-       }
-
-       /* TODO: re register alarm */
-
-       /* clear instance */
-       ret = _cals_clear_instances(index);
-       if (ret) {
-               ERR("_cals_clear_instances failed (%d)", ret);
-               return ret;
-       }
-
-       /* insert instance */
-       struct cals_time st;
-       struct cals_time et;
-
-       st.type = sch_record->dtstart_type;
-       if (st.type == CALS_TIME_UTIME)
-               st.utime = sch_record->dtstart_utime;
-       else {
-               st.year = sch_record->dtstart_year;
-               st.month = sch_record->dtstart_month;
-               st.mday = sch_record->dtstart_mday;
-       }
-
-       et.type = sch_record->dtend_type;
-       if (et.type == CALS_TIME_UTIME)
-               et.utime = sch_record->dtend_utime;
-       else {
-               et.year = sch_record->dtend_year;
-               et.month = sch_record->dtend_month;
-               et.mday = sch_record->dtend_mday;
-       }
-
-       cals_instance_insert(index, &st, &et, sch_record);
-
-       /* set notify */
-       if(sch_record->cal_type == CALS_SCH_TYPE_EVENT)
-               is_success= cals_notify(CALS_NOTI_TYPE_EVENT);
-       else
-               is_success= cals_notify(CALS_NOTI_TYPE_TODO);
-
-       return CAL_SUCCESS;
-}
-
-int _get_sch_basic_info(int id, int *cal_id, int *sch_type, int *acc_id)
-{
-       int r;
-       sqlite3_stmt *stmt;
-       char query[CALS_SQL_MAX_LEN];
-
-       snprintf(query, sizeof(query), "SELECT calendar_id, type, "
-                       "account_id FROM %s WHERE id = %d",
-                       CALS_TABLE_SCHEDULE, id);
-
-       stmt = cals_query_prepare(query);
-
-       if (!stmt) {
-               ERR("cals_query_prepare failed");
-               return CAL_ERR_DB_FAILED;
-       }
-
-       r = cals_stmt_step(stmt);
-
-       if (r < 0) {
-               sqlite3_finalize(stmt);
-               ERR("cals_stmt_step failed (%d)", r);
-               return r;
-       }
-
-       if (r == CAL_SUCCESS) {
-               ERR("cals_stmt_step return no data");
-               sqlite3_finalize(stmt);
-               return CAL_ERR_NO_DATA;
-       }
-
-       *cal_id = sqlite3_column_int(stmt, 0);
-       *sch_type = sqlite3_column_int(stmt, 1);
-       *acc_id = sqlite3_column_int(stmt, 2);
-
-       sqlite3_finalize(stmt);
-
-       return CAL_SUCCESS;
-}
-
-int _cals_update_deleted_table(int id)
-{
-       int r;
-       char query[CALS_SQL_MAX_LEN];
-
-       snprintf(query, sizeof(query), "INSERT INTO %s "
-                               "SELECT id, type, calendar_id, %d FROM %s "
-                               "WHERE id = %d",
-                               CALS_TABLE_DELETED,
-                               cals_get_next_ver(), CALS_TABLE_SCHEDULE,
-                               id);
-
-       r = cals_query_exec(query);
-       if (r) {
-               ERR("cals_query_exec() failed (%d)", r);
-               return r;
-       }
-       return CAL_SUCCESS;
-}
-
-int _cals_delete_schedule(int id)
-{
-       int r;
-       char query[CALS_SQL_MAX_LEN];
-
-       snprintf(query, sizeof(query), "DELETE FROM %s WHERE id = %d",
-                       CALS_TABLE_SCHEDULE, id);
-
-       r = cals_query_exec(query);
-       if (r) {
-               ERR("cals_query_exec() failed (%d)", r);
-               return r;
-       }
-       return CAL_SUCCESS;
-}
-
-int _cals_clear_instances(int id)
-{
-       int r;
-       char query[CALS_SQL_MAX_LEN];
-
-       snprintf(query, sizeof(query), "DELETE FROM %s WHERE event_id = %d ",
-                       CALS_TABLE_NORMAL_INSTANCE, id);
-
-       r = cals_query_exec(query);
-       if (r) {
-               ERR("cals_query_exec() failed (%d)", r);
-               return r;
-       }
-
-       snprintf(query, sizeof(query), "DELETE FROM %s WHERE event_id = %d ",
-                       CALS_TABLE_ALLDAY_INSTANCE, id);
-
-       r = cals_query_exec(query);
-       if (r) {
-               ERR("cals_query_exec() failed (%d)", r);
-               return r;
-       }
-
-       return CAL_SUCCESS;
-}
-
-int _cals_delete_rrule(int id)
-{
-       int r;
-       char query[CALS_SQL_MAX_LEN];
-
-       snprintf(query, sizeof(query), "DELETE FROM %s WHERE event_id = %d",
-                       CALS_TABLE_RRULE, id);
-
-       r = cals_query_exec(query);
-       if (r) {
-               ERR("cals_query_exec() failed (%d)", r);
-               return r;
-       }
-
-       return CAL_SUCCESS;
-}
-
-int _cals_mark_delete_schedule(int id)
-{
-       int r;
-       char query[CALS_SQL_MAX_LEN];
-
-       snprintf(query, sizeof(query), "UPDATE %s "
-                       "SET is_deleted = 1, changed_ver = %d, "
-                       "last_mod = strftime('%%s','now') WHERE id = %d",
-                       CALS_TABLE_SCHEDULE, cals_get_next_ver(), id);
-
-       r = cals_query_exec(query);
-       if (r) {
-               ERR("cals_query_exec() failed (%d)", r);
-               return r;
-       }
-
-       return CAL_SUCCESS;
-}
-
-int cals_delete_schedule(int id)
-{
-       int r;
-       int cal_id;
-       int sch_type;
-       int acc_id;
-
-       r = _get_sch_basic_info(id, &cal_id, &sch_type, &acc_id);
-       if (r) {
-               ERR("_get_sch_basic_info failed (%d)", r);
-               return r;
-       }
-
-       if (acc_id == LOCAL_ACCOUNT_ID) {
-               _cals_update_deleted_table(id);
-               if (r) {
-                       ERR("_cals_update_deleted_table failed (%d)", r);
-                       return r;
-               }
-               r = _cals_delete_schedule(id);
-               if (r) {
-                       ERR("_cals_delete_schedule failed (%d)", r);
-                       return r;
-               }
-               _cals_delete_participant_info(id);
-               if (r) {
-                       ERR("_cals_delete_participant_info failed (%d)", r);
-                       return r;
-               }
-               _cals_delete_rrule(id);
-               if (r) {
-                       ERR("_cals_delete_rrule failed (%d)", r);
-                       return r;
-               }
-       }
-       else {
-               r = _cals_mark_delete_schedule(id);
-               if (r) {
-                       ERR("_cals_mark_delete_schedule failed (%d)", r);
-                       return r;
-               }
-       }
-
-       r = _cals_clear_instances(id);
-       if (r) {
-               ERR("_cals_clear_instances failed (%d)", r);
-               return r;
-       }
-
-       r = cals_alarm_remove(CALS_ALARM_REMOVE_BY_EVENT_ID, id);
-       if (r) {
-               ERR("cals_alarm_remove() failed(%d)", r);
-               return r;
-       }
-
-       if(sch_type == CALS_SCH_TYPE_EVENT)
-               r = cals_notify(CALS_NOTI_TYPE_EVENT);
-       else
-               r = cals_notify(CALS_NOTI_TYPE_TODO);
-
-       if (r)
-               WARN("cals_notify failed (%d)", r);
-
-       return CAL_SUCCESS;
-}
-
-int cals_rearrange_schedule_field(const char *src, char *dest, int dest_size)
-{
-       int ret = 0;
-       if (strstr(src, CAL_VALUE_INT_INDEX))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_INDEX);
-
-       if (strstr(src,CAL_VALUE_INT_ACCOUNT_ID))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_ACCOUNT_ID);
-
-       if (strstr(src,CAL_VALUE_INT_TYPE))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_TYPE);
-
-       if (strstr(src,CAL_VALUE_TXT_SUMMARY))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_TXT_SUMMARY);
-
-       if (strstr(src,CAL_VALUE_TXT_DESCRIPTION))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_TXT_DESCRIPTION);
-
-       if (strstr(src,CAL_VALUE_TXT_LOCATION))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_TXT_LOCATION);
-
-       if (strstr(src, CAL_VALUE_TXT_CATEGORIES))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_TXT_CATEGORIES);
-
-       if(strstr(src,CAL_VALUE_INT_MISSED))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_MISSED);
-
-       if(strstr(src,CAL_VALUE_INT_TASK_STATUS))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_TASK_STATUS);
-
-       if(strstr(src,CAL_VALUE_INT_PRIORITY))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_PRIORITY);
-
-       if(strstr(src,CAL_VALUE_INT_TIMEZONE))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_TIMEZONE);
-
-       if(strstr(src,CAL_VALUE_INT_FILE_ID))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_FILE_ID);
-
-       if(strstr(src,CAL_VALUE_INT_CONTACT_ID))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_CONTACT_ID);
-
-       if(strstr(src,CAL_VALUE_INT_BUSY_STATUS))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_BUSY_STATUS);
-
-       if(strstr(src,CAL_VALUE_INT_SENSITIVITY))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_SENSITIVITY);
-
-       if(strstr(src,CAL_VALUE_TXT_UID))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_TXT_UID);
-
-       if(strstr(src,CAL_VALUE_INT_CALENDAR_TYPE))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_CALENDAR_TYPE);
-
-       if(strstr(src,CAL_VALUE_TXT_ORGANIZER_NAME))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_TXT_ORGANIZER_NAME);
-
-       if(strstr(src,CAL_VALUE_TXT_ORGANIZER_EMAIL))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_TXT_ORGANIZER_EMAIL);
-
-       if(strstr(src, CAL_VALUE_INT_MEETING_STATUS))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_MEETING_STATUS);
-
-       if(strstr(src,CAL_VALUE_TXT_GCAL_ID))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_TXT_GCAL_ID);
-
-       if(strstr(src,CAL_VALUE_INT_DELETED))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_DELETED);
-
-       if(strstr(src,CAL_VALUE_TXT_UPDATED))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_TXT_UPDATED);
-
-       if(strstr(src,CAL_VALUE_INT_LOCATION_TYPE))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_LOCATION_TYPE);
-
-       if(strstr(src,CAL_VALUE_TXT_LOCATION_SUMMARY))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_TXT_LOCATION_SUMMARY);
-
-       if(strstr(src,CAL_VALUE_TXT_ETAG))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_TXT_ETAG);
-
-       if(strstr(src,CAL_VALUE_INT_CALENDAR_ID))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_CALENDAR_ID);
-
-       if(strstr(src,CAL_VALUE_INT_SYNC_STATUS))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_SYNC_STATUS);
-
-       if(strstr(src,CAL_VALUE_TXT_EDIT_URL))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_TXT_EDIT_URL);
-
-       if(strstr(src,CAL_VALUE_TXT_GEDERID))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_TXT_GEDERID);
-
-       if(strstr(src,CAL_VALUE_INT_DST))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_DST);
-
-       if(strstr(src,CAL_VALUE_INT_ORIGINAL_EVENT_ID))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_ORIGINAL_EVENT_ID);
-
-       if(strstr(src,CAL_VALUE_DBL_LATITUDE))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_DBL_LATITUDE);
-
-       if(strstr(src,CAL_VALUE_DBL_LONGITUDE))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_DBL_LONGITUDE);
-
-       if(strstr(src,CAL_VALUE_INT_EMAIL_ID))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_EMAIL_ID);
-
-       if(strstr(src,CAL_VALUE_INT_AVAILABILITY))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_AVAILABILITY);
-
-       if(strstr(src,CAL_VALUE_LLI_CREATED_TIME))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_LLI_CREATED_TIME);
-
-       if(strstr(src,CAL_VALUE_LLI_COMPLETED_TIME))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_LLI_COMPLETED_TIME);
-
-       if(strstr(src,CAL_VALUE_INT_PROGRESS))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_PROGRESS);
-
-       if(strstr(src,CAL_VALUE_INT_IS_DELETED))
-               ret += snprintf(dest+ret, dest_size-ret, ",%s", CAL_VALUE_INT_IS_DELETED);
-
-       return CAL_SUCCESS;
-}
-
-int cals_stmt_get_filted_schedule(sqlite3_stmt *stmt,
-               cal_sch_full_t *sch_record, const char *select_field)
-{
-       int count = 0;
-       const unsigned char *temp;
-       const char *start, *result;
-
-       retv_if(NULL == stmt, CAL_ERR_ARG_NULL);
-       retv_if(NULL == sch_record, CAL_ERR_ARG_NULL);
-       retv_if(NULL == select_field, CAL_ERR_ARG_NULL);
-
-       start = select_field;
-       if((result = strstr(start, CAL_VALUE_INT_INDEX))) {
-               sch_record->index = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_ACCOUNT_ID))) {
-               sch_record->account_id = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_TYPE))) {
-               sch_record->cal_type = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_TXT_SUMMARY))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->summary = SAFE_STRDUP(temp);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_TXT_DESCRIPTION))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->description = SAFE_STRDUP(temp);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_TXT_LOCATION))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->location = SAFE_STRDUP(temp);
-               start = result;
-       }
-
-       if((result = strstr(start, CAL_VALUE_TXT_CATEGORIES))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->categories = SAFE_STRDUP(temp);
-               start = result;
-       }
-
-       if((result = strstr(start, CAL_VALUE_TXT_EXDATE))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->exdate = SAFE_STRDUP(temp);
-               start = result;
-       }
-       if((result = strstr(start,CAL_VALUE_INT_MISSED))) {
-               sch_record->missed = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_TASK_STATUS))) {
-               sch_record->task_status = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_PRIORITY))) {
-               sch_record->priority = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_TIMEZONE))) {
-               sch_record->timezone = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_FILE_ID))) {
-               sch_record->file_id = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_CONTACT_ID))) {
-               sch_record->contact_id = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_BUSY_STATUS))) {
-               sch_record->busy_status = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_SENSITIVITY))) {
-               sch_record->sensitivity = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_TXT_UID))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->uid = SAFE_STRDUP(temp);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_CALENDAR_TYPE))) {
-               sch_record->calendar_type = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_CALENDAR_TYPE))) {
-               sch_record->calendar_type = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_TXT_ORGANIZER_NAME))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->organizer_name = SAFE_STRDUP(temp);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_TXT_ORGANIZER_EMAIL))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->organizer_email = SAFE_STRDUP(temp);
-               start = result;
-       }
-
-       if((result = strstr(start, CAL_VALUE_INT_MEETING_STATUS))) {
-               sch_record->meeting_status = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_TXT_GCAL_ID))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->gcal_id = SAFE_STRDUP(temp);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_TXT_UPDATED))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->updated = SAFE_STRDUP(temp);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_LOCATION_TYPE))) {
-               sch_record->location_type = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_TXT_LOCATION_SUMMARY))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->location_summary = SAFE_STRDUP(temp);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_TXT_ETAG))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->etag = SAFE_STRDUP(temp);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_CALENDAR_ID))) {
-               sch_record->calendar_id = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_SYNC_STATUS))) {
-               sch_record->sync_status = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_TXT_EDIT_URL))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->edit_uri = SAFE_STRDUP(temp);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_TXT_GEDERID))) {
-               temp = sqlite3_column_text(stmt, count++);
-               sch_record->gevent_id = SAFE_STRDUP(temp);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_DST))) {
-               sch_record->dst = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_ORIGINAL_EVENT_ID))) {
-               sch_record->original_event_id = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_DBL_LATITUDE))) {
-               sch_record->latitude = sqlite3_column_double(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_DBL_LONGITUDE))) {
-               sch_record->longitude = sqlite3_column_double(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_EMAIL_ID))) {
-               sch_record->email_id = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_AVAILABILITY))) {
-               sch_record->availability = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_LLI_CREATED_TIME))) {
-               sch_record->created_time = sqlite3_column_int64(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_LLI_COMPLETED_TIME))) {
-               sch_record->completed_time = sqlite3_column_int64(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_PROGRESS))) {
-               sch_record->progress = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       if((result = strstr(start,CAL_VALUE_INT_IS_DELETED))) {
-               sch_record->is_deleted = sqlite3_column_int(stmt, count++);
-               start = result;
-       }
-
-       return CAL_SUCCESS;
-}
-
-
-void cals_stmt_get_full_schedule(sqlite3_stmt *stmt,cal_sch_full_t *sch_record, bool is_utc)
-{
-       int count = 0;
-       char *dtstart_datetime;
-       char *dtend_datetime;
-       char buf[8] = {0};
-       const unsigned char *temp;
-
-       sch_record->index = sqlite3_column_int(stmt, count++);
-       sch_record->account_id = sqlite3_column_int(stmt, count++);
-       sch_record->cal_type = sqlite3_column_int(stmt, count++);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->summary = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->description = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->location = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->categories = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->exdate = SAFE_STRDUP(temp);
-
-       sch_record->missed = sqlite3_column_int(stmt, count++);
-       sch_record->task_status = sqlite3_column_int(stmt, count++);
-       sch_record->priority = sqlite3_column_int(stmt, count++);
-       sch_record->timezone = sqlite3_column_int(stmt, count++);
-       sch_record->file_id = sqlite3_column_int(stmt, count++);
-       sch_record->contact_id = sqlite3_column_int(stmt, count++);
-       sch_record->busy_status = sqlite3_column_int(stmt, count++);
-       sch_record->sensitivity = sqlite3_column_int(stmt, count++);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->uid = SAFE_STRDUP(temp);
-
-       sch_record->calendar_type = sqlite3_column_int(stmt, count++);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->organizer_name = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->organizer_email = SAFE_STRDUP(temp);
-
-       sch_record->meeting_status = sqlite3_column_int(stmt, count++);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->gcal_id = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->updated = SAFE_STRDUP(temp);
-
-       sch_record->location_type = sqlite3_column_int(stmt, count++);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->location_summary = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->etag = SAFE_STRDUP(temp);
-
-       sch_record->calendar_id = sqlite3_column_int(stmt, count++);
-
-       sch_record->sync_status = sqlite3_column_int(stmt, count++);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->edit_uri = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->gevent_id = SAFE_STRDUP(temp);
-
-       sch_record->dst = sqlite3_column_int(stmt, count++);
-
-       sch_record->original_event_id = sqlite3_column_int(stmt, count++);
-
-       sch_record->latitude = sqlite3_column_double(stmt,count++);
-       sch_record->longitude = sqlite3_column_double(stmt,count++);
-
-       sch_record->email_id = sqlite3_column_int(stmt, count++);
-
-       sch_record->availability = sqlite3_column_int(stmt, count++);
-
-       sch_record->created_time = sqlite3_column_int64(stmt, count++);
-
-       sch_record->completed_time = sqlite3_column_int64(stmt, count++);
-
-       sch_record->progress = sqlite3_column_int(stmt,count++);
-
-
-       sqlite3_column_int(stmt,count++);
-       sqlite3_column_int(stmt,count++);
-       sch_record->is_deleted = sqlite3_column_int(stmt,count++);
-
-       sch_record->dtstart_type = sqlite3_column_int(stmt,count++);
-       sch_record->dtstart_utime = sqlite3_column_int64(stmt,count++);
-       temp = sqlite3_column_text(stmt, count++);
-       if (temp) {
-               dtstart_datetime = SAFE_STRDUP(temp);
-               snprintf(buf, strlen("YYYY") + 1, "%s", &dtstart_datetime[0]);
-               sch_record->dtstart_year =  atoi(buf);
-               snprintf(buf, strlen("MM") + 1, "%s", &dtstart_datetime[4]);
-               sch_record->dtstart_month = atoi(buf);
-               snprintf(buf, strlen("DD") + 1, "%s", &dtstart_datetime[6]);
-               sch_record->dtstart_mday = atoi(buf);
-               if (dtstart_datetime) free(dtstart_datetime);
-       }
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->dtstart_tzid = SAFE_STRDUP(temp);
-
-       sch_record->dtend_type = sqlite3_column_int(stmt, count++);
-       sch_record->dtend_utime = sqlite3_column_int64(stmt, count++);
-       temp = sqlite3_column_text(stmt, count++);
-       if (temp) {
-               dtend_datetime = SAFE_STRDUP(temp);
-               snprintf(buf, strlen("YYYY") + 1, "%s", &dtend_datetime[0]);
-               sch_record->dtend_year =  atoi(buf);
-               snprintf(buf, strlen("MM") + 1, "%s", &dtend_datetime[4]);
-               sch_record->dtend_month = atoi(buf);
-               snprintf(buf, strlen("DD") + 1, "%s", &dtend_datetime[6]);
-               sch_record->dtend_mday = atoi(buf);
-               if (dtend_datetime) free(dtend_datetime);
-       }
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->dtend_tzid = SAFE_STRDUP(temp);
-
-       sch_record->last_mod = sqlite3_column_int64(stmt,count++);
-       sch_record->rrule_id = sqlite3_column_int(stmt,count++);
-}
-
-void cals_stmt_fill_rrule(sqlite3_stmt *stmt,cal_sch_full_t *sch_record)
-{
-       char *until_datetime;
-       char buf[8] = {0};
-       const unsigned char *temp;
-       int count = 0;
-
-       sch_record->rrule_id = sqlite3_column_int(stmt,count++);
-       sqlite3_column_int(stmt,count++); // event_id
-       sch_record->freq = sqlite3_column_int(stmt,count++);
-       sch_record->range_type = sqlite3_column_int(stmt,count++);
-       sch_record->until_type = sqlite3_column_int(stmt,count++);
-       sch_record->until_utime = sqlite3_column_int64(stmt, count++);
-
-       temp = sqlite3_column_text(stmt, count++);
-       if (temp) {
-               until_datetime = SAFE_STRDUP(temp);
-               snprintf(buf, strlen("YYYY") + 1, "%s", &until_datetime[0]);
-               sch_record->until_year =  atoi(buf);
-               snprintf(buf, strlen("MM") + 1, "%s", &until_datetime[4]);
-               sch_record->until_month = atoi(buf);
-               snprintf(buf, strlen("DD") + 1, "%s", &until_datetime[6]);
-               sch_record->until_mday = atoi(buf);
-               if (until_datetime) free(until_datetime);
-       }
-
-       sch_record->count = sqlite3_column_int(stmt,count++);
-       sch_record->interval = sqlite3_column_int(stmt,count++);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->bysecond = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->byminute = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->byhour = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->byday = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->bymonthday = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->byyearday = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->byweekno = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->bymonth = SAFE_STRDUP(temp);
-
-       temp = sqlite3_column_text(stmt, count++);
-       sch_record->bysetpos = SAFE_STRDUP(temp);
-
-       sch_record->wkst = sqlite3_column_int(stmt,count++);
-}
-
-inline char *cals_strcat(char * const dest, const char *src, int bufsize)
-{
-       return strncat(dest, src, bufsize - strlen(dest) -1);
-}
-
-void _cals_sch_search_get_cond(int fields, char * const buf, int bufsize)
-{
-       int first;
-
-       first = 1;
-
-       if (fields & CALS_SEARCH_FIELD_SUMMARY) {
-               if (first)
-                       first = 0;
-               else
-                       cals_strcat(buf, "OR ", bufsize);
-               cals_strcat(buf, "A.summary LIKE ('%%' || :key || '%%') ", bufsize);
-       }
-
-       if (fields & CALS_SEARCH_FIELD_DESCRIPTION) {
-               if (first)
-                       first = 0;
-               else
-                       cals_strcat(buf, "OR ", bufsize);
-               cals_strcat(buf, "A.description LIKE ('%%' || :key || '%%') ", bufsize);
-       }
-
-       if (fields & CALS_SEARCH_FIELD_LOCATION) {
-               if (first)
-                       first = 0;
-               else
-                       cals_strcat(buf, "OR ", bufsize);
-               cals_strcat(buf, "A.location LIKE ('%%' || :key || '%%') ", bufsize);
-       }
-
-       if (fields & CALS_SEARCH_FIELD_ATTENDEE) {
-               if (first)
-                       first = 0;
-               else
-                       cals_strcat(buf, "OR ", bufsize);
-               cals_strcat(buf, "B.attendee_name LIKE ('%%' || :key || '%%') ", bufsize);
-       }
-
-       return;
-}
-
-int cals_sch_search(cals_sch_type sch_type, int fields, const char *keyword, cal_iter **iter)
-{
-       cal_iter *it;
-       sqlite3_stmt *stmt;
-       char query[CALS_SQL_MAX_LEN] = {0};
-       char cond[CALS_SQL_MIN_LEN] = {0};
-
-       _cals_sch_search_get_cond(fields, cond, sizeof(cond));
-       snprintf(query, sizeof(query), "SELECT A.* "
-                       "FROM %s A LEFT JOIN %s B ON A.id = B.event_id "
-                       "JOIN %s C ON A.calendar_id = C.ROWID "
-                       "WHERE A.type = %d AND (%s) AND C.visibility = 1",
-                       CALS_TABLE_SCHEDULE, CALS_TABLE_PARTICIPANT, CALS_TABLE_CALENDAR, sch_type, cond);
-       DBG("QUERY [%s]", query);
-
-       stmt = cals_query_prepare(query);
-       retvm_if (!stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() failed");
-
-       sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":key"), keyword, strlen(keyword), SQLITE_TRANSIENT);
-
-       it = calloc(1, sizeof(cal_iter));
-       if (!it) {
-               sqlite3_finalize(stmt);
-               ERR("calloc() failed(%d)", errno);
-               return CAL_ERR_OUT_OF_MEMORY;
-       }
-
-       it->i_type = CAL_STRUCT_TYPE_SCHEDULE;
-       it->stmt = stmt;
-       *iter = it;
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_smartsearch_excl(const char *keyword, int offset, int limit, cal_iter **iter)
-{
-       cal_iter *it;
-       sqlite3_stmt *stmt;
-       char query[CALS_SQL_MAX_LEN] = {0};
-       char buf[1024] = {0};
-
-       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",
-                       CALS_TABLE_SCHEDULE, CALS_TABLE_CALENDAR, limit, offset);
-
-       stmt = cals_query_prepare(query);
-       retvm_if (!stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() failed");
-
-       cals_escape_like_pattern(keyword, buf, sizeof(buf));
-       sqlite3_bind_text(stmt, sqlite3_bind_parameter_index(stmt, ":key"), buf, strlen(buf), SQLITE_TRANSIENT);
-
-       it = calloc(1, sizeof(cal_iter));
-       if (!it) {
-               sqlite3_finalize(stmt);
-               ERR("calloc() failed(%d)", errno);
-               return CAL_ERR_OUT_OF_MEMORY;
-       }
-
-       it->i_type = CAL_STRUCT_TYPE_SCHEDULE;
-       it->stmt = stmt;
-       *iter = it;
-
-       return CAL_SUCCESS;
-}
-
diff --git a/src/cals-schedule.h b/src/cals-schedule.h
deleted file mode 100755 (executable)
index 4f5b20d..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __CALENDAR_SVC_SCHEDULE_H__
-#define __CALENDAR_SVC_SCHEDULE_H__
-
-/**
- *  This function add full field of calendar info to DB.
- *
- * @return             This function returns true on success, or false on failure.
- * @param[in]  sch_record              Points of the full field information for schedule table' s record.
- * @exception  CAL_ERR_DB_FAILED, CAL_ERR_ARG_INVALID, CAL_ERR_DB_NOT_OPENED,
- *                             CAL_ERR_DB_RECORD_NOT_FOUND, CAL_ERR_DB_FAILED
- */
-int cals_insert_schedule(cal_sch_full_t *sch_record);
-int cals_update_schedule(const int index, cal_sch_full_t *sch_record);
-int cals_delete_schedule(const int index);
-int cals_sch_search(cals_sch_type sch_type, int fields, const char *keyword, cal_iter **iter);
-
-int cals_rearrange_schedule_field(const char *src, char *dest, int dest_size);
-
-int cals_stmt_get_filted_schedule(sqlite3_stmt *stmt,cal_sch_full_t *sch_record, const char *select_field);
-void cals_stmt_get_full_schedule(sqlite3_stmt *stmt,cal_sch_full_t *sch_record, bool is_utc);
-void cals_stmt_fill_rrule(sqlite3_stmt *stmt,cal_sch_full_t *sch_record);
-
-#endif /* __CALENDAR_SVC_SCHEDULE_H__ */
-
-
diff --git a/src/cals-sqlite.c b/src/cals-sqlite.c
deleted file mode 100755 (executable)
index 0936c07..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <db-util.h>
-
-#include "cals-internal.h"
-#include "cals-typedef.h"
-#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)
-{
-       int ret;
-
-       if (!calendar_db_handle) {
-               ret = db_util_open(CALS_DB_PATH, &calendar_db_handle, 0);
-               retvm_if(SQLITE_OK != ret, CAL_ERR_DB_NOT_OPENED,
-                               "db_util_open() Failed(%d).", ret);
-       }
-       return CAL_SUCCESS;
-}
-
-int cals_db_close(void)
-{
-       int ret = 0;
-
-       if (calendar_db_handle) {
-               ret = db_util_close(calendar_db_handle);
-               warn_if(SQLITE_OK != ret, "db_util_close() Failed(%d)", ret);
-               calendar_db_handle = NULL;
-               CALS_DBG("The database disconnected really.");
-       }
-
-       return CAL_SUCCESS;
-}
-
-int cals_last_insert_id(void)
-{
-       return sqlite3_last_insert_rowid(calendar_db_handle);
-}
-
-int cals_query_get_first_int_result(const char *query)
-{
-       int ret;
-       sqlite3_stmt *stmt = NULL;
-       retvm_if(NULL == calendar_db_handle, CAL_ERR_DB_NOT_OPENED, "Database is not opended");
-
-       ret = sqlite3_prepare_v2(calendar_db_handle, query, strlen(query), &stmt, NULL);
-       retvm_if(SQLITE_OK != ret, CAL_ERR_DB_FAILED,
-                       "sqlite3_prepare_v2(%s) failed(%s).", query, sqlite3_errmsg(calendar_db_handle));
-
-       ret = sqlite3_step(stmt);
-       if (SQLITE_ROW != ret) {
-               ERR("sqlite3_step() failed(%d, %s).", ret, sqlite3_errmsg(calendar_db_handle));
-               sqlite3_finalize(stmt);
-               if (SQLITE_DONE == ret) return CAL_ERR_DB_RECORD_NOT_FOUND;
-               return CAL_ERR_DB_FAILED;
-       }
-
-       ret = sqlite3_column_int(stmt, 0);
-       sqlite3_finalize(stmt);
-
-       return ret;
-}
-
-
-int cals_query_exec(char *query)
-{
-       int ret;
-       char *err_msg = NULL;
-
-       retvm_if(NULL == calendar_db_handle, CAL_ERR_DB_NOT_OPENED, "Database is not opended");
-       //CALS_DBG("query : %s", query);
-
-       ret = sqlite3_exec(calendar_db_handle, query, NULL, NULL, &err_msg);
-       if (SQLITE_OK != ret) {
-               ERR("sqlite3_exec(%s) failed(%d, %s).", query, ret, err_msg);
-               sqlite3_free(err_msg);
-               switch (ret) {
-               case SQLITE_BUSY:
-               case SQLITE_LOCKED:
-                       return CAL_ERR_DB_LOCK;
-               case SQLITE_IOERR:
-                       return CAL_ERR_IO_ERR;
-               case SQLITE_FULL:
-                       return CAL_ERR_NO_SPACE;
-               default:
-                       return CAL_ERR_DB_FAILED;
-               }
-       }
-
-       return CAL_SUCCESS;
-}
-
-sqlite3_stmt* cals_query_prepare(char *query)
-{
-       int ret = -1;
-       sqlite3_stmt *stmt = NULL;
-
-       retvm_if(NULL == query, NULL, "Invalid query");
-       retvm_if(NULL == calendar_db_handle, NULL, "Database is not opended");
-       //CALS_DBG("prepare query : %s", query);
-
-       ret = sqlite3_prepare_v2(calendar_db_handle, query, strlen(query), &stmt, NULL);
-       retvm_if(SQLITE_OK != ret, NULL,
-                       "sqlite3_prepare_v2(%s) Failed(%s).", query, sqlite3_errmsg(calendar_db_handle));
-
-       return stmt;
-}
-
-int cals_stmt_step(sqlite3_stmt *stmt)
-{
-       int ret;
-       ret = sqlite3_step(stmt);
-       switch (ret) {
-       case SQLITE_BUSY:
-       case SQLITE_LOCKED:
-               ret = CAL_ERR_DB_LOCK;
-               break;
-       case SQLITE_IOERR:
-               ret = CAL_ERR_IO_ERR;
-               break;
-       case SQLITE_FULL:
-               ret = CAL_ERR_NO_SPACE;
-               break;
-       case SQLITE_CONSTRAINT:
-               ret = CAL_ERR_ALREADY_EXIST;
-               break;
-       case SQLITE_ROW:
-               ret = CAL_TRUE;
-               break;
-       case SQLITE_DONE:
-               ret = CAL_SUCCESS;
-               break;
-       default:
-               ERR("sqlite3_step() Failed(%d)", ret);
-               ret = CAL_ERR_DB_FAILED;
-               break;
-       }
-       return ret;
-}
-
-int cals_escape_like_pattern(const char *src, char * const dest, int dest_size)
-{
-       int s_pos=0, d_pos=0;
-
-       if (NULL == src) {
-               ERR("The parameter(src) is NULL");
-               dest[d_pos] = '\0';
-               return 0;
-       }
-
-       while (src[s_pos] != 0) {
-               if (dest_size -1 == d_pos) {
-                       break;
-               }
-               if ('%' == src[s_pos] || '_' == src[s_pos]) {
-                       dest[d_pos++] = '\\';
-               }
-               dest[d_pos++] = src[s_pos++];
-       }
-
-       dest[d_pos] = '\0';
-       return d_pos;
-}
-
-
diff --git a/src/cals-sqlite.h b/src/cals-sqlite.h
deleted file mode 100755 (executable)
index c99e882..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __CALENDAR_SVC_SQLITE_H__
-#define __CALENDAR_SVC_SQLITE_H__
-
-#include <sqlite3.h>
-
-#define CALS_SQL_MAX_LEN 2048
-#define CALS_SQL_MIN_LEN 1024
-
-int cals_db_open(void);
-int cals_db_close(void);
-
-int cals_last_insert_id(void);
-
-int cals_query_get_first_int_result(const char *query);
-int cals_query_exec(char *query);
-
-sqlite3_stmt* cals_query_prepare(char *query);
-int cals_stmt_step(sqlite3_stmt *stmt);
-
-static inline int cals_stmt_bind_text(sqlite3_stmt *stmt, int pos, const char *str) {
-       return sqlite3_bind_text(stmt, pos, str, strlen(str), SQLITE_STATIC);
-}
-
-int cals_escape_like_pattern(const char *src, char *dest, int dest_size);
-
-#endif /* __CALENDAR_SVC_SQLITE_H__ */
diff --git a/src/cals-struct.c b/src/cals-struct.c
deleted file mode 100755 (executable)
index c57ddd1..0000000
+++ /dev/null
@@ -1,3066 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#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)
-{
-       calendar->index = -1;
-       calendar->visibility = true;
-       calendar->account_id = LOCAL_ACCOUNT_ID;
-}
-
-API cal_struct* calendar_svc_struct_new(const char *event_type)
-{
-       int ret, type;
-       void *user_data;
-       cal_struct *temp;
-
-       retvm_if(NULL == event_type, NULL, "event_type is NULL");
-
-       if(0 == strcmp(event_type, CAL_STRUCT_SCHEDULE)) {
-               type = CAL_STRUCT_TYPE_SCHEDULE;
-
-               user_data = (cal_sch_full_t*)malloc(sizeof(cal_sch_full_t));
-               retvm_if(NULL == user_data, NULL, "malloc(cal_sch_full_t:sch) Failed(%d)", errno);
-
-               ret = cals_event_init(user_data);
-               if(ret) {
-                       free(user_data);
-                       ERR("cals_event_init() Failed(%d)", ret);
-                       return NULL;
-               }
-
-       } else if (0 == strcmp(event_type, CAL_STRUCT_TODO)) {
-               type = CAL_STRUCT_TYPE_TODO;
-
-               user_data = (cal_sch_full_t*)calloc(1, sizeof(cal_sch_full_t));
-               retvm_if(NULL == user_data, NULL, "calloc(cal_sch_full_t:todo) Failed(%d)", errno);
-
-               ret = cals_todo_init(user_data);
-               if(ret) {
-                       free(user_data);
-                       ERR("cals_todo_init() Failed(%d)", ret);
-                       return NULL;
-               }
-
-       } else if (0 == strcmp(event_type, CAL_STRUCT_CALENDAR)) {
-               type = CAL_STRUCT_TYPE_CALENDAR;
-
-               user_data = calloc(1, sizeof(calendar_t));
-               retvm_if(NULL == user_data, NULL, "calloc(calendar_t) Failed(%d)", errno);
-
-               cals_init_calendar_record(user_data);
-       } else if (0 == strcmp(event_type, CAL_STRUCT_TIMEZONE))        {
-               type = CAL_STRUCT_TYPE_TIMEZONE;
-
-               user_data = (cal_timezone_t*)calloc(1, sizeof(cal_timezone_t));
-               retvm_if(NULL == user_data, NULL, "calloc(cal_timezone_t) Failed(%d)", errno);
-       } else if(0 == strcmp(event_type, CAL_STRUCT_UPDATED)) {
-               type = CAL_STRUCT_TYPE_UPDATED_LIST;
-
-               user_data = (cals_updated*)calloc(1, sizeof(cals_updated));
-               retvm_if(NULL == user_data, NULL, "calloc(cals_updated) Failed(%d)", errno);
-       } else if(0 == strcmp(event_type, CALS_STRUCT_PERIOD_NORMAL_ONOFF)) {
-               type = CALS_STRUCT_TYPE_PERIOD_NORMAL_ONOFF;;
-               user_data = (cals_struct_period_normal_onoff*)calloc(1,
-                               sizeof(cals_struct_period_normal_onoff));
-               retvm_if(NULL == user_data, NULL,
-                               "Failed to calloc PERIOD_NORMAL_ONOFF(%d)", errno);
-
-       } else if(0 == strcmp(event_type, CALS_STRUCT_PERIOD_ALLDAY_ONOFF)) {
-               type = CALS_STRUCT_TYPE_PERIOD_ALLDAY_ONOFF;;
-               user_data = (cals_struct_period_allday_onoff*)calloc(1,
-                               sizeof(cals_struct_period_allday_onoff));
-               retvm_if(NULL == user_data, NULL,
-                               "Failed to calloc PERIOD_ALLDAY_ONOFF(%d)", errno);
-
-       } else if(0 == strcmp(event_type, CALS_STRUCT_PERIOD_NORMAL_BASIC)) {
-               type = CALS_STRUCT_TYPE_PERIOD_NORMAL_BASIC;
-               user_data = (cals_struct_period_normal_basic*)calloc(1,
-                               sizeof(cals_struct_period_normal_basic));
-               retvm_if(NULL == user_data, NULL,
-                               "Failed to calloc CAL_STRUCT_PERIOD_NORMAL_BASIC(%d)", errno);
-
-       } else if(0 == strcmp(event_type, CALS_STRUCT_PERIOD_ALLDAY_BASIC)) {
-               type = CALS_STRUCT_TYPE_PERIOD_ALLDAY_BASIC;
-               user_data = (cals_struct_period_allday_basic*)calloc(1,
-                               sizeof(cals_struct_period_allday_basic));
-               retvm_if(NULL == user_data, NULL,
-                               "Failed to calloc CAL_STRUCT_PERIOD_ALLDAY_BASIC(%d)", errno);
-
-       } else if(0 == strcmp(event_type, CALS_STRUCT_PERIOD_NORMAL_OSP)) {
-               type = CALS_STRUCT_TYPE_PERIOD_NORMAL_OSP;
-               user_data = (cals_struct_period_normal_osp*)calloc(1,
-                               sizeof(cals_struct_period_normal_osp));
-               retvm_if(NULL == user_data, NULL,
-                               "Failed to calloc CAL_STRUCT_PERIOD_NORMAL_BASIC(%d)", errno);
-
-       } else if(0 == strcmp(event_type, CALS_STRUCT_PERIOD_ALLDAY_OSP)) {
-               type = CALS_STRUCT_TYPE_PERIOD_ALLDAY_OSP;
-               user_data = (cals_struct_period_allday_osp*)calloc(1,
-                               sizeof(cals_struct_period_allday_osp));
-               retvm_if(NULL == user_data, NULL,
-                               "Failed to calloc CAL_STRUCT_PERIOD_ALLDAY_BASIC(%d)", errno);
-
-       } else if(0 == strcmp(event_type, CALS_STRUCT_PERIOD_NORMAL_LOCATION)) {
-               type = CALS_STRUCT_TYPE_PERIOD_NORMAL_LOCATION;
-               user_data = (cals_struct_period_normal_location*)calloc(1,
-                               sizeof(cals_struct_period_normal_location));
-               retvm_if(NULL == user_data, NULL,
-                               "Failed to calloc CAL_STRUCT_PERIOD_NORMAL_LOCATION(%d)", errno);
-
-       } else if(0 == strcmp(event_type, CALS_STRUCT_PERIOD_ALLDAY_LOCATION)) {
-               type = CALS_STRUCT_TYPE_PERIOD_ALLDAY_LOCATION;
-               user_data = (cals_struct_period_allday_location*)calloc(1,
-                               sizeof(cals_struct_period_allday_location));
-               retvm_if(NULL == user_data, NULL,
-                               "Failed to calloc CAL_STRUCT_PERIOD_ALLDAY_BASIC(%d)", errno);
-
-       } else if(0 == strcmp(event_type, CALS_STRUCT_PERIOD_NORMAL_ALARM)) {
-               type = CALS_STRUCT_TYPE_PERIOD_NORMAL_ALARM;
-               user_data = (cals_struct_period_normal_alarm*)calloc(1,
-                               sizeof(cals_struct_period_normal_alarm));
-               retvm_if(NULL == user_data, NULL,
-                               "Failed to calloc CAL_STRUCT_PERIOD_NORMAL_ALARM(%d)", errno);
-
-       } else {
-               ERR("Unknown type(%s)", event_type);
-               return NULL;
-       }
-
-       temp = (cal_struct*)calloc(1, sizeof(cal_struct));
-       if(NULL == temp) {
-               free(user_data);
-               ERR("calloc(cal_struct) Failed(%d)", errno);
-               return NULL;
-       }
-       temp->event_type = type;
-       temp->user_data = user_data;
-
-       return temp;
-}
-
-//API to free the calendar struct
-static inline void cals_free_calendar_record(calendar_t *calendar)
-{
-       retm_if(calendar == NULL, "calendar is NULL");
-
-       free(calendar->calendar_id);
-       free(calendar->uid);
-       free(calendar->link);
-       free(calendar->name);
-       free(calendar->description);
-       free(calendar->author);
-       free(calendar->color);
-       free(calendar->location);
-       free(calendar->timezone_label);
-       free(calendar->user_location);
-       free(calendar->weather);
-
-       free(calendar);
-}
-
-static inline void cals_free_timezone_record(cal_timezone_t *tz_info)
-{
-       retm_if(NULL == tz_info, "tz_info is NULL");
-
-       free(tz_info->standard_name);
-       free(tz_info->day_light_name);
-
-       free(tz_info);
-}
-
-API int calendar_svc_struct_free (cal_struct** event)
-{
-       int ret = 0;
-
-       retvm_if(NULL == event || NULL == *event, CAL_ERR_ARG_INVALID, "Invalid parameter");
-
-       switch((*event)->event_type)
-       {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-       case CAL_STRUCT_TYPE_TODO:
-#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;
-       case CAL_STRUCT_TYPE_CALENDAR:
-               cals_free_calendar_record((calendar_t*)(*event)->user_data);
-               CAL_FREE(*event);
-               break;
-       case CAL_STRUCT_TYPE_TIMEZONE:
-               cals_free_timezone_record((cal_timezone_t*)(*event)->user_data);
-               CAL_FREE(*event);
-               break;
-       case CAL_STRUCT_TYPE_UPDATED_LIST:
-               CAL_FREE((*event)->user_data);
-               CAL_FREE(*event);
-               break;
-       default:
-               ERR("Unknown type(%d)", (*event)->event_type);
-               break;
-       }
-
-       return CAL_SUCCESS;
-}
-
-API char * calendar_svc_struct_get_str (cal_struct *event,const char *field)
-{
-       //CALS_FN_CALL();
-       retvm_if(NULL == event || NULL == event->user_data || NULL == field,
-                       NULL,"Invalid parameters.");
-
-       cal_sch_full_t * sch_rec = NULL;
-       calendar_t * cal_rec = NULL;
-       cal_timezone_t *tz_rec = NULL;
-       cals_struct_period_normal_basic *nbs = NULL;
-       cals_struct_period_allday_basic *abs = NULL;
-       cals_struct_period_normal_osp *nosp = NULL;
-       cals_struct_period_allday_osp *aosp = NULL;
-       cals_struct_period_normal_location *nosl = NULL;
-       cals_struct_period_allday_location *aosl = NULL;
-
-       switch(event->event_type)
-       {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-       case CAL_STRUCT_TYPE_TODO:
-               sch_rec = (cal_sch_full_t*)event->user_data;
-               if(0 == strcmp(field,CAL_VALUE_TXT_SUMMARY))
-               {
-                       return (sch_rec->summary);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_DESCRIPTION))
-               {
-                       return (sch_rec->description);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_LOCATION))
-               {
-                       return (sch_rec->location);
-               }
-               else if(0 == strcmp(field, CAL_VALUE_TXT_CATEGORIES))
-               {
-                       return (sch_rec->categories);
-               }
-               else if(0 == strcmp(field, CAL_VALUE_TXT_EXDATE))
-               {
-                       return (sch_rec->exdate);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_UID))
-               {
-                       return (sch_rec->uid);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ORGANIZER_NAME))
-               {
-                       return (sch_rec->organizer_name);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ORGANIZER_EMAIL))
-               {
-                       return (sch_rec->organizer_email);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_GCAL_ID))
-               {
-                       return (sch_rec->gcal_id);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_UPDATED))
-               {
-                       return (sch_rec->updated);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_LOCATION_SUMMARY))
-               {
-                       return (sch_rec->location_summary);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ETAG))
-               {
-                       return (sch_rec->etag);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_EDIT_URL))
-               {
-                       return (sch_rec->edit_uri);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_GEDERID))
-               {
-                       return (sch_rec->gevent_id);
-               }
-               else if(0 == strcmp(field, CALS_VALUE_TXT_DTSTART_TZID))
-                       return (sch_rec->dtstart_tzid);
-               else if(0 == strcmp(field, CALS_VALUE_TXT_DTEND_TZID))
-                       return (sch_rec->dtend_tzid);
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYSECOND))
-                       return (sch_rec->bysecond);
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYMINUTE))
-                       return (sch_rec->byminute);
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYHOUR))
-                       return (sch_rec->byhour);
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYDAY))
-                       return (sch_rec->byday);
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYMONTHDAY))
-                       return (sch_rec->bymonthday);
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYYEARDAY))
-                       return (sch_rec->byyearday);
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYWEEKNO))
-                       return (sch_rec->byweekno);
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYMONTH))
-                       return (sch_rec->bymonth);
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYSETPOS))
-                       return (sch_rec->bysetpos);
-               else
-               {
-                       ERR("Can not find the field(%s)!", field);
-                       return NULL;
-               }
-               break;
-
-       case CAL_STRUCT_TYPE_CALENDAR:
-               cal_rec = (calendar_t*)event->user_data;
-               if(0 == strcmp(field,CAL_TABLE_TXT_CALENDAR_ID))
-               {
-                       return(cal_rec->calendar_id);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_UID))
-               {
-                       return(cal_rec->uid);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_LINK))
-               {
-                       return(cal_rec->link);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_NAME))
-               {
-                       return(cal_rec->name);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_DESCRIPTION))
-               {
-                       return(cal_rec->description);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_AUTHOR))
-               {
-                       return(cal_rec->author);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_COLOR))
-               {
-                       return(cal_rec->color);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_LOCATION))
-               {
-                       return(cal_rec->location);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_TIME_ZONE_LABEL))
-               {
-                       return(cal_rec->timezone_label);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_USER_LOCATION))
-               {
-                       return(cal_rec->user_location);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_WEATHER))
-               {
-                       return(cal_rec->weather);
-               }
-               else
-               {
-                       ERR("Can not find the field!(%s)",field);
-                       return NULL;
-               }
-
-               break;
-       case CAL_STRUCT_TYPE_TIMEZONE:
-               tz_rec = (cal_timezone_t*)event->user_data;
-               if(0 == strcmp(field,CAL_TZ_VALUE_TXT_STD_NAME))
-               {
-                       return(tz_rec->standard_name);
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_TXT_DST_NAME))
-               {
-                       return(tz_rec->day_light_name);
-               }else {
-                       ERR("Can not find the field!(%s)",field);
-                       return NULL;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_ONOFF:
-               ERR("No field in CALS_LIST_PERIOD_NORMAL_ONOFF");
-               return NULL;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_ONOFF:
-               ERR("No field in CALS_LIST_PERIOD_ALLDAY_ONOFF");
-               return NULL;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_BASIC:
-               nbs = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_TXT_SUMMARY))
-                       return nbs->summary;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_TXT_LOCATION))
-                       return nbs->location;
-               else {
-                       ERR("Can not find the field!(%s)",field);
-                       return NULL;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_BASIC:
-               abs = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_TXT_SUMMARY))
-                       return abs->summary;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_TXT_LOCATION))
-                       return abs->location;
-               else {
-                       ERR("Can not find the field!(%s)", field);
-                       return NULL;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_OSP:
-               nosp = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_TXT_SUMMARY))
-                       return nosp->summary;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_TXT_LOCATION))
-                       return nosp->location;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_TXT_DESCRIPTION))
-                       return nosp->description;
-               else {
-                       ERR("Can not find the field!(%s)", field);
-                       return NULL;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_OSP:
-               aosp = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_TXT_SUMMARY))
-                       return aosp->summary;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_TXT_LOCATION))
-                       return aosp->location;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_TXT_DESCRIPTION))
-                       return aosp->description;
-               else {
-                       ERR("Can not find the field!(%s)", field);
-                       return NULL;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_LOCATION:
-               nosl = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_TXT_SUMMARY))
-                       return nosl->summary;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_TXT_LOCATION))
-                       return nosl->location;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_TXT_DESCRIPTION))
-                       return nosl->description;
-               else {
-                       ERR("Can not find the field!(%s)", field);
-                       return NULL;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_LOCATION:
-               aosl = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_TXT_SUMMARY))
-                       return aosl->summary;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_TXT_LOCATION))
-                       return aosl->location;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_TXT_DESCRIPTION))
-                       return aosl->description;
-               else {
-                       ERR("Can not find the field!(%s)", field);
-                       return NULL;
-               }
-               break;
-
-       default:
-               ERR("Can not find the field!(%s)!", field);
-               return NULL;
-       }
-}
-
-API int calendar_svc_struct_get_int(cal_struct *event, const char *field)
-{
-       cal_sch_full_t * sch_rec = NULL;
-       cals_updated *update = NULL;
-       calendar_t * cal_rec = NULL;
-       cal_timezone_t *tz_rec = NULL;
-       cals_struct_period_normal_onoff *nof = NULL;
-       cals_struct_period_allday_onoff *aof = NULL;
-       cals_struct_period_normal_basic *nbs = NULL;
-       cals_struct_period_allday_basic *abs = NULL;
-       cals_struct_period_normal_osp *nosp = NULL;
-       cals_struct_period_allday_osp *aosp = NULL;
-       cals_struct_period_normal_location *nosl = NULL;
-       cals_struct_period_allday_location *aosl = NULL;
-       cals_struct_period_normal_alarm *nosa = NULL;
-
-       retvm_if(NULL == event || NULL==event->user_data || NULL == field, 0,
-                               "Invalid parameters(event(%p), field(%p))", event, field);
-       switch(event->event_type)
-       {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-       case CAL_STRUCT_TYPE_TODO:
-               sch_rec = event->user_data;
-               if(0 == strcmp(field,CAL_VALUE_INT_INDEX))
-               {
-                       return sch_rec->index;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ACCOUNT_ID))
-               {
-                       return sch_rec->account_id;
-               }
-               else if(0 == strcmp(field, CAL_VALUE_INT_TYPE))
-               {
-                       return sch_rec->cal_type;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_FILE_ID))
-               {
-                       return sch_rec->file_id;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_CONTACT_ID))
-               {
-                       return sch_rec->contact_id;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_BUSY_STATUS))
-               {
-                       return sch_rec->busy_status;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_SENSITIVITY))
-               {
-                       return sch_rec->sensitivity;
-               }
-               else if(0 == strcmp(field, CAL_VALUE_INT_CALENDAR_TYPE))
-               {
-                       return sch_rec->calendar_type;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_MEETING_STATUS))
-               {
-                       return sch_rec->meeting_status;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_LOCATION_TYPE))
-               {
-                       return sch_rec->location_type;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_CALENDAR_ID))
-               {
-                       return sch_rec->calendar_id;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_DST))
-               {
-                       return sch_rec->dst;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ORIGINAL_EVENT_ID))
-               {
-                       return sch_rec->original_event_id;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_SYNC_STATUS))
-               {
-                       return sch_rec->sync_status;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_PRIORITY))
-               {
-                       return sch_rec->priority;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_TASK_STATUS))
-               {
-                       return sch_rec->task_status;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_TIMEZONE))
-               {
-                       return sch_rec->timezone;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_EMAIL_ID))
-               {
-                       return sch_rec->email_id;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_AVAILABILITY))
-               {
-                       return sch_rec->availability;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_DELETED))
-               {
-                       return 0;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_PROGRESS))
-               {
-                       return sch_rec->progress;
-               }
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTSTART_TYPE))
-                       return sch_rec->dtstart_type;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTSTART_YEAR))
-                       return sch_rec->dtstart_year;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTSTART_MONTH))
-                       return sch_rec->dtstart_month;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTSTART_MDAY))
-                       return sch_rec->dtstart_mday;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTEND_TYPE))
-                       return sch_rec->dtend_type;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTEND_YEAR))
-                       return sch_rec->dtend_year;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTEND_MONTH))
-                       return sch_rec->dtend_month;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTEND_MDAY))
-                       return sch_rec->dtend_mday;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_FREQ))
-                       return sch_rec->freq;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_ID))
-                       return sch_rec->rrule_id;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_RANGE_TYPE))
-                       return sch_rec->range_type;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_UNTIL_TYPE))
-                       return sch_rec->until_type;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_UNTIL_YEAR))
-                       return sch_rec->until_year;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_UNTIL_MONTH))
-                       return sch_rec->until_month;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_UNTIL_MDAY))
-                       return sch_rec->until_mday;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_COUNT))
-                       return sch_rec->count;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_INTERVAL))
-                       return sch_rec->interval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_WKST))
-                       return sch_rec->wkst;
-               /* deprecated start >>>>>>>>>>>>>>>>>>>>>>>>>*/
-               else if(0 == strcmp(field, "index"))
-               {
-                       return sch_rec->index;
-               }
-               else if(0 == strcmp(field, CAL_VALUE_INT_CAL_TYPE))
-               {
-                       return sch_rec->cal_type;
-               }
-               else
-               {
-                       ERR("Can not find the field(%s)",field);
-               }
-               break;
-       case CAL_STRUCT_TYPE_CALENDAR:
-               cal_rec = event->user_data;
-
-               if(0 == strcmp(field,CAL_TABLE_INT_INDEX))
-               {
-                       return cal_rec->index;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_UPDATED))
-               {
-                       return cal_rec->updated;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_HIDDEN))
-               {
-                       return cal_rec->hidden;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_SELECTED))
-               {
-                       return cal_rec->selected;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_LOCALE))
-               {
-                       return cal_rec->locale;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_COUNTRY))
-               {
-                       return cal_rec->country;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_TIME_ZONE))
-               {
-                       return cal_rec->time_zone;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_DISPLAY_ALL_TIMEZONES))
-               {
-                       return cal_rec->display_all_timezones;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_DATE_FIELD_ORDER))
-               {
-                       return cal_rec->date_field_order;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_FROMAT_24HOUR_TIME))
-               {
-                       return cal_rec->format_24hour_time;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_WEEK_START))
-               {
-                       return cal_rec->week_start;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_DEFAULT_CAL_MODE))
-               {
-                       return cal_rec->default_cal_mode;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_CUSTOM_CAL_MODE))
-               {
-                       return cal_rec->custom_cal_mode;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_SHOW_DECLINED_EVENTS))
-               {
-                       return cal_rec->show_declined_events;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_HIDE_INVITATIONS))
-               {
-                       return cal_rec->hide_invitations;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_ALTERNATE_CALENDAR))
-               {
-                       return cal_rec->alternate_calendar;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_VISIBILITY))
-               {
-                       return cal_rec->visibility;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_PROJECTION))
-               {
-                       return cal_rec->projection;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_SEQUENCE))
-               {
-                       return cal_rec->sequence;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_SUPRESS_REPLY_NOTIFICATIONS))
-               {
-                       return cal_rec->suppress_reply_notifications;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_SYNC_EVENT))
-               {
-                       return cal_rec->sync_event;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_TIMES_CLEANED))
-               {
-                       return cal_rec->times_cleaned;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_GUESTS_CAN_MODIFY))
-               {
-                       return cal_rec->guests_can_modify;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_GUESTS_CAN_INVITE_OTHERS))
-               {
-                       return cal_rec->guests_can_invite_others;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_GUESTS_CAN_SEE_GUESTS))
-               {
-                       return cal_rec->guests_can_see_guests;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_ACCESS_LEVEL))
-               {
-                       return cal_rec->access_level;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_SYNC_STATUS))
-               {
-                       return cal_rec->sync_status;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_ACCOUNT_ID))
-               {
-                       return cal_rec->account_id;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_SENSITIVITY))
-               {
-                       return cal_rec->sensitivity;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_STORE_TYPE))
-               {
-                       return cal_rec->store_type;
-               }
-               else
-               {
-                       ERR("Can not find the field(%s)",field);
-               }
-               break;
-       case CAL_STRUCT_TYPE_TIMEZONE:
-               tz_rec = event->user_data;
-               if(0 == strcmp(field,CAL_TZ_VALUE_INT_INDEX))
-               {
-                       return tz_rec->index;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_TZ_OFFSET))
-               {
-                       return tz_rec->tz_offset_from_gmt;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_STD_START_MONTH))
-               {
-                       return tz_rec->std_start_month;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_STD_START_POSITION_OF_WEEK))
-               {
-                       return tz_rec->std_start_position_of_week;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_STD_START_DAY))
-               {
-                       return tz_rec->std_start_day;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_STD_START_HOUR))
-               {
-                       return tz_rec->std_start_hour;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_STD_BIAS))
-               {
-                       return tz_rec->standard_bias;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_DST_START_MONTH))
-               {
-                       return tz_rec->day_light_start_month;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_DST_START_POSITION_OF_WEEK))
-               {
-                       return tz_rec->day_light_start_position_of_week;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_DST_START_DAY))
-               {
-                       return tz_rec->day_light_start_day;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_DST_START_HOUR))
-               {
-                       return tz_rec->day_light_start_hour;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_DST_BIAS))
-               {
-                       return tz_rec->day_light_bias;
-               }
-
-               break;
-       case CAL_STRUCT_TYPE_UPDATED_LIST:
-               update = event->user_data;
-               if(0 == strcmp(field, CALS_STRUCT_UPDATED_INT_TYPE))
-               {
-                       return update->type;
-               }
-               else if(0 == strcmp(field, CALS_STRUCT_UPDATED_INT_ID))
-               {
-                       return update->id;
-               }
-               else if(0 == strcmp(field, CALS_STRUCT_UPDATED_INT_VERSION))
-               {
-                       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);
-               }
-               break;
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_ONOFF:
-               nof = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ONOFF_INT_EVENTID))
-                       return nof->index;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ONOFF_INT_DTSTART_TYPE))
-                       return nof->dtstart_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ONOFF_INT_DTEND_TYPE))
-                       return nof->dtstart_type;
-               else
-                       ERR("Can't find field(%s)", field);
-
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_ONOFF:
-               aof = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_EVENTID))
-                       return aof->index;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_TYPE))
-                       return nof->dtstart_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_YEAR))
-                       return aof->dtstart_year;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_MONTH))
-                       return aof->dtstart_month;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_MDAY))
-                       return aof->dtstart_mday;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTEND_TYPE))
-                       return nof->dtend_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTEND_YEAR))
-                       return aof->dtend_year;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTEND_MONTH))
-                       return aof->dtend_month;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTEND_MDAY))
-                       return aof->dtend_mday;
-               else
-                       ERR("Can't find field(%s)", field);
-
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_BASIC:
-               nbs = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_INT_EVENTID))
-                       return nbs->index;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_INT_DTSTART_TYPE))
-                       return nbs->dtstart_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_INT_DTEND_TYPE))
-                       return nbs->dtstart_type;
-               else
-                       ERR("Can't find field(%s)", field);
-
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_BASIC:
-               abs = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_EVENTID))
-                       return abs->index;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_TYPE))
-                       return abs->dtstart_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_YEAR))
-                       return abs->dtstart_year;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_MONTH))
-                       return abs->dtstart_month;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_MDAY))
-                       return abs->dtstart_mday;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_TYPE))
-                       return abs->dtend_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_YEAR))
-                       return abs->dtend_year;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_MONTH))
-                       return abs->dtend_month;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_MDAY))
-                       return abs->dtend_mday;
-               else
-                       ERR("Can't find field(%s)", field);
-
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_OSP:
-               nosp = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_EVENTID))
-                       return nosp->index;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_DTSTART_TYPE))
-                       return nosp->dtstart_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_DTEND_TYPE))
-                       return nosp->dtend_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_CALENDAR_ID))
-                       return nosp->calendar_id;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_BUSY_STATUS))
-                       return nosp->busy_status;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_STATUS))
-                       return nosp->meeting_status;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_PRIORITY))
-                       return nosp->priority;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_VISIBILITY))
-                       return nosp->sensitivity;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_IS_RECURRING))
-                       return nosp->rrule_id;
-               else
-                       ERR("Can't find field(%s)", field);
-
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_OSP:
-               aosp = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_EVENTID))
-                       return aosp->index;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_TYPE))
-                       return aosp->dtstart_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_YEAR))
-                       return aosp->dtstart_year;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_MONTH))
-                       return aosp->dtstart_month;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_MDAY))
-                       return aosp->dtstart_mday;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_TYPE))
-                       return aosp->dtend_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_YEAR))
-                       return aosp->dtend_year;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_MONTH))
-                       return aosp->dtend_month;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_MDAY))
-                       return aosp->dtend_mday;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_CALENDAR_ID))
-                       return aosp->calendar_id;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_BUSY_STATUS))
-                       return aosp->busy_status;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_STATUS))
-                       return aosp->meeting_status;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_PRIORITY))
-                       return aosp->priority;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_VISIBILITY))
-                       return aosp->sensitivity;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_IS_RECURRING))
-                       return aosp->rrule_id;
-               else
-                       ERR("Can't find field(%s)", field);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_LOCATION:
-               nosl = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_EVENTID))
-                       return nosl->index;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_DTSTART_TYPE))
-                       return nosl->dtstart_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_DTEND_TYPE))
-                       return nosl->dtend_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_CALENDAR_ID))
-                       return nosl->calendar_id;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_BUSY_STATUS))
-                       return nosl->busy_status;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_STATUS))
-                       return nosl->meeting_status;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_PRIORITY))
-                       return nosl->priority;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_VISIBILITY))
-                       return nosl->sensitivity;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_IS_RECURRING))
-                       return nosl->rrule_id;
-               else
-                       ERR("Can't find field(%s)", field);
-
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_LOCATION:
-               aosl = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_EVENTID))
-                       return aosl->index;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTSTART_TYPE))
-                       return aosl->dtstart_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTSTART_YEAR))
-                       return aosl->dtstart_year;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTSTART_MONTH))
-                       return aosl->dtstart_month;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTSTART_MDAY))
-                       return aosl->dtstart_mday;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTEND_TYPE))
-                       return aosl->dtend_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTEND_YEAR))
-                       return aosl->dtend_year;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTEND_MONTH))
-                       return aosl->dtend_month;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTEND_MDAY))
-                       return aosl->dtend_mday;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_CALENDAR_ID))
-                       return aosl->calendar_id;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_BUSY_STATUS))
-                       return aosl->busy_status;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_STATUS))
-                       return aosl->meeting_status;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_PRIORITY))
-                       return aosl->priority;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_VISIBILITY))
-                       return aosl->sensitivity;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_IS_RECURRING))
-                       return aosl->rrule_id;
-               else
-                       ERR("Can't find field(%s)", field);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_ALARM:
-               nosa = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_INT_EVENTID))
-                       return nosa->index;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_INT_DTSTART_TYPE))
-                       return nosa->dtstart_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_INT_DTEND_TYPE))
-                       return nosa->dtend_type;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_INT_CALENDAR_ID))
-                       return nosa->calendar_id;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_INT_ALARM_ID))
-                       return nosa->alarm_id;
-               else
-                       ERR("Can't find field(%s)", field);
-               break;
-
-       default:
-               break;
-
-       }
-
-       return 0;
-}
-
-API int calendar_svc_struct_set_int (cal_struct *event, const char *field, int intval)
-{
-       cal_sch_full_t * sch_rec = NULL;
-       calendar_t * cal_rec = NULL;
-       cal_timezone_t *tz_rec = NULL;
-       cals_struct_period_normal_onoff *nof = NULL;
-       cals_struct_period_allday_onoff *aof = NULL;
-       cals_struct_period_normal_basic *nbs = NULL;
-       cals_struct_period_allday_basic *abs = NULL;
-       cals_struct_period_normal_osp *nosp = NULL;
-       cals_struct_period_allday_osp *aosp = NULL;
-       cals_struct_period_normal_location *nosl = NULL;
-       cals_struct_period_allday_location *aosl = NULL;
-       cals_struct_period_normal_alarm *nosa = NULL;
-
-       retv_if(NULL == event, CAL_ERR_ARG_NULL);
-       retv_if(NULL == field, CAL_ERR_ARG_NULL);
-
-       switch(event->event_type)
-       {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-       case CAL_STRUCT_TYPE_TODO:
-               sch_rec = event->user_data;
-               if(0 == strcmp(field,CAL_VALUE_INT_INDEX))
-               {
-                       sch_rec->index = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ACCOUNT_ID))
-               {
-                       sch_rec->account_id = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_FILE_ID))
-               {
-                       sch_rec->file_id = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_CONTACT_ID))
-               {
-                       sch_rec->contact_id = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_BUSY_STATUS))
-               {
-                       sch_rec->busy_status = intval;
-               }
-               else if(0 == strcmp(field, CAL_VALUE_INT_SENSITIVITY))
-               {
-                       sch_rec->sensitivity = intval;
-               }
-               else if(0 == strcmp(field, CAL_VALUE_INT_CALENDAR_TYPE))
-               {
-                       sch_rec->calendar_type = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_MEETING_STATUS))
-               {
-                       sch_rec->meeting_status = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_LOCATION_TYPE))
-               {
-                       sch_rec->location_type = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_CALENDAR_ID))
-               {
-                       sch_rec->calendar_id = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_DST))
-               {
-                       sch_rec->dst = intval;
-               }
-               else if(0 == strcmp(field, CAL_VALUE_INT_ORIGINAL_EVENT_ID))
-               {
-                       sch_rec->original_event_id = intval;
-               }
-               else if(0 == strcmp(field, CAL_VALUE_INT_PRIORITY))
-               {
-                       sch_rec->priority = intval;
-               }
-               else if(0 == strcmp(field, CAL_VALUE_INT_SYNC_STATUS))
-               {
-                       sch_rec->sync_status = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_TASK_STATUS))
-               {
-                       sch_rec->task_status= intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_TIMEZONE))
-               {
-                       sch_rec->timezone= intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_EMAIL_ID))
-               {
-                       sch_rec->email_id= intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_AVAILABILITY))
-               {
-                       sch_rec->availability= intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_PROGRESS))
-               {
-                       sch_rec->progress = intval;
-               }
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTSTART_TYPE))
-                       sch_rec->dtstart_type = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTSTART_YEAR))
-                       sch_rec->dtstart_year = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTSTART_MONTH))
-                       sch_rec->dtstart_month = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTSTART_MDAY))
-                       sch_rec->dtstart_mday = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTEND_TYPE))
-                       sch_rec->dtend_type = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTEND_YEAR))
-                       sch_rec->dtend_year = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTEND_MONTH))
-                       sch_rec->dtend_month = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_DTEND_MDAY))
-                       sch_rec->dtend_mday = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_FREQ))
-                       sch_rec->freq = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_RANGE_TYPE))
-                       sch_rec->range_type = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_UNTIL_TYPE))
-                       sch_rec->until_type = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_UNTIL_YEAR))
-                       sch_rec->until_year = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_UNTIL_MONTH))
-                       sch_rec->until_month = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_UNTIL_MDAY))
-                       sch_rec->until_mday = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_COUNT))
-                       sch_rec->count = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_INTERVAL))
-                       sch_rec->interval = intval;
-               else if(0 == strcmp(field, CALS_VALUE_INT_RRULE_WKST))
-                       sch_rec->wkst = intval;
-               /* deprecated start >>>>>>>>>>>>>>>>>>> */
-               else if(0 == strcmp(field,"index"))
-               {
-                       sch_rec->index = intval;
-               }
-               /* <<<<<<<<<<<<<<<<<<<< deprecated end */
-               else
-               {
-                       ERR("Invalid field(%d, %s)", event->event_type, field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CAL_STRUCT_TYPE_CALENDAR:
-               cal_rec = event->user_data;
-               if(0 == strcmp(field,CAL_TABLE_INT_UPDATED))
-               {
-                       cal_rec->updated = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_HIDDEN))
-               {
-                       cal_rec->hidden = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_SELECTED))
-               {
-                       cal_rec->selected = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_LOCALE))
-               {
-                       cal_rec->locale = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_COUNTRY))
-               {
-                       cal_rec->country = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_TIME_ZONE))
-               {
-                       cal_rec->time_zone = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_DISPLAY_ALL_TIMEZONES))
-               {
-                       cal_rec->display_all_timezones = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_DATE_FIELD_ORDER))
-               {
-                       cal_rec->date_field_order = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_FROMAT_24HOUR_TIME))
-               {
-                       cal_rec->format_24hour_time = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_WEEK_START))
-               {
-                       cal_rec->week_start = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_DEFAULT_CAL_MODE))
-               {
-                       cal_rec->default_cal_mode = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_CUSTOM_CAL_MODE))
-               {
-                       cal_rec->custom_cal_mode = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_SHOW_DECLINED_EVENTS))
-               {
-                       cal_rec->show_declined_events = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_HIDE_INVITATIONS))
-               {
-                       cal_rec->hide_invitations = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_ALTERNATE_CALENDAR))
-               {
-                       cal_rec->alternate_calendar = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_VISIBILITY))
-               {
-                       cal_rec->visibility = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_PROJECTION))
-               {
-                       cal_rec->projection = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_SEQUENCE))
-               {
-                       cal_rec->sequence = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_SUPRESS_REPLY_NOTIFICATIONS))
-               {
-                       cal_rec->suppress_reply_notifications = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_SYNC_EVENT))
-               {
-                       cal_rec->sync_event = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_TIMES_CLEANED))
-               {
-                       cal_rec->times_cleaned = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_GUESTS_CAN_MODIFY))
-               {
-                       cal_rec->guests_can_modify = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_GUESTS_CAN_INVITE_OTHERS))
-               {
-                       cal_rec->guests_can_invite_others = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_GUESTS_CAN_SEE_GUESTS))
-               {
-                       cal_rec->guests_can_see_guests = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_ACCESS_LEVEL))
-               {
-                       cal_rec->access_level = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_SYNC_STATUS))
-               {
-                       cal_rec->sync_status = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_ACCOUNT_ID))
-               {
-                       cal_rec->account_id = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_SENSITIVITY))
-               {
-                       cal_rec->sensitivity = intval;
-               }
-               else if(0 == strcmp(field,CAL_TABLE_INT_STORE_TYPE))
-               {
-                       cal_rec->store_type = intval;
-               }
-               else
-               {
-                       ERR("Invalid field(%d, %s)", event->event_type, field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-       case CAL_STRUCT_TYPE_TIMEZONE:
-               tz_rec = event->user_data;
-               if(0 == strcmp(field,CAL_TZ_VALUE_INT_INDEX))
-               {
-                       tz_rec->index = intval;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_TZ_OFFSET))
-               {
-                       tz_rec->tz_offset_from_gmt = intval;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_STD_START_MONTH))
-               {
-                       tz_rec->std_start_month = intval;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_STD_START_POSITION_OF_WEEK))
-               {
-                       tz_rec->std_start_position_of_week = intval;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_STD_START_DAY))
-               {
-                       tz_rec->std_start_day = intval;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_STD_START_HOUR))
-               {
-                       tz_rec->std_start_hour = intval;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_STD_BIAS))
-               {
-                       tz_rec->standard_bias = intval;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_DST_START_MONTH))
-               {
-                       tz_rec->day_light_start_month = intval;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_DST_START_POSITION_OF_WEEK))
-               {
-                       tz_rec->day_light_start_position_of_week = intval;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_DST_START_DAY))
-               {
-                       tz_rec->day_light_start_day = intval;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_DST_START_HOUR))
-               {
-                       tz_rec->day_light_start_hour = intval;
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_INT_DST_BIAS))
-               {
-                       tz_rec->day_light_bias = intval;
-               }
-               else {
-                       ERR("Invalid field(%d, %s)", event->event_type, field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_ONOFF:
-               nof = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ONOFF_INT_EVENTID))
-                       nof->index = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ONOFF_INT_DTSTART_TYPE))
-                       nof->dtstart_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ONOFF_INT_DTEND_TYPE))
-                       nof->dtend_type = intval;
-               else {
-                       ERR("Invalid field(%d, %s)", event->event_type, field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_ONOFF:
-               aof = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_EVENTID))
-                       aof->index = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_TYPE))
-                       aof->dtstart_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_YEAR))
-                       aof->dtstart_year = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_MONTH))
-                       aof->dtstart_month = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_MDAY))
-                       aof->dtstart_mday = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTEND_TYPE))
-                       aof->dtend_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTEND_YEAR))
-                       aof->dtend_year = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTEND_MONTH))
-                       aof->dtend_month = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTEND_MDAY))
-                       aof->dtend_mday = intval;
-               else {
-                       ERR("Invalid field(%d, %s)", event->event_type, field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_BASIC:
-               nbs = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_INT_EVENTID))
-                       nbs->index = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_INT_DTSTART_TYPE))
-                       nbs->dtstart_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_INT_DTEND_TYPE))
-                       nbs->dtend_type = intval;
-               else {
-                       ERR("Invalid field(%d, %s)", event->event_type, field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_BASIC:
-               abs = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_EVENTID))
-                       abs->index = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_TYPE))
-                       abs->dtstart_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_YEAR))
-                       abs->dtstart_year = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_MONTH))
-                       abs->dtstart_month = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_MDAY))
-                       abs->dtstart_mday = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_TYPE))
-                       abs->dtend_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_YEAR))
-                       abs->dtend_year = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_MONTH))
-                       abs->dtend_month = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_MDAY))
-                       abs->dtend_mday = intval;
-               else {
-                       ERR("Invalid field(%d, %s)", event->event_type, field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_OSP:
-               nosp = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_EVENTID))
-                       nosp->index = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_DTSTART_TYPE))
-                       nosp->dtstart_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_DTEND_TYPE))
-                       nosp->dtend_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_CALENDAR_ID))
-                       nosp->calendar_id = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_BUSY_STATUS))
-                       nosp->busy_status = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_STATUS))
-                       nosp->meeting_status = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_PRIORITY))
-                       nosp->priority = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_VISIBILITY))
-                       nosp->sensitivity = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_INT_IS_RECURRING))
-                       nosp->rrule_id = intval;
-               else {
-                       ERR("Invalid field(%d, %s)", event->event_type, field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_OSP:
-               aosp = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_EVENTID))
-                       aosp->index = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_TYPE))
-                       aosp->dtstart_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_YEAR))
-                       aosp->dtstart_year = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_MONTH))
-                       aosp->dtstart_month = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_MDAY))
-                       aosp->dtstart_mday = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_TYPE))
-                       aosp->dtend_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_YEAR))
-                       aosp->dtend_year = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_MONTH))
-                       aosp->dtend_month = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_MDAY))
-                       aosp->dtend_mday = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_CALENDAR_ID))
-                       aosp->calendar_id = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_BUSY_STATUS))
-                       aosp->busy_status = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_STATUS))
-                       aosp->meeting_status = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_PRIORITY))
-                       aosp->priority = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_VISIBILITY))
-                       aosp->sensitivity = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_INT_IS_RECURRING))
-                       aosp->rrule_id = intval;
-               else {
-                       ERR("Invalid field(%d, %s)", event->event_type, field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_LOCATION:
-               nosl = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_EVENTID))
-                       nosl->index = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_DTSTART_TYPE))
-                       nosl->dtstart_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_DTEND_TYPE))
-                       nosl->dtend_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_CALENDAR_ID))
-                       nosl->calendar_id = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_BUSY_STATUS))
-                       nosl->busy_status = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_STATUS))
-                       nosl->meeting_status = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_PRIORITY))
-                       nosl->priority = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_VISIBILITY))
-                       nosl->sensitivity = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_INT_IS_RECURRING))
-                       nosl->rrule_id = intval;
-               else {
-                       ERR("Invalid field(%d, %s)", event->event_type, field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_LOCATION:
-               aosl = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_EVENTID))
-                       aosl->index = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTSTART_TYPE))
-                       aosl->dtstart_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTSTART_YEAR))
-                       aosl->dtstart_year = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTSTART_MONTH))
-                       aosl->dtstart_month = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTSTART_MDAY))
-                       aosl->dtstart_mday = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTEND_TYPE))
-                       aosl->dtend_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTEND_YEAR))
-                       aosl->dtend_year = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTEND_MONTH))
-                       aosl->dtend_month = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_DTEND_MDAY))
-                       aosl->dtend_mday = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_CALENDAR_ID))
-                       aosl->calendar_id = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_BUSY_STATUS))
-                       aosl->busy_status = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_STATUS))
-                       aosl->meeting_status = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_PRIORITY))
-                       aosl->priority = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_VISIBILITY))
-                       aosl->sensitivity = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_INT_IS_RECURRING))
-                       aosl->rrule_id = intval;
-               else {
-                       ERR("Invalid field(%d, %s)", event->event_type, field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_ALARM:
-               nosa = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_INT_EVENTID))
-                       nosa->index = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_INT_DTSTART_TYPE))
-                       nosa->dtstart_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_INT_DTEND_TYPE))
-                       nosa->dtend_type = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_INT_CALENDAR_ID))
-                       nosa->calendar_id = intval;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_INT_ALARM_ID))
-                       nosa->alarm_id = intval;
-               else {
-                       ERR("Invalid field(%d, %s)", event->event_type, field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-
-       default:
-               ERR("Invalid field(%d, %s)", event->event_type, field);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_struct_set_str (cal_struct *event, const char *field, const char *strval)
-{
-       retex_if(NULL == event || NULL == field || NULL == strval,,"[ERROR]calendar_svc_struct_set_str:Invalid parameters.\n");
-
-       cal_sch_full_t *sch_rec = NULL;
-       calendar_t *cal_rec = NULL;
-       cal_timezone_t *tz_rec = NULL;
-       cals_struct_period_normal_basic *nbs = NULL;
-       cals_struct_period_allday_basic *abs = NULL;
-       cals_struct_period_normal_osp *nosp = NULL;
-       cals_struct_period_allday_osp *aosp = NULL;
-       cals_struct_period_normal_location *nosl = NULL;
-       cals_struct_period_allday_location *aosl = NULL;
-
-       retvm_if(strval == NULL, CAL_ERR_FAIL, "Invalid argument: value is NULL");
-
-       switch(event->event_type)
-       {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-       case CAL_STRUCT_TYPE_TODO:
-               sch_rec = (cal_sch_full_t*)event->user_data;
-               if(0 == strcmp(field,CAL_VALUE_TXT_SUMMARY))
-               {
-                       CAL_FREE(sch_rec->summary);
-                       sch_rec->summary = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_DESCRIPTION))
-               {
-                       CAL_FREE(sch_rec->description);
-                       sch_rec->description = strdup(strval);
-               }
-               else if(0 == strcmp(field, CAL_VALUE_TXT_LOCATION))
-               {
-                       CAL_FREE(sch_rec->location);
-                       sch_rec->location = strdup(strval);
-               }
-               else if(0 == strcmp(field, CAL_VALUE_TXT_CATEGORIES))
-               {
-                       CAL_FREE(sch_rec->categories);
-                       sch_rec->categories = strdup(strval);
-               }
-               else if(0 == strcmp(field, CAL_VALUE_TXT_EXDATE))
-               {
-                       CAL_FREE(sch_rec->exdate);
-                       sch_rec->exdate = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_UID))
-               {
-                       CAL_FREE(sch_rec->uid);
-                       sch_rec->uid = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ORGANIZER_NAME))
-               {
-                       CAL_FREE(sch_rec->organizer_name);
-                       sch_rec->organizer_name = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ORGANIZER_EMAIL  ))
-               {
-                       CAL_FREE(sch_rec->organizer_email);
-                       sch_rec->organizer_email = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_GCAL_ID ))
-               {
-                       CAL_FREE(sch_rec->gcal_id);
-                       sch_rec->gcal_id = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_UPDATED))
-               {
-                       CAL_FREE(sch_rec->updated);
-                       sch_rec->updated = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_LOCATION_SUMMARY))
-               {
-                       CAL_FREE(sch_rec->location_summary);
-                       sch_rec->location_summary = strdup(strval);
-               }
-               else if(0 == strcmp(field, CAL_VALUE_TXT_ETAG))
-               {
-                       CAL_FREE(sch_rec->etag);
-                       sch_rec->etag = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_EDIT_URL))
-               {
-                       CAL_FREE(sch_rec->edit_uri);
-                       sch_rec->edit_uri = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_GEDERID))
-               {
-                       CAL_FREE(sch_rec->gevent_id);
-                       sch_rec->gevent_id = strdup(strval);
-               }
-               else if(0 == strcmp(field, CALS_VALUE_TXT_DTSTART_TZID))
-               {
-                       CAL_FREE(sch_rec->dtstart_tzid);
-                       sch_rec->dtstart_tzid = strdup(strval);
-               }
-               else if(0 == strcmp(field, CALS_VALUE_TXT_DTEND_TZID))
-               {
-                       CAL_FREE(sch_rec->dtend_tzid);
-                       sch_rec->dtend_tzid = strdup(strval);
-               }
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYSECOND))
-               {
-                       CAL_FREE(sch_rec->bysecond);
-                       sch_rec->bysecond = strdup(strval);
-               }
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYMINUTE))
-               {
-                       CAL_FREE(sch_rec->byminute);
-                       sch_rec->byminute = strdup(strval);
-               }
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYHOUR))
-               {
-                       CAL_FREE(sch_rec->byhour);
-                       sch_rec->byhour = strdup(strval);
-               }
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYDAY))
-               {
-                       CAL_FREE(sch_rec->byday);
-                       sch_rec->byday = strdup(strval);
-               }
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYMONTHDAY))
-               {
-                       CAL_FREE(sch_rec->bymonthday);
-                       sch_rec->bymonthday = strdup(strval);
-               }
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYYEARDAY))
-               {
-                       CAL_FREE(sch_rec->byyearday);
-                       sch_rec->byyearday = strdup(strval);
-               }
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYWEEKNO))
-               {
-                       CAL_FREE(sch_rec->byweekno);
-                       sch_rec->byweekno = strdup(strval);
-               }
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYMONTH))
-               {
-                       CAL_FREE(sch_rec->bymonth);
-                       sch_rec->bymonth = strdup(strval);
-               }
-               else if(0 == strcmp(field, CALS_VALUE_TXT_RRULE_BYSETPOS))
-               {
-                       CAL_FREE(sch_rec->bysetpos);
-                       sch_rec->bysetpos = strdup(strval);
-               }
-               else
-               {
-                       retex_if(true,,"Can not find the field(%s)", field);
-               }
-               break;
-
-       case CAL_STRUCT_TYPE_CALENDAR:
-               cal_rec = (calendar_t*)event->user_data;
-
-               if(0 == strcmp(field,CAL_TABLE_TXT_CALENDAR_ID))
-               {
-                       CAL_FREE(cal_rec->calendar_id);
-                       cal_rec->calendar_id = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_UID))
-               {
-                       CAL_FREE(cal_rec->uid);
-                       cal_rec->uid = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_LINK))
-               {
-                       CAL_FREE(cal_rec->link);
-                       cal_rec->link = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_NAME))
-               {
-                       CAL_FREE(cal_rec->name);
-                       cal_rec->name = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_DESCRIPTION))
-               {
-                       CAL_FREE(cal_rec->description);
-                       cal_rec->description = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_AUTHOR))
-               {
-                       CAL_FREE(cal_rec->author);
-                       cal_rec->author = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_COLOR))
-               {
-                       CAL_FREE(cal_rec->color);
-                       cal_rec->color = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_LOCATION))
-               {
-                       CAL_FREE(cal_rec->location);
-                       cal_rec->location  = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_TIME_ZONE_LABEL))
-               {
-                       CAL_FREE(cal_rec->timezone_label);
-                       cal_rec->timezone_label = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_USER_LOCATION))
-               {
-                       CAL_FREE(cal_rec->user_location);
-                       cal_rec->user_location = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_TABLE_TXT_WEATHER))
-               {
-                       CAL_FREE(cal_rec->weather);
-                       cal_rec->weather = strdup(strval);
-               }
-               else
-               {
-                       retex_if(true,,"[ERROR]calendar_svc_struct_set_str:Can not find the field!\n");
-               }
-
-               break;
-       case CAL_STRUCT_TYPE_TIMEZONE:
-               tz_rec = (cal_timezone_t*)event->user_data;
-               if(0 == strcmp(field,CAL_TZ_VALUE_TXT_STD_NAME))
-               {
-                       CAL_FREE(tz_rec->standard_name);
-                       tz_rec->standard_name = strdup(strval);
-               }
-               else if(0 == strcmp(field,CAL_TZ_VALUE_TXT_DST_NAME))
-               {
-                       CAL_FREE(tz_rec->day_light_name);
-                       tz_rec->day_light_name = strdup(strval);
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_ONOFF:
-               ERR("No field in CALS_LIST_PERIOD_NORMAL_ONOFF");
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_ONOFF:
-               ERR("No field in CALS_LIST_PERIOD_ALLDAY_ONOFF");
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_BASIC:
-               nbs = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_TXT_SUMMARY)) {
-                       CAL_FREE(nbs->summary);
-                       nbs->summary = strdup(strval);
-               } else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_TXT_LOCATION)) {
-                       CAL_FREE(nbs->location);
-                       nbs->location = strdup(strval);
-               }else {
-                       ERR("Can not find the field!(%s)",field);
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_BASIC:
-               abs = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_TXT_SUMMARY)) {
-                       CAL_FREE(abs->summary);
-                       abs->summary = strdup(strval);
-               } else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_BASIC_TXT_LOCATION)) {
-                       CAL_FREE(abs->location);
-                       abs->location = strdup(strval);
-               }else {
-                       ERR("Can not find the field!(%s)",field);
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_OSP:
-               nosp = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_TXT_SUMMARY)) {
-                       CAL_FREE(nosp->summary);
-                       nosp->summary = strdup(strval);
-               } else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_TXT_LOCATION)) {
-                       CAL_FREE(nosp->location);
-                       nosp->location = strdup(strval);
-               } else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_TXT_DESCRIPTION)) {
-                       CAL_FREE(nosp->description);
-                       nosp->description = strdup(strval);
-               }else {
-                       ERR("Can not find the field!(%s)",field);
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_OSP:
-               nosp = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_TXT_SUMMARY)) {
-                       CAL_FREE(aosp->summary);
-                       aosp->summary = strdup(strval);
-               } else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_TXT_LOCATION)) {
-                       CAL_FREE(aosp->location);
-                       aosp->location = strdup(strval);
-               } else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_OSP_TXT_DESCRIPTION)) {
-                       CAL_FREE(aosp->description);
-                       aosp->description = strdup(strval);
-               } else {
-                       ERR("Can not find the field!(%s)", field);
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_LOCATION:
-               nosl = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_TXT_SUMMARY)) {
-                       CAL_FREE(nosp->summary);
-                       nosl->summary = strdup(strval);
-               } else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_TXT_LOCATION)) {
-                       CAL_FREE(nosp->location);
-                       nosl->location = strdup(strval);
-               } else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_TXT_DESCRIPTION)) {
-                       CAL_FREE(nosp->description);
-                       nosl->description = strdup(strval);
-               }else {
-                       ERR("Can not find the field!(%s)",field);
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_LOCATION:
-               nosl = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_TXT_SUMMARY)) {
-                       CAL_FREE(aosp->summary);
-                       aosl->summary = strdup(strval);
-               } else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_TXT_LOCATION)) {
-                       CAL_FREE(aosp->location);
-                       aosl->location = strdup(strval);
-               } else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_TXT_DESCRIPTION)) {
-                       CAL_FREE(aosp->description);
-                       aosl->description = strdup(strval);
-               } else {
-                       ERR("Can not find the field!(%s)", field);
-               }
-               break;
-
-       default:
-               ERR("Unknown event type(%d)", event->event_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       return CAL_SUCCESS;
-
-CATCH:
-
-       return CAL_ERR_FAIL;
-
-}
-
-API double calendar_svc_struct_get_double(cal_struct* record, const char *field)
-{
-       double ret_val = 0.0;
-       cal_sch_full_t *sch_rec = NULL;
-       cals_struct_period_normal_location *nosl = NULL;
-       cals_struct_period_allday_location *aosl = NULL;
-
-       retv_if(NULL == record, 0.0);
-       retv_if(NULL == field, 0.0);
-       retv_if(NULL == record->user_data, 0.0);
-
-       switch(record->event_type) {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-       case CAL_STRUCT_TYPE_TODO:
-               sch_rec = record->user_data;
-               if(0 == strcmp(field,CAL_VALUE_DBL_LATITUDE))
-                       ret_val = sch_rec->latitude;
-               else if(0 == strcmp(field,CAL_VALUE_DBL_LONGITUDE))
-                       ret_val = sch_rec->longitude;
-               else
-                       ERR("Unknown field(%s)", field);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_LOCATION:
-               nosl = record->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_DBL_LATITUDE))
-                       ret_val = nosl->latitude;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_DBL_LONGITUDE))
-                       ret_val = nosl->longitude;
-               else
-                       ERR("Unknown field(%s)", field);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_LOCATION:
-               aosl = record->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_DBL_LATITUDE))
-                       ret_val = aosl->latitude;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_DBL_LONGITUDE))
-                       ret_val = aosl->longitude;
-               else
-                       ERR("Unknown field(%s)", field);
-               break;
-
-       default:
-               ERR("Unknown event type(%d)", record->event_type);
-               break;
-       }
-
-       return ret_val;
-}
-
-API int calendar_svc_struct_set_double(cal_struct* record, const char *field,double value)
-{
-       cal_sch_full_t * sch_rec = NULL;
-       cals_struct_period_normal_location *nosl = NULL;
-       cals_struct_period_allday_location *aosl = NULL;
-
-       retv_if(NULL == record, CAL_ERR_ARG_NULL);
-       retv_if(NULL == field, CAL_ERR_ARG_NULL);
-       retv_if(NULL == record->user_data, CAL_ERR_ARG_INVALID);
-
-       switch(record->event_type)
-       {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-       case CAL_STRUCT_TYPE_TODO:
-               sch_rec = record->user_data;
-               if(0 == strcmp(field,CAL_VALUE_DBL_LATITUDE))
-                       sch_rec->latitude = value;
-               else if(0 == strcmp(field,CAL_VALUE_DBL_LONGITUDE))
-                       sch_rec->longitude = value;
-               else {
-                       ERR("Unknown field(%s)", field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_LOCATION:
-               nosl = record->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_DBL_LATITUDE))
-                       nosl->latitude = value;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_DBL_LONGITUDE))
-                       nosl->longitude = value;
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_ALLDAY_LOCATION:
-               aosl = record->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_DBL_LATITUDE))
-                       aosl->latitude = value;
-               else if (!strcmp(field, CALS_LIST_PERIOD_ALLDAY_LOCATION_DBL_LONGITUDE))
-                       aosl->longitude = value;
-               else
-                       ERR("Unknown field(%s)", field);
-               break;
-
-       default:
-               ERR("Unknown event type(%d)", record->event_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       return CAL_SUCCESS;
-}
-
-
-
-API int calendar_svc_struct_get_list (cal_struct *event, const char *field, GList **retlist)
-{
-       cal_sch_full_t * sch_rec = NULL;
-
-       retv_if(NULL == event, CAL_ERR_ARG_NULL);
-       retv_if(NULL == field, CAL_ERR_ARG_NULL);
-       retv_if(NULL == event->user_data, CAL_ERR_ARG_INVALID);
-
-       switch(event->event_type) {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-               sch_rec = (cal_sch_full_t*)event->user_data;
-               if(0 == strcmp(field,CAL_VALUE_LST_ATTENDEE_LIST))
-                       *retlist = sch_rec->attendee_list;
-               else if(0 == strcmp(field, CAL_VALUE_LST_ALARM))
-                       *retlist = sch_rec->alarm_list;
-               else {
-                       ERR("Unknown field(%s)", field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-       case CAL_STRUCT_TYPE_TODO:
-               sch_rec = (cal_sch_full_t*)event->user_data;
-               if(0 == strcmp(field,CAL_VALUE_LST_ATTENDEE_LIST))
-                       *retlist = sch_rec->attendee_list;
-               else if(0 == strcmp(field, CAL_VALUE_LST_ALARM))
-                       *retlist = sch_rec->alarm_list;
-               else {
-                       ERR("Unknown field(%s)", field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-       case CAL_STRUCT_TYPE_CALENDAR:
-       default:
-               ERR("Unknown event type(%d)", event->event_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       return CAL_SUCCESS;
-}
-
-
-
-static int _cals_struct_remove_list(const char *field, GList *list)
-{
-       GList *pList = list;
-
-       while(pList)
-       {
-               calendar_svc_value_free((cal_value**)&pList->data);
-
-               pList = pList->next;
-       }
-       g_list_free(list);
-       return 0;
-}
-
-
-API int calendar_svc_struct_store_list (cal_struct *event, const char *field, GList *list)
-{
-       cal_sch_full_t *sch_rec = NULL;
-
-       retv_if(NULL == event, CAL_ERR_ARG_NULL);
-       retv_if(NULL == field, CAL_ERR_ARG_NULL);
-       retv_if(NULL == event->user_data, CAL_ERR_ARG_INVALID);
-
-       switch(event->event_type) {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-               sch_rec = (cal_sch_full_t*)event->user_data;
-
-               if(0 == strcmp(field,CAL_VALUE_LST_ATTENDEE_LIST))
-               {
-                       if(list == NULL)
-                               _cals_struct_remove_list(field,sch_rec->attendee_list);
-
-                       sch_rec->attendee_list = list;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_LST_ALARM))
-               {
-                       if(list == NULL)
-                               _cals_struct_remove_list(field,sch_rec->alarm_list);
-
-                       sch_rec->alarm_list = list;
-               } else {
-                       ERR("%s is invalid field for event type schedule");
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CAL_STRUCT_TYPE_TODO:
-               sch_rec = (cal_sch_full_t*)event->user_data;
-
-               if(0 == strcmp(field,CAL_VALUE_LST_ATTENDEE_LIST))
-               {
-                       if(list == NULL)
-                               _cals_struct_remove_list(field,sch_rec->attendee_list);
-
-                       sch_rec->attendee_list = list;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_LST_ALARM))
-               {
-                       if(list == NULL)
-                               _cals_struct_remove_list(field,sch_rec->alarm_list);
-
-                       sch_rec->alarm_list = list;
-               } else {
-                       ERR("%s is invalid field for todo type schedule");
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CAL_STRUCT_TYPE_CALENDAR:
-       default:
-               ERR("Invalid schedule type(%d)", event->event_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       return CAL_SUCCESS;
-}
-
-API cal_value* calendar_svc_value_new (const char *filed)
-{
-       CALS_FN_CALL;
-       cal_value* value = NULL;
-
-       retex_if(NULL == filed,,"[ERROR]calendar_svc_value_new:Invalid parameters.\n");
-
-       value = (cal_value*)malloc(sizeof(cal_value));
-       retex_if(NULL == value,,"[ERROR]calendar_svc_value_new:Failed to malloc!\n");
-
-       memset(value,0x00,sizeof(cal_value));
-
-       if(0 == strcmp(CAL_VALUE_LST_ATTENDEE_LIST,filed))
-       {
-               value->v_type = CAL_EVENT_PATICIPANT;
-               value->user_data = (cal_participant_info_t*)malloc(sizeof(cal_participant_info_t));
-               retex_if(NULL == value->user_data,,"[ERROR]calendar_svc_value_new:Fail to malloc!\n");
-
-               memset(value->user_data,0,sizeof(cal_participant_info_t));
-       }
-       else if(0 == strcmp(CAL_VALUE_LST_ALARM,filed))
-       {
-               value->v_type = CAL_EVENT_ALARM;
-               value->user_data = (cal_alarm_info_t*)malloc(sizeof(cal_alarm_info_t));
-               retex_if(NULL == value->user_data,,"[ERROR]calendar_svc_value_new:Fail to malloc!\n");
-
-               memset(value->user_data,0,sizeof(cal_alarm_info_t));
-       }
-       else
-       {
-               CAL_FREE(value);
-
-               retex_if(true,,"[ERROR]calendar_svc_value_new:Invalid parameter!\n");
-       }
-       DBG("- calendar_svc_value_new\n");
-       return value;
-
-CATCH:
-
-       CAL_FREE(value);
-
-
-       return NULL;
-}
-
-static int calendar_svc_free_participant(cal_participant_info_t* value)
-{
-       CALS_FN_CALL;
-       if(NULL == value)
-       {
-               return CAL_SUCCESS;
-       }
-
-       CAL_FREE(value->attendee_name);
-       CAL_FREE(value->attendee_email);
-       CAL_FREE(value->attendee_number);
-       CAL_FREE(value);
-
-
-       return CAL_SUCCESS;
-}
-
-static int calendar_svc_free_alarm_info(cal_alarm_info_t* value)
-{
-       CALS_FN_CALL;
-
-       if(value) {
-               free(value->alarm_tone);
-               free(value->alarm_description);
-               free(value);
-       }
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_value_free (cal_value **value)
-{
-       CALS_FN_CALL;
-       retex_if(NULL == value,,"[ERROR]calendar_svc_value_free:Invalid parameter!\n");
-       retex_if(NULL == *value,,"[ERROR]calendar_svc_value_free:Invalid parameter!\n");
-
-       switch((*value)->v_type)
-       {
-       case CAL_EVENT_PATICIPANT:
-               calendar_svc_free_participant((cal_participant_info_t*)(*value)->user_data);
-               break;
-
-       case CAL_EVENT_ALARM:
-               calendar_svc_free_alarm_info((cal_alarm_info_t*)(*value)->user_data);
-               break;
-
-       default:
-               break;
-       }
-
-       CAL_FREE((*value));
-
-
-       return CAL_SUCCESS;
-
-CATCH:
-
-       return CAL_ERR_FAIL;
-
-}
-
-
-API int calendar_svc_value_set_int (cal_value *value, const char *field, int intval)
-{
-       cal_participant_info_t *participant = NULL;
-       cal_alarm_info_t *alarm_info = NULL;
-
-       if (!value || !value->user_data || !field || !*field) {
-               ERR("Invalid parameter");
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       switch(value->v_type)
-       {
-       case CAL_EVENT_PATICIPANT:
-
-               participant = (cal_participant_info_t*)value->user_data;
-
-               if(0 == strcmp(field,CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS))
-               {
-                       participant->attendee_status = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ATTENDEE_DETAIL_TYPE))
-               {
-                       participant->attendee_type = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ATTENDEE_DETAIL_CT_INDEX))
-               {
-                       participant->attendee_ct_index = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ATTENDEE_ROLE))
-               {
-                       participant->attendee_role = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ATTENDEE_RSVP))
-               {
-                       participant->attendee_rsvp = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_DETAIL_DELETE))
-               {
-                       participant->is_deleted= intval;
-               }
-               else
-               {
-                       ERR("Invalid field (%s)", field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-       case CAL_EVENT_ALARM:
-               alarm_info = (cal_alarm_info_t*)value->user_data;
-               if(0 == strcmp(field,CAL_VALUE_INT_ALARMS_TICK))
-               {
-                       alarm_info->remind_tick = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ALARMS_TICK_UNIT))
-               {
-                       alarm_info->remind_tick_unit = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ALARMS_TYPE))
-               {
-                       alarm_info->alarm_type = intval;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ALARMS_ID))
-               {
-                       alarm_info->alarm_id = intval;
-               }
-               else
-               {
-                       ERR("Invalid field (%s)", field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       default:
-               ERR("Invalid value type (%d)", value->v_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_value_set_lli(cal_value *value, const char *field, long long int llival)
-{
-       cal_alarm_info_t *alarm_info;
-
-       if (!field || !*field)
-               return CAL_ERR_ARG_NULL;
-
-       switch(value->v_type)
-       {
-       case CAL_EVENT_ALARM:
-               alarm_info = (cal_alarm_info_t *)value->user_data;
-               if (!strcmp(field, CAL_VALUE_LLI_ALARMS_TIME))
-                       alarm_info->alarm_time = llival;
-               else {
-                       ERR("Invalid field (%s) in alarm value", field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-       default:
-               ERR("Invalid value type (%d)", value->v_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       return CAL_SUCCESS;
-}
-
-API long long int calendar_svc_value_get_lli(cal_value *value, const char *field)
-{
-       cal_alarm_info_t *alarm_info;
-
-       switch(value->v_type)
-       {
-       case CAL_EVENT_ALARM:
-               alarm_info = (cal_alarm_info_t*)value->user_data;
-               if(!strcmp(field,CAL_VALUE_LLI_ALARMS_TIME))
-                       return alarm_info->alarm_time;
-               else {
-                       ERR("Invalid field (%s) in alarm value", field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-       default:
-               ERR("Invalid value type (%d)", value->v_type);
-               return CAL_ERR_ARG_INVALID;
-       }
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_value_set_str (cal_value *value, const char *field, const char *strval)
-{
-       retex_if(NULL == value || NULL == value->user_data || NULL == field || NULL == strval,,"[ERROR]calendar_svc_value_free:Invalid parameter!\n");
-
-       cal_participant_info_t* participant = NULL;
-       cal_alarm_info_t *alarm_info = NULL;
-
-       int str_len = strlen(strval)+1;
-
-       switch(value->v_type)
-       {
-       case CAL_EVENT_PATICIPANT:
-
-               participant = (cal_participant_info_t*)value->user_data;
-
-               if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME))
-               {
-                       CAL_FREE(participant->attendee_name);
-
-
-                       participant->attendee_name = (char*)malloc(str_len);
-                       retex_if(NULL == participant->attendee_name,,"[ERROR]calendar_svc_value_set_str:Failed to malloc!\n");
-
-                       memset(participant->attendee_name,0x00,str_len);
-
-                       strcpy(participant->attendee_name,strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL))
-               {
-                       CAL_FREE(participant->attendee_email);
-
-
-                       participant->attendee_email = (char*)malloc(str_len);
-                       retex_if(NULL == participant->attendee_email,,"[ERROR]calendar_svc_value_set_str:Failed to malloc!\n");
-
-                       memset(participant->attendee_email,0x00,str_len);
-
-                       strcpy(participant->attendee_email,strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_DETAIL_NUMBER))
-               {
-                       CAL_FREE(participant->attendee_number);
-
-
-                       participant->attendee_number = (char*)malloc(str_len);
-                       retex_if(NULL == participant->attendee_number,,"[ERROR]calendar_svc_value_set_str:Failed to malloc!\n");
-
-                       memset(participant->attendee_number,0x00,str_len);
-
-                       strcpy(participant->attendee_number,strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_GROUP))
-               {
-                       CAL_FREE(participant->attendee_group);
-
-
-                       participant->attendee_group = (char*)malloc(str_len);
-                       retex_if(NULL == participant->attendee_group,,"[ERROR]calendar_svc_value_set_str:Failed to malloc!\n");
-
-                       memset(participant->attendee_group,0x00,str_len);
-
-                       strcpy(participant->attendee_group,strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_DELEGATOR_URI))
-               {
-                       CAL_FREE(participant->attendee_delegator_uri);
-
-
-                       participant->attendee_delegator_uri = (char*)malloc(str_len);
-                       retex_if(NULL == participant->attendee_delegator_uri,,"[ERROR]calendar_svc_value_set_str:Failed to malloc!\n");
-
-                       memset(participant->attendee_delegator_uri,0x00,str_len);
-
-                       strcpy(participant->attendee_delegator_uri,strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_DELEGATE_URI))
-               {
-                       CAL_FREE(participant->attendee_delegate_uri);
-
-
-                       participant->attendee_delegate_uri = (char*)malloc(str_len);
-                       retex_if(NULL == participant->attendee_delegate_uri,,"[ERROR]calendar_svc_value_set_str:Failed to malloc!\n");
-
-                       memset(participant->attendee_delegate_uri,0x00,str_len);
-
-                       strcpy(participant->attendee_delegate_uri,strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_UID))
-               {
-                       CAL_FREE(participant->attendee_uid);
-
-
-                       participant->attendee_uid = (char*)malloc(str_len);
-                       retex_if(NULL == participant->attendee_uid,,"[ERROR]calendar_svc_value_set_str:Failed to malloc!\n");
-
-                       memset(participant->attendee_uid,0x00,str_len);
-
-                       strcpy(participant->attendee_uid,strval);
-               }
-
-               else
-               {
-               }
-               break;
-       case CAL_EVENT_ALARM:
-
-               alarm_info = (cal_alarm_info_t*)value->user_data;
-
-               if(0 == strcmp(field,CAL_VALUE_TXT_ALARMS_TONE))
-               {
-                       CAL_FREE(alarm_info->alarm_tone);
-
-
-                       alarm_info->alarm_tone = (char*)malloc(str_len);
-                       retex_if(NULL == alarm_info->alarm_tone,,"[ERROR]calendar_svc_value_set_str:Failed to malloc!\n");
-
-                       memset(alarm_info->alarm_tone,0x00,str_len);
-
-                       strcpy(alarm_info->alarm_tone,strval);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ALARMS_DESCRIPTION))
-               {
-                       CAL_FREE(alarm_info->alarm_description);
-
-                       alarm_info->alarm_description = (char *)malloc(str_len);
-                       retex_if(NULL == alarm_info->alarm_description,,"[ERROR]calendar_svc_value_set_str:Failed to malloc!\n");
-
-                       memset(alarm_info->alarm_description,0x00,str_len);
-
-                       strcpy(alarm_info->alarm_description,strval);
-               }
-               break;
-       default:
-               break;
-       }
-
-       return CAL_SUCCESS;
-
-CATCH:
-
-       return CAL_ERR_FAIL;
-
-}
-
-API int calendar_svc_value_get_int (cal_value *value, const char *field)
-{
-       cal_participant_info_t* participant = NULL;
-       cal_alarm_info_t* alarm_info = NULL;
-
-       if (!value || !value->user_data || !field || !*field) {
-               ERR("Invalid parameter");
-               return 0;
-       }
-
-       switch(value->v_type)
-       {
-       case CAL_EVENT_PATICIPANT:
-
-               participant = (cal_participant_info_t*)value->user_data;
-
-               if(0 == strcmp(field,CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS))
-               {
-                       return (participant->attendee_status);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ATTENDEE_DETAIL_TYPE))
-               {
-                       return (participant->attendee_type);
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ATTENDEE_DETAIL_CT_INDEX))
-               {
-                       return participant->attendee_ct_index;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ATTENDEE_ROLE))
-               {
-                       return participant->attendee_role;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ATTENDEE_RSVP))
-               {
-                       return participant->attendee_rsvp;
-               }
-               else
-               {
-               }
-               break;
-       case CAL_EVENT_ALARM:
-               alarm_info = (cal_alarm_info_t*)value->user_data;
-               if(0 == strcmp(field,CAL_VALUE_INT_ALARMS_TICK))
-               {
-                       return alarm_info->remind_tick;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ALARMS_TICK_UNIT))
-               {
-                       return alarm_info->remind_tick_unit;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ALARMS_TYPE))
-               {
-                       return alarm_info->alarm_type;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_INT_ALARMS_ID))
-               {
-                       return alarm_info->alarm_id;
-               }
-               break;
-       default:
-               break;
-       }
-
-       return 0;
-}
-
-API char * calendar_svc_value_get_str (cal_value *value, const char *field)
-{
-       CALS_FN_CALL;
-       cal_participant_info_t* participant = NULL;
-       cal_alarm_info_t * alarm_info = NULL;
-
-       if (!value || !value->user_data || !field || !*field) {
-               ERR("Invalid parameter");
-               return NULL;
-       }
-
-       switch(value->v_type)
-       {
-       case CAL_EVENT_PATICIPANT:
-
-               participant = (cal_participant_info_t*)value->user_data;
-
-               if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME))
-               {
-                       return participant->attendee_name;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL))
-               {
-                       return participant->attendee_email;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_DETAIL_NUMBER))
-               {
-                       return participant->attendee_number;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_GROUP))
-               {
-                       return participant->attendee_group;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_DELEGATOR_URI))
-               {
-                       return participant->attendee_delegator_uri;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_DELEGATE_URI))
-               {
-                       return participant->attendee_delegate_uri;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ATTENDEE_UID))
-               {
-                       return participant->attendee_uid;
-               }
-               break;
-       case CAL_EVENT_ALARM:
-
-               alarm_info = (cal_alarm_info_t*)value->user_data;
-
-               if(0 == strcmp(field,CAL_VALUE_TXT_ALARMS_TONE))
-               {
-                       return alarm_info->alarm_tone;
-               }
-               else if(0 == strcmp(field,CAL_VALUE_TXT_ALARMS_DESCRIPTION))
-               {
-                       return alarm_info->alarm_description;
-               }
-               break;
-       default:
-               break;
-       }
-
-       return NULL;
-}
-
-API long long int calendar_svc_struct_get_lli(cal_struct *event, const char *field)
-{
-       cal_sch_full_t *sch_rec = NULL;
-       cals_struct_period_normal_onoff *nof = NULL;
-       cals_struct_period_normal_basic *nbs = NULL;
-       cals_struct_period_normal_osp *nosp = NULL;
-       cals_struct_period_normal_location *nosl = NULL;
-       cals_struct_period_normal_alarm *nosa = NULL;
-
-       retv_if(NULL == event || NULL == event->user_data, 0);
-       retv_if(NULL == field, 0);
-
-       switch(event->event_type)
-       {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-       case CAL_STRUCT_TYPE_TODO:
-               sch_rec = (cal_sch_full_t*)event->user_data;
-
-               if (0 == strcmp(field, CALS_VALUE_LLI_DTSTART_UTIME))
-                       return sch_rec->dtstart_utime;
-               else if (0 == strcmp(field, CALS_VALUE_LLI_DTEND_UTIME))
-                       return sch_rec->dtend_utime;
-               else if (0 == strcmp(field, CALS_VALUE_LLI_LASTMOD))
-                       return sch_rec->last_mod;
-               else if (0 == strcmp(field, CALS_VALUE_LLI_RRULE_UNTIL_UTIME))
-                       return sch_rec->until_utime;
-               else if(0 == strcmp(field,CAL_VALUE_LLI_CREATED_TIME))
-                       return sch_rec->created_time;
-               else if(0 == strcmp(field,CAL_VALUE_LLI_COMPLETED_TIME))
-                       return sch_rec->completed_time;
-               else
-                       ERR("Can not find the field(%s)",field);
-               break;
-
-       case CAL_STRUCT_TYPE_CALENDAR:
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_ONOFF:
-               nof = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ONOFF_LLI_DTSTART_UTIME))
-                       return nof->dtstart_utime;
-               else
-                       ERR("Can't find field(%s)", field);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_BASIC:
-               nbs = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_LLI_DTSTART_UTIME))
-                       return nbs->dtstart_utime;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_LLI_DTEND_UTIME))
-                       return nbs->dtend_utime;
-               else
-                       ERR("Can't find field(%s)", field);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_OSP:
-               nosp = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_LLI_DTSTART_UTIME))
-                       return nosp->dtstart_utime;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_LLI_DTEND_UTIME))
-                       return nosp->dtend_utime;
-               else
-                       ERR("Can't find field(%s)", field);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_LOCATION:
-               nosl = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_LLI_DTSTART_UTIME))
-                       return nosl->dtstart_utime;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_LLI_DTEND_UTIME))
-                       return nosl->dtend_utime;
-               else
-                       ERR("Can't find field(%s)", field);
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_ALARM:
-               nosa = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_LLI_DTSTART_UTIME))
-                       return nosa->dtstart_utime;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_LLI_DTEND_UTIME))
-                       return nosa->dtend_utime;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_LLI_ALARM_UTIME))
-                       return nosa->alarm_utime;
-               else
-                       ERR("Can't find field(%s)", field);
-               break;
-
-       default:
-               break;
-       }
-       return 0;
-}
-
-API int calendar_svc_struct_set_lli(cal_struct *event, const char *field, long long int value)
-{
-       cal_sch_full_t *sch_rec = NULL;
-       cals_struct_period_normal_onoff *nof = NULL;
-       cals_struct_period_normal_basic *nbs = NULL;
-       cals_struct_period_normal_osp *nosp = NULL;
-       cals_struct_period_normal_location *nosl = NULL;
-       cals_struct_period_normal_alarm *nosa = NULL;
-
-       retv_if(NULL == event || NULL == event->user_data, CAL_ERR_ARG_NULL);
-
-       switch(event->event_type)
-       {
-       case CAL_STRUCT_TYPE_SCHEDULE:
-       case CAL_STRUCT_TYPE_TODO:
-
-               sch_rec = (cal_sch_full_t*)event->user_data;
-
-               if (0 == strcmp(field, CALS_VALUE_LLI_DTSTART_UTIME))
-                       sch_rec->dtstart_utime = value;
-               else if (0 == strcmp(field, CALS_VALUE_LLI_DTEND_UTIME))
-                       sch_rec->dtend_utime = value;
-               else if (0 == strcmp(field, CALS_VALUE_LLI_LASTMOD))
-                       sch_rec->last_mod = value;
-               else if (0 == strcmp(field, CALS_VALUE_LLI_RRULE_UNTIL_UTIME))
-                       sch_rec->until_utime = value;
-               else if(0 == strcmp(field,CAL_VALUE_LLI_CREATED_TIME))
-                       sch_rec->created_time = value;
-               else if(0 == strcmp(field,CAL_VALUE_LLI_COMPLETED_TIME))
-                       sch_rec->completed_time = value;
-               else
-                       return CAL_ERR_ARG_INVALID;
-               break;
-
-       case CAL_STRUCT_TYPE_CALENDAR:
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_ONOFF:
-               nof = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ONOFF_LLI_DTSTART_UTIME))
-                       nof->dtstart_utime = value;
-               else {
-                       ERR("Can't find field(%s)", field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_BASIC:
-               nbs = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_LLI_DTSTART_UTIME))
-                       nbs->dtstart_utime = value;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_BASIC_LLI_DTEND_UTIME))
-                       nbs->dtend_utime = value;
-               else {
-                       ERR("Can't find field(%s)", field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_OSP:
-               nosp = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_LLI_DTSTART_UTIME))
-                       nosp->dtstart_utime = value;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_OSP_LLI_DTEND_UTIME))
-                       nosp->dtend_utime = value;
-               else {
-                       ERR("Can't find field(%s)", field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_LOCATION:
-               nosl = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_LLI_DTSTART_UTIME))
-                       nosl->dtstart_utime = value;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_LOCATION_LLI_DTEND_UTIME))
-                       nosl->dtend_utime = value;
-               else {
-                       ERR("Can't find field(%s)", field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       case CALS_STRUCT_TYPE_PERIOD_NORMAL_ALARM:
-               nosa = event->user_data;
-               if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_LLI_DTSTART_UTIME))
-                       nosa->dtstart_utime = value;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_LLI_DTEND_UTIME))
-                       nosa->dtend_utime = value;
-               else if (!strcmp(field, CALS_LIST_PERIOD_NORMAL_ALARM_LLI_ALARM_UTIME))
-                       nosa->alarm_utime = value;
-               else {
-                       ERR("Can't find field(%s)", field);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               break;
-
-       default:
-               break;
-       }
-
-       return CAL_SUCCESS;
-}
-
-
diff --git a/src/cals-time.c b/src/cals-time.c
deleted file mode 100644 (file)
index b2d8602..0000000
+++ /dev/null
@@ -1,291 +0,0 @@
-#include <unicode/ucal.h>
-#include <unicode/ustring.h>
-#include <unicode/ustdio.h>
-#include <unicode/udat.h>
-#include <stdlib.h>
-#include "cals-time.h"
-#include "calendar-svc-provider.h"
-#include "cals-internal.h"
-
-#define ms2sec(ms) (long long int)(ms / 1000.0)
-#define sec2ms(s) (s * 1000.0)
-
-static UCalendar *_ucal_get_cal(const char *tzid)
-{
-       UCalendar *cal;
-       UErrorCode status = U_ZERO_ERROR;
-       UChar *_tzid;
-
-       _tzid = NULL;
-
-       if (tzid) {
-               _tzid = (UChar*)malloc(sizeof(UChar) * (strlen(tzid) +1));
-               if (_tzid)
-                       u_uastrcpy(_tzid, tzid);
-               else
-                       ERR("malloc failed");
-       }
-
-       cal = ucal_open(_tzid, u_strlen(_tzid), "en_US", UCAL_TRADITIONAL, &status);
-       if (_tzid)
-               free(_tzid);
-
-       if (U_FAILURE(status)) {
-               ERR("ucal_open failed (%s)", u_errorName(status));
-               return NULL;
-       }
-       return cal;
-}
-
-static void _ucal_set_time(UCalendar *cal, struct cals_time *t)
-{
-       UErrorCode status = U_ZERO_ERROR;
-
-       if (t->type == CALS_TIME_UTIME) {
-               ucal_setMillis(cal, sec2ms(t->utime), &status);
-               if (U_FAILURE(status)) {
-                       ERR("ucal_setMillis failed (%s)", u_errorName(status));
-                       return;
-               }
-       } else if (t->type == CALS_TIME_LOCALTIME) {
-               ucal_setDateTime(cal, t->year, t->month - 1, t->mday, 0, 0, 0, &status);
-               if (U_FAILURE(status)) {
-                       ERR("ucal_setDate failed (%s)", u_errorName(status));
-                       return;
-               }
-       } else
-               ERR("Invalid dtstart type. Current time is used in default");
-}
-
-long long int cals_time_diff(struct cals_time *st, struct cals_time *et)
-{
-       UErrorCode status = U_ZERO_ERROR;
-       UCalendar *cal;
-       UDate ud;
-       int dr;
-       if (st->type == CALS_TIME_UTIME)
-               return et->utime - st->utime;
-
-       cal = _ucal_get_cal(et->tzid);
-
-       _ucal_set_time(cal, et);
-
-       ud = ucal_getMillis(cal, &status);
-
-       _ucal_set_time(cal, st);
-
-       dr = ucal_getFieldDifference(cal, ud, UCAL_DATE, &status);
-       if (U_FAILURE(status)) {
-               ERR("ucal_getFieldDifference failed (%s)", u_errorName(status));
-               return 0;
-       }
-
-       ucal_close(cal);
-
-       return dr;
-}
-
-long long int cals_time_diff_with_now(struct cals_time *t)
-{
-       long long int now;
-       UErrorCode status = U_ZERO_ERROR;
-       UCalendar *cal;
-       UDate ud;
-
-       if (t->type == CALS_TIME_UTIME) {
-               DBG("alarm utime diff (%lld) - (%lld)", t->utime, ms2sec(ucal_getNow()));
-               return t->utime - ms2sec(ucal_getNow());
-       }
-
-       cal = _ucal_get_cal(t->tzid);
-       _ucal_set_time(cal, t);
-       ud = ucal_getMillis(cal, &status);
-       ucal_close(cal);
-       now = ms2sec(ucal_getNow());
-       DBG("alarm allday diff (%lld) - (%lld) ", ms2sec(ud), now);
-       return ms2sec(ud) - now ;
-}
-
-char *cals_time_get_str_datetime(char *tzid, long long int t)
-{
-       UErrorCode status = U_ZERO_ERROR;
-       UCalendar *cal;
-       int y, mon, d, h, m, s;
-       char buf[17] = {0};
-
-       if (tzid == NULL) {
-               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;
-       d = ucal_get(cal, UCAL_DATE, &status);
-       h = ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
-       m = ucal_get(cal, UCAL_MINUTE, &status);
-       s = ucal_get(cal, UCAL_SECOND, &status);
-
-       snprintf(buf, sizeof(buf),
-                       "%04d%02d%02dT%02d%02d%02dZ",
-                       y, mon, d, h, m, s);
-       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;
-       UCalendar *cal;
-       UErrorCode status = U_ZERO_ERROR;
-       UChar *_tzid;
-
-       _tzid = NULL;
-
-       if (ct->tzid) {
-               _tzid = (UChar*)malloc(sizeof(UChar) * (strlen(ct->tzid) +1));
-               if (_tzid)
-                       u_uastrcpy(_tzid, ct->tzid);
-               else
-                       ERR("malloc failed");
-       }
-DBG("tzid(%s)", ct->tzid);
-       cal = ucal_open(_tzid, u_strlen(_tzid), "en_US", UCAL_TRADITIONAL, &status);
-       if (_tzid)
-               free(_tzid);
-
-       if (U_FAILURE(status)) {
-               ERR("ucal_open failed (%s)", u_errorName(status));
-               return -1;
-       }
-
-       ucal_set(cal, UCAL_YEAR, ct->year);
-       ucal_set(cal, UCAL_MONTH, ct->month - 1);
-       ucal_set(cal, UCAL_DATE, ct->mday);
-       ucal_set(cal, UCAL_HOUR, 0);
-       ucal_set(cal, UCAL_MINUTE, 0);
-       ucal_set(cal, UCAL_SECOND, 0);
-
-       lli = (long long int)(ms2sec(ucal_getMillis(cal, &status)));
-
-       ucal_close(cal);
-       DBG("%04d/%02d/%02d %02d:%02d:%03d", ct->year, ct->month, ct->mday, 0, 0, 0);
-       DBG("%lld", lli);
-       return lli;
-}
-
-
-long long int cals_time_date_to_utime(const char *tzid,
-               int year, int month, int mday, int hour, int minute, int second)
-{
-       UCalendar *cal;
-       UErrorCode status = U_ZERO_ERROR;
-       //UChar *_tzid;
-       long long int lli;
-
-       cal = _ucal_get_cal(tzid);
-
-       ucal_set(cal, UCAL_YEAR, year);
-       ucal_set(cal, UCAL_MONTH, month - 1);
-       ucal_set(cal, UCAL_DATE, mday);
-       ucal_set(cal, UCAL_HOUR, hour);
-       ucal_set(cal, UCAL_MINUTE, minute);
-       ucal_set(cal, UCAL_SECOND, second);
-
-       lli = ms2sec(ucal_getMillis(cal, &status));
-       if (U_FAILURE(status)) {
-               ERR("ucal_open failed (%s)", u_errorName(status));
-               ucal_close(cal);
-               return -1;
-       }
-       ucal_close(cal);
-       return lli;
-}
-
-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
diff --git a/src/cals-time.h b/src/cals-time.h
deleted file mode 100644 (file)
index 7850250..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef __CALENDAR_SVC_TIME_H__
-#define __CALENDAR_SVC_TIME_H__
-
-struct cals_time {
-       int type;
-       long long int utime;
-       int year;
-       int month;
-       int mday;
-       char tzid[15];
-};
-
-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);
-
-#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
diff --git a/src/cals-todo.c b/src/cals-todo.c
deleted file mode 100755 (executable)
index 328896c..0000000
+++ /dev/null
@@ -1,470 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <errno.h>
-
-#include "cals-internal.h"
-#include "cals-typedef.h"
-#include "cals-sqlite.h"
-#include "cals-db-info.h"
-#include "cals-db.h"
-#include "cals-utils.h"
-#include "cals-schedule.h"
-
-static const char *_todo_list_order[] = {
-       [CALS_TODO_LIST_ORDER_END_DATE] = "dtend_utime DESC",
-       [CALS_TODO_LIST_ORDER_PRIORITY] = "priority DESC, dtend_utime DESC",
-       [CALS_TODO_LIST_ORDER_STATUS] = "task_status ASC, dtend_utime DESC",
-};
-
-static inline const char *cals_todo_get_order(cals_todo_list_order_t order)
-{
-       return _todo_list_order[order];
-}
-
-static int __todo_get_query_priority(int priority, char *query, int len)
-{
-       switch (priority) {
-       case CALS_TODO_PRIORITY_NONE: // 0x01
-               snprintf(query, len, "AND priority = %d ", 0);
-               break;
-
-       case CALS_TODO_PRIORITY_HIGH: // 0x020
-               snprintf(query, len, "AND priority < %d ", CALS_TODO_PRIORITY_MID);
-               break;
-
-       case CALS_TODO_PRIORITY_MID: // 0x04
-               snprintf(query, len, "AND priority = %d ", CALS_TODO_PRIORITY_MID);
-               break;
-
-       case CALS_TODO_PRIORITY_LOW: // 0x08
-               snprintf(query, len, "AND priority > %d ", CALS_TODO_PRIORITY_MID);
-               break;
-
-       case 0x03: /* NONE | HIGH */
-               snprintf(query, len, "AND (priority = %d OR priority < %d) ", 0, CALS_TODO_PRIORITY_MID);
-               break;
-
-       case 0x05: /* NONE | MID */
-               snprintf(query, len, "AND (priority = %d OR priority = %d) ", 0, CALS_TODO_PRIORITY_MID);
-               break;
-
-       case 0x09: /* NONE | LOW */
-               snprintf(query, len, "AND (priority = %d OR priority > %d) ", 0, CALS_TODO_PRIORITY_MID);
-               break;
-
-       case 0x06: /* HIGH |MID */
-               snprintf(query, len, "AND priority > %d AND priority <= %d ", 0, CALS_TODO_PRIORITY_MID);
-               break;
-
-       case 0x0A: /* HIGH |LOW */
-               snprintf(query, len, "AND priority > %d AND priority != %d ", 0, CALS_TODO_PRIORITY_MID);
-               break;
-
-       case 0x0C: /* MID |LOW */
-               snprintf(query, len, "AND priority >= %d ", CALS_TODO_PRIORITY_MID);
-               break;
-
-       case 0x07: /* NONE | HIGH | MID */
-               snprintf(query, len, "AND priority <= %d ", CALS_TODO_PRIORITY_MID);
-               break;
-
-       case 0x0B: /* NONE | HIGH | LOW */
-               snprintf(query, len, "AND priority <> %d ", CALS_TODO_PRIORITY_MID);
-               break;
-
-       case 0x0D: /* NONE | MID | LOW */
-               snprintf(query, len, "AND priority >= %d ", CALS_TODO_PRIORITY_MID);
-               break;
-
-       case 0x0E: /* HIGH | MID |LOW */
-               snprintf(query, len, "AND priority > %d ", 0);
-               break;
-
-       case 0x0F: /* NONE | HIGH | MID | LOW */
-               memset(query, 0x0, len);
-       default:
-               break;
-       }
-       return 0;
-}
-
-static int __todo_get_query_status(int status, char *query, int len)
-{
-       int i, conj;
-       char buf[64] = {0};
-
-       if (status) {
-               if (status & 0xff) {
-                       DBG("check status:%x", status);
-                       return -1;
-               }
-               conj = 0;
-               snprintf(query, len, "%s", "AND ( ");
-
-               for (i = 0; i < 5; i++) {
-                       if (status & (1 << (i + 8))) {
-                               if (conj) {
-                                       strcat(query,  "OR ");
-                                       conj = 0;
-                               }
-
-                               snprintf(buf, sizeof(buf), "task_status = %d ", (1 << (i + 8)));
-                               strcat(query,  buf);
-                               conj = 1;
-                       }
-               }
-               strcat(query,  ") ");
-
-       } else {
-               memset(query, 0x0, len);
-
-       }
-       return 0;
-}
-
-/**
- * This function gets count related with todo.
- * If parameter is invalid(0, negative, etc.), it will be ignored
- * If all parameters are invalid, this function return all todo count.
- *
- * @param[in] calendar_id calendar_id
- * @param[in] start_time start time
- * @param[in] end_time end time
- * @param[in] priority priority(0~9)
- * @param[in] status #cals_status_t
- * @return The count number on success, Negative value(#cal_error) on error
- */
-/*
-API int calendar_svc_todo_get_count(int calendar_id,
-               long long int dtstart_utime, long long int dtend_utime, int priority, cals_status_t status)
-{
-       char query[CALS_SQL_MIN_LEN];
-       char cond[CALS_SQL_MIN_LEN];
-
-       cals_todo_get_condition(calendar_id, start_time, end_time, priority, status, cond, sizeof(cond));
-
-       snprintf(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE is_deleted = 0 AND %s",
-                       CALS_TABLE_SCHEDULE, cond);
-
-       return cals_query_get_first_int_result(query);
-}
-*/
-API int calendar_svc_todo_get_list(int calendar_id, long long int dtend_from, long long int dtend_to,
-               int priority,cals_status_t status, cals_todo_list_order_t order, cal_iter **iter)
-{
-       cal_iter *it;
-       sqlite3_stmt *stmt = NULL;
-       char buf_id[256] = {0};
-       char buf_dtend_from[256] = {0};
-       char buf_dtend_to[256] = {0};
-       char buf_priority[256] = {0};
-       char buf_status[256] = {0};
-       char query[CALS_SQL_MAX_LEN];
-
-       retv_if(NULL == iter, CAL_ERR_ARG_NULL);
-       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_id, sizeof(buf_id), "AND calendar_id = %d ", calendar_id);
-       } else {
-               memset(buf_id, 0x0, sizeof(buf_id));
-       }
-
-       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 != 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));
-       }
-
-       __todo_get_query_priority(priority, buf_priority, sizeof(buf_priority));
-       __todo_get_query_status(status, buf_status, sizeof(buf_status));
-
-       snprintf(query, sizeof(query),
-                       "SELECT * FROM %s "
-                       "WHERE is_deleted = 0 AND type = %d "
-                       "%s %s %s %s %s "
-                       "ORDER BY %s",
-                       CALS_TABLE_SCHEDULE,
-                       CAL_STRUCT_TYPE_TODO,
-                       buf_id, buf_dtend_from, buf_dtend_to, buf_priority, buf_status,
-                       cals_todo_get_order(order));
-
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() Failed");
-
-       it = calloc(1, sizeof(cal_iter));
-       if (NULL == it) {
-               sqlite3_finalize(stmt);
-               ERR("calloc() Failed(%d)", errno);
-               return CAL_ERR_OUT_OF_MEMORY;
-       }
-       it->i_type = CAL_STRUCT_TYPE_TODO;
-       it->stmt = stmt;
-       *iter = it;
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_todo_search(int fields, const char *keyword, cal_iter **iter)
-{
-       int ret;
-
-       ret = cals_sch_search(CALS_SCH_TYPE_TODO, fields, keyword, iter);
-       retvm_if(ret < 0, ret, "cals_sch_search() failed(%d)", ret);
-
-       return CAL_SUCCESS;
-}
-
-static inline int cals_todo_get_changes(int calendar_id, int version, cal_iter *iter)
-{
-       char buf[64] = {0};
-       char query[CALS_SQL_MIN_LEN] = {0,};
-       sqlite3_stmt *stmt;
-       cals_updated *last;
-       cals_updated *result;
-
-       if (calendar_id > 0) {
-               snprintf(buf, sizeof(buf), "AND calendar_id = %d ", calendar_id);
-       } else {
-               memset(buf, 0x0, sizeof(buf));
-       }
-
-       snprintf(query, sizeof(query),
-                       "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, 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,
-                       CALS_TABLE_DELETED,
-                       version, CALS_SCH_TYPE_TODO, buf);
-
-       DBG("query(%s)", query);
-       stmt = cals_query_prepare(query);
-       retvm_if (NULL == stmt, CAL_ERR_DB_FAILED, "cals_query_prepare() failed.");
-
-       while (CAL_TRUE == cals_stmt_step(stmt)){
-               result = cals_updated_schedule_add_mempool();
-
-               result->id = sqlite3_column_int(stmt, 0);
-               result->ver = sqlite3_column_int(stmt, 1);
-               if (sqlite3_column_int(stmt, 3) == 1) {
-                       result->type = CALS_UPDATED_TYPE_DELETED;
-               } else if (sqlite3_column_int(stmt, 2) != result->ver) {
-                       result->type = CALS_UPDATED_TYPE_MODIFIED;
-               } else {
-                       result->type = CALS_UPDATED_TYPE_INSERTED;
-               }
-
-               result->calendar_id = sqlite3_column_int(stmt, 4);
-
-               if (iter->info->head == NULL) {
-                       iter->info->head = result;
-               } else {
-                       last->next = result;
-               }
-               last = result;
-       }
-       iter->i_type = CAL_STRUCT_TYPE_UPDATED_LIST;
-
-       sqlite3_finalize(stmt);
-
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_todo_get_changes(int calendar_id, int version, cal_iter **iter)
-{
-       int ret;
-       cal_iter *it;
-
-       retv_if (NULL == iter, CAL_ERR_ARG_NULL);
-       retvm_if (version < 0, CAL_ERR_ARG_INVALID, "Invalid argument");
-
-       it = calloc(1, sizeof(cal_iter));
-       retvm_if (NULL == it, CAL_ERR_OUT_OF_MEMORY, "calloc() failed");
-
-       it->info = calloc(1, sizeof(cals_updated_info));
-       if (!it->info) {
-               ERR("calloc() Failed");
-               free(it);
-               return CAL_ERR_OUT_OF_MEMORY;
-       }
-
-       ret = cals_todo_get_changes(calendar_id, version, it);
-       if (ret) {
-               ERR("cals_todo_get_changes() failed(%d", ret);
-               free(it->info);
-               free(it);
-               return ret;
-       }
-
-       *iter = it;
-
-       return CAL_SUCCESS;
-}
-
-
-API int calendar_svc_todo_get_iter(int calendar_id, int priority, int status,
-               cals_todo_list_order_t order, cal_iter **iter)
-{
-       char query[CALS_SQL_MIN_LEN] = {0};
-       char buf_id[64] = {0};
-       char buf_prio[64] = {0};
-       char buf_stat[256] = {0};
-       cal_iter *it;
-       sqlite3_stmt *stmt = NULL;
-
-       it = calloc(1, sizeof(cal_iter));
-       retvm_if(NULL == it, CAL_ERR_OUT_OF_MEMORY, "Failed to calloc(%d)", errno);
-       it->is_patched = 0;
-
-       if (calendar_id > 0) {
-               snprintf(buf_id, sizeof(buf_id), "AND calendar_id = %d ", calendar_id);
-       } else {
-               memset(buf_id, 0x0, sizeof(buf_id));
-       }
-
-       /* priority */
-       __todo_get_query_priority(priority, buf_prio, sizeof(buf_prio));
-
-       /* status */
-       __todo_get_query_status(status, buf_stat, sizeof(buf_stat));
-
-       /* dtend means due */
-       it->i_type = CAL_STRUCT_TYPE_TODO;
-       snprintf(query, sizeof(query),
-                       "SELECT * FROM %s "
-                       "WHERE type = %d %s %s %s ",
-                       CALS_TABLE_SCHEDULE,
-                       CALS_SCH_TYPE_TODO, buf_id, buf_prio, buf_stat);
-DBG("%s\n", query);
-       stmt = cals_query_prepare(query);
-       retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "Failed to query prepare");
-
-       it->stmt = stmt;
-       *iter = it;
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_todo_get_list_by_period(int calendar_id,
-               long long int due_from, long long int dueto, int priority, int status, cal_iter **iter)
-{
-       char query[CALS_SQL_MIN_LEN] = {0};
-       char buf_id[64] = {0};
-       char buf_prio[64] = {0};
-       char buf_stat[256] = {0};
-       cal_iter *it;
-       sqlite3_stmt *stmt = NULL;
-
-       it = calloc(1, sizeof(cal_iter));
-       retvm_if(NULL == it, CAL_ERR_OUT_OF_MEMORY, "Failed to calloc(%d)", errno);
-       it->is_patched = 0;
-
-       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));
-
-       /* status */
-       __todo_get_query_status(status, buf_stat, sizeof(buf_stat));
-
-       /* dtend means due */
-       it->i_type = CAL_STRUCT_TYPE_TODO;
-       snprintf(query, sizeof(query),
-                       "SELECT * FROM %s "
-                       "WHERE dtend_utime >= %lld AND dtend_utime <= %lld "
-                       "AND type = %d %s %s %s "
-                       "ORDER BY dtend_utime ",
-                       CALS_TABLE_SCHEDULE,
-                       due_from, dueto,
-                       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");
-
-       it->stmt = stmt;
-       *iter = it;
-       return CAL_SUCCESS;
-}
-
-API int calendar_svc_todo_get_count_by_period(int calendar_id,
-               long long int due_from, long long int dueto, int priority, int status, int *count)
-{
-       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};
-
-       retvm_if(priority < 0, CAL_ERR_ARG_INVALID, "Invalid argument: priorit(%d)", priority);
-       retvm_if(status < 0, CAL_ERR_ARG_INVALID, "Invalid argument: status(%d)", priority);
-
-       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));
-
-       /* status */
-       __todo_get_query_status(status, buf_stat, sizeof(buf_stat));
-
-       snprintf(query, sizeof(query),
-                       "SELECT count(*) FROM %s "
-                       "WHERE dtend_utime >= %lld AND dtend_utime <= %lld "
-                       "AND type = %d %s %s %s ",
-                       CALS_TABLE_SCHEDULE,
-                       due_from, dueto,
-                       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");
-
-       ret = cals_stmt_step(stmt);
-       if (CAL_TRUE == ret) {
-               cnt = sqlite3_column_int(stmt, 0);
-
-       } else if (CAL_SUCCESS != ret) {
-               sqlite3_finalize(stmt);
-               ERR("Failed to step(errno:%d)", ret);
-               return ret;
-       }
-       sqlite3_finalize(stmt);
-       *count = cnt;
-
-       return CAL_SUCCESS;
-}
-
diff --git a/src/cals-typedef.h b/src/cals-typedef.h
deleted file mode 100755 (executable)
index 0344abe..0000000
+++ /dev/null
@@ -1,617 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef _CALENDAR_SVC_TYPEDEF_H_
-#define _CALENDAR_SVC_TYPEDEF_H_
-
-#include <time.h>
-#include <sqlite3.h>
-
-#include "calendar-svc-provider.h"
-
-/* Definition */
-#define CALS_INVALID_ID                                (-1)
-
-#define CAL_SCH_SUMMARY_LEN_MAX                        1024//256                       /**< Summary string length of Schedule */
-#define CAL_SCH_DESCRIPTION_LEN_MAX            4096                        /**< Description string length of Schedule */
-
-#define CAL_RECORD_CNT_MAX                             2000                    /**< max record count */
-
-#define CAL_YEAR_MIN                           1900            /**< Start value of year's range */
-#define CAL_YEAR_MAX                           2037            /**< End value of year's range */
-#define CAL_MONTH_CNT_MAX                      12                      /**< max month count */
-#define CAL_MONTH_CNT_MIN                      1                       /**< min month count */
-#define CAL_DAY_CNT_MAX                                31                      /**< max day count */
-#define BENCHMARK_YEAR                         1900L           /**< tm_year's benchmark */
-#define ONE_DAY_SECONDS                                86400L          /**< seconds in a day */
-#define ONE_WEEK_SECONDS                       604800L         /**< seconds in a week */
-#define ONE_MONTH_SECONDS                      2678400L        /**< seconds in a month */
-#define ONE_YEAR_SECONDS                       31536000L       /**< seconds in a year */
-#define DAY_OF_A_WEEK                          7                       /**< days of a week */
-#define MAX_REPEAT_OF_A_WEEK           9                       /**< max repeat event count in week */
-
-#define MONTH_MAX 11
-#define MONTH_DAY_MIN 1
-#define MONTH_DAY_MAX 31
-#define MONTH_MIN 0
-
-#define TM_YEAR_MIN 0
-#define TM_YEAR_MAX 138
-
-#define BASE_TIME_YEAR 70
-
-#define CAL_EVENT_UID_MAX_COUNT                                        256                                     /**< Max count of calendar UID*/
-
-typedef enum
-{
-       CAL_STRUCT_TYPE_SCHEDULE=0,     /**< schedule type */
-       CAL_STRUCT_TYPE_CALENDAR,       /**< calendar type */
-       CAL_STRUCT_TYPE_TODO,    /**< task type   */
-       CAL_STRUCT_TYPE_TIMEZONE,
-       CAL_STRUCT_TYPE_SCHEDULE_LIST,
-       CAL_STRUCT_TYPE_TODO_LIST,
-       CAL_STRUCT_TYPE_UPDATED_LIST,
-       CALS_STRUCT_TYPE_PERIOD_NORMAL_ONOFF,
-       CALS_STRUCT_TYPE_PERIOD_ALLDAY_ONOFF,
-       CALS_STRUCT_TYPE_PERIOD_NORMAL_BASIC,
-       CALS_STRUCT_TYPE_PERIOD_ALLDAY_BASIC,
-       CALS_STRUCT_TYPE_PERIOD_NORMAL_OSP,
-       CALS_STRUCT_TYPE_PERIOD_ALLDAY_OSP,
-       CALS_STRUCT_TYPE_PERIOD_NORMAL_LOCATION,
-       CALS_STRUCT_TYPE_PERIOD_ALLDAY_LOCATION,
-       CALS_STRUCT_TYPE_PERIOD_NORMAL_ALARM,
-       CALS_STRUCT_TYPE_PERIOD_ALLDAY_ALARM
-
-} cal_struct_type;
-
-typedef enum
-{
-       CAL_EVENT_PATICIPANT = 0,       /**< CAL_STRUCT_PARTICIPANT */
-       CAL_EVENT_RECURRENCY,   /**< CAL_STRUCT_RECURRENCY */
-       CAL_EVENT_DELETE,               /**< CAL_STRUCT_DELETE */
-       CAL_EVENT_SYNC_STATUS,  /**< CAL_STRUCT_SYNC_STATUS */
-       CAL_EVENT_CALENDAR,     /**< CAL_STRUCT_CALENDAR */
-       CAL_EVENT_ALARM,
-       CAL_EVENT_MAX,
-
-} cal_data_type_t;
-
-
-#define CAL_STRUCT_UPDATED "updated"     /**< CAL_STRUCT_UPDATED */
-
-typedef struct _updated {
-       int type;
-       int id;
-       int ver;
-       int calendar_id;
-       struct _updated *next;
-} cals_updated;
-
-typedef struct {
-       cals_updated *head;
-       cals_updated *cursor;
-} cals_updated_info;
-
-struct _cal_struct {
-       cal_struct_type event_type;
-       void* user_data;
-};
-
-struct _cal_value {
-       cal_data_type_t v_type;
-       void* user_data;
-};
-
-struct _cal_iter {
-       int i_type;
-       sqlite3_stmt *stmt;
-       int is_patched;
-       cals_updated_info *info;
-};
-
-typedef struct
-{
-       int localtime_offset;
-       int local_dst_offset;
-       char local_tz_id[50];
-       struct tm start_local_dst_date_time;
-       struct tm start_local_std_date_time;
-
-       int temptime_offset;
-       int temp_dst_offset;
-       char temp_tz_id[50];
-       struct tm start_temp_dst_date_time;
-       struct tm start_temp_std_date_time;
-
-       int is_initialize;
-       int is_used_calendar_tz;
-} cal_svc_tm_info_t;
-
-typedef enum
-{
-       CALS_NOTI_TYPE_EVENT = 0x0,
-       CALS_NOTI_TYPE_TODO,
-       CALS_NOTI_TYPE_CALENDAR,
-}cals_noti_type;
-
-/**
- * @enum cal_record_sort_t
- * This enumeration defines record sort type.
- */
-typedef enum
-{
-       CAL_SORT_BY_ID = 0,                     /**< get reocrds sort by id */
-       CAL_SORT_BY_START_DATE,         /**< get reocrds sort by start time */
-       CAL_SORT_BY_END_DATE,           /**< get reocrds sort by end time */
-       CAL_SORT_BY_MODIFIED_DATE,      /**< get reocrds sort by modified time */
-       CAL_SORT_BY_STATUS,                     /**< get reocrds sort by status */
-       CAL_SORT_BY_PRIORITY_TIME_ALPHABET,                     /**< get reocrds sort by priority->time->alphabet */
-       CAL_SORT_BY_PRIORITY,                   /**< get reocrds sort by priority */
-
-} cal_record_sort_t;
-
-/**
- * @enum cal_record_asc_desc_t
- * This enumeration defines event sort type.
- */
-typedef enum
-{
-       CAL_SORT_ASC =0,                                                /**< asc sort type */
-       CAL_SORT_DESC                                                   /**< desc sort type */
-}cal_record_asc_desc_t;
-
-/**
- * @enum calendar_type_t
- * This enumeration defines calendar type.
- */
-typedef enum
-{
-       CAL_ALL_CALENDAR =0,                                    /**< all calendar type */
-       CAL_PHONE_CALENDAR,                                             /**< phone calendar type */
-       CAL_ACTIVESYNC_CALENDAR,                                /**< activesync calendar type*/
-       CAL_GOOGLE_CALENDAR                                             /**< google calendar type*/
-}calendar_type_t;
-
-/**
- * @enum cal_type_t
- * This enumeration defines calendar event type.
- */
-typedef enum
-{
-       CALS_SCH_TYPE_NONE=0,                   /**< None type */
-       CALS_SCH_TYPE_EVENT,    /**< schedule event type */
-       CALS_SCH_TYPE_TODO,             /**< task event type */
-       CALS_SCH_TYPE_MAX,              /**< max type */
-} cals_sch_type;
-
-
-/**
- * @enum cal_vCal_ver_t
- * This enumeration defines vCalendar version.
- */
-typedef enum
-{
-       CAL_VCAL_VER_1_0 = 0,   /**< vCalendar ver 1.0 */
-       CAL_VCAL_VER_2_0,               /**< vCalendar ver 2.0 */
-       CAL_VCAL_VER_UNKNOWN    /**< vCalendar ver unknown */
-} cal_vCal_ver_t;
-
-/**
- * @enum cal_filter_t
- * This enumeration defines filter type for todo data.
- */
-typedef enum
-{
-       CAL_TODO_FILTER_UNDONE = 1,                                             /**< todo condition is undone */
-       CAL_TODO_FILTER_DONE = 2,                                                       /**< todo condition is done */
-       CAL_TODO_FILTER_OVER_DUE = 4,                                           /**< todo condition is duration */
-       CAL_TODO_FILTER_UNDONE_AND_DONE =3,                             /**< todo condition is undone and done */
-       CAL_TODO_FILTER_UNDONE_AND_OVER_DUE = 5,                        /**< todo condition is undone and overdue */
-       CAL_TODO_FILTER_DONE_AND_OVER_DUE = 6,                          /**< todo condition is done and overdue */
-       CAL_TODO_FILTER_ALL = 7,                                                                /**< todo condition is all */
-
-       CAL_TODO_FILTER_MAX = CAL_TODO_FILTER_ALL
-}cal_filter_t;
-
-/**
- * @enum cal_priority_t
- * This enumeration defines priority for todo data.
- */
-typedef enum
-{
-       CAL_PRIORITY_LOW,       /**< priority low */
-       CAL_PRIORITY_MID,       /**< priority middle */
-       CAL_PRIORITY_HIGH       /**< priority high */
-}cal_priority_t;
-
-
-/**
- * @enum cal_starting_day_type_t
- * This enumeration defines starting day.
- */
-typedef enum
-{
-       CAL_STARTING_DAY_SUNDAY=0,      /**< starting day is sunday */
-       CAL_STARTING_DAY_MONDAY         /**< starting day is monday */
-} cal_starting_day_type_t;
-
-/**
- * This structure defines schedule information.
- */
-typedef struct
-{
-       int index;                              /**< Record index */
-       int account_id;                 /**< Account_id */
-       cals_sch_type cal_type;                 /**< Calendar event type */
-
-       char *summary;                  /**< Summary, appointment, task: subject, birthday:Name */
-       char *description;              /**< Description,appointment, task: description, anniversary,holiday:occasion*/
-       char *location;                 /**< Location */
-       char *categories;
-       char *exdate;
-       GList *alarm_list;
-       bool missed;                            /**< Miss alarm flag */
-       cals_status_t task_status;              /**< current task status */
-       cal_priority_t priority;                /**< Priority */
-       int timezone;                   /**< timezone of task */
-       int file_id;                    /**< file id for attach or alarm tone*/
-       int contact_id;                 /**< contact id for birthday in contact list */
-       GList *attendee_list;   /**< collection of attendee */
-       int busy_status;                /**< ACS, G : Flag of busy or not */
-       int sensitivity;                /**< ACS, G : The sensitivity (public, private, confidential). #cal_visibility_type_t*/
-       int meeting_status;             /**< ACS, G : The status of the meeting. */
-       char *uid;                              /**< ACS, G : Unique ID of the meeting item */
-       char *organizer_name;           /**< ACS, G : Name of organizer(author) */
-       char *organizer_email;  /**< ACS, G : Email of organizer */
-       calendar_type_t calendar_type;          /**< ACS, G : Type(all,phone,google) of calendar */
-       char *gcal_id;                  /**< G : Server id of calendar */
-       char *updated;                  /**< G : Updated time stamp */
-       int location_type;              /**< G : Location type */
-       char *location_summary; /**< G : A simple string value that can be used as a representation of this location */
-       char *etag;                             /**< G : ETAG of this event */
-       int calendar_id;                        /**< G : id to map from calendar table */
-       cal_sync_status_t sync_status;          /**< G : Indication for event entry whether added/ modified/ deleted */
-       char *edit_uri;      /**< G : EditUri for google calendar */
-       char *gevent_id;                        /**< G : Server id of an event */
-       int dst;                                        /**< dst of event */
-       GList *exception_date_list;                    /**< exception dates */
-       int original_event_id;        /**< original event id for recurrency exception */
-       double latitude;
-       double longitude;
-       int email_id;
-       int availability;
-       long long int created_time;
-       long long int completed_time;
-       int progress;
-       int is_deleted; /**< for sync */
-       int dtstart_type;
-       long long int dtstart_utime;
-       int dtstart_year;
-       int dtstart_month;
-       int dtstart_mday;
-       char *dtstart_tzid;
-       int dtend_type;
-       long long int dtend_utime;
-       int dtend_year;
-       int dtend_month;
-       int dtend_mday;
-       char *dtend_tzid;
-       int duration;
-       long long int last_mod;
-       int rrule_id;
-       int freq;
-       int range_type;
-       int until_type;
-       long long int until_utime;
-       int until_year;
-       int until_month;
-       int until_mday;
-       int count;
-       int interval;
-       char *bysecond;
-       char *byminute;
-       char *byhour;
-       char *byday;
-       char *bymonthday;
-       char *byyearday;
-       char *byweekno;
-       char *bymonth;
-       char *bysetpos;
-       int wkst;
-}cal_sch_full_t;
-
-
-/**
- * This structure defines participant information of a meetting.
- * ical: cutype, member, role, partstat, rsvp, delto, delfrom, sentby, cn,  dir, language
- */
-typedef struct
-{
-       int event_id;
-       char *attendee_number;
-       int attendee_type;
-       int attendee_ct_index;
-       char *attendee_uid;
-       int is_deleted;
-
-       /* ical spec from here */
-       char *attendee_group;   /* cutype */
-       char *attendee_email;   /* member */
-       int attendee_role;              /* role */
-       int attendee_status;    /* partstat: ACCEPTED, DECLINED.. */
-       int attendee_rsvp;              /* rsvp */
-       char *attendee_delegate_uri;    /* delfrom */
-       char *attendee_delegator_uri;   /* delto */
-       /* sentby */
-       char *attendee_name;    /* cn */
-       /* dir */
-       /* language */
-
-}cal_participant_info_t;
-
-/**
- * This structure defines exception information of alarm.
- */
-typedef struct
-{
-       int alarm_id;                   /**< Alarm id */
-       int event_id;
-       cal_alert_type_t alarm_type;                    /**< Alert type(see 'cal_alert_type_t') */
-       int is_deleted;
-
-       /* audio */
-       /* -- trigger */
-       long long int alarm_time;
-       int remind_tick;
-       cal_sch_remind_tick_unit_t      remind_tick_unit;
-       /* --attach */
-       char *alarm_tone;                       /**< Alert Sound File Name */
-
-       /* display */
-       char *alarm_description;                        /**< Alert description */
-
-
-       /* email */
-
-}cal_alarm_info_t;
-
-//This is the calendar schema
-typedef struct
-{
-       int index;
-       int store_type;
-       char *calendar_id;
-       char *uid;
-       char *link;
-       long updated;
-       char *name;
-       char *description;
-       char *author;
-       char *color;
-       int hidden;
-       int selected;
-       char *location;
-       int locale;
-       int country;
-       long time_zone;
-       char *timezone_label;
-       int display_all_timezones;
-       int date_field_order;
-       int format_24hour_time;
-       int week_start;
-       int default_cal_mode;
-       int custom_cal_mode;
-       char *user_location;
-       char *weather;
-       int show_declined_events;
-       int hide_invitations;
-       int alternate_calendar;
-       int visibility;
-       int projection;
-       int sequence;
-       int suppress_reply_notifications;
-       int sync_event;
-       int times_cleaned;
-       int guests_can_modify;
-       int guests_can_invite_others;
-       int guests_can_see_guests;
-       int access_level;
-       int sync_status;
-       int is_deleted;
-       int account_id;
-       int sensitivity;
-}calendar_t;
-
-typedef struct
-{
-       //int gcal_dev_db_id;
-       char *uid;
-       char *name;
-       calendar_type_t calendar_type;          /**<one type of calendar */
-}calendar_main_info_t;
-
-
-/* type for timezone information save */
-typedef struct
-{
-       int index;
-       int tz_offset_from_gmt;
-
-       char *standard_name;
-       int std_start_month;
-       int std_start_position_of_week;
-       int std_start_day;
-       int std_start_hour;
-       int standard_bias;
-
-       char *day_light_name;
-       int day_light_start_month;
-       int day_light_start_position_of_week;
-       int day_light_start_day;
-       int day_light_start_hour;
-       int day_light_bias;
-} cal_timezone_t;
-
-typedef struct
-{
-       int index;
-       int dtstart_type;
-       long long int dtstart_utime;
-       int dtend_type;
-       long long int dtend_utime;
-} cals_struct_period_normal_onoff;
-
-typedef struct
-{
-       int index;
-       int dtstart_type;
-       int dtstart_year;
-       int dtstart_month;
-       int dtstart_mday;
-       int dtend_type;
-       int dtend_year;
-       int dtend_month;
-       int dtend_mday;
-} cals_struct_period_allday_onoff;
-
-typedef struct
-{
-       int index;
-       int dtstart_type;
-       long long int dtstart_utime;
-       int dtend_type;
-       long long int dtend_utime;
-       char *summary;
-       char *location;
-} cals_struct_period_normal_basic;
-
-typedef struct
-{
-       int index;
-       int dtstart_type;
-       int dtstart_year;
-       int dtstart_month;
-       int dtstart_mday;
-       int dtend_type;
-       int dtend_year;
-       int dtend_month;
-       int dtend_mday;
-       char *summary;
-       char *location;
-} cals_struct_period_allday_basic;
-
-typedef struct
-{
-       int index;
-       int calendar_id;
-       int dtstart_type;
-       long long int dtstart_utime;
-       int dtend_type;
-       long long int dtend_utime;
-       char *summary;
-       char *description;
-       char *location;
-       int busy_status;
-       int meeting_status;
-       int priority;
-       int sensitivity;
-       int rrule_id;
-} cals_struct_period_normal_osp;
-
-typedef struct
-{
-       int index;
-       int calendar_id;
-       int dtstart_type;
-       int dtstart_year;
-       int dtstart_month;
-       int dtstart_mday;
-       int dtend_type;
-       int dtend_year;
-       int dtend_month;
-       int dtend_mday;
-       char *summary;
-       char *description;
-       char *location;
-       int busy_status;
-       int meeting_status;
-       int priority;
-       int sensitivity;
-       int rrule_id;
-} cals_struct_period_allday_osp;
-
-typedef struct
-{
-       int index;
-       int calendar_id;
-       int dtstart_type;
-       long long int dtstart_utime;
-       int dtend_type;
-       long long int dtend_utime;
-       char *summary;
-       char *description;
-       char *location;
-       int busy_status;
-       int meeting_status;
-       int priority;
-       int sensitivity;
-       int rrule_id;
-       double latitude;
-       double longitude;
-} cals_struct_period_normal_location;
-
-typedef struct
-{
-       int index;
-       int calendar_id;
-       int dtstart_type;
-       int dtstart_year;
-       int dtstart_month;
-       int dtstart_mday;
-       int dtend_type;
-       int dtend_year;
-       int dtend_month;
-       int dtend_mday;
-       char *summary;
-       char *description;
-       char *location;
-       int busy_status;
-       int meeting_status;
-       int priority;
-       int sensitivity;
-       int rrule_id;
-       double latitude;
-       double longitude;
-} cals_struct_period_allday_location;
-
-typedef struct
-{
-       int index;
-       int calendar_id;
-       int dtstart_type;
-       long long int dtstart_utime;
-       int dtend_type;
-       long long int dtend_utime;
-       long long int alarm_utime;
-       int alarm_id;
-}cals_struct_period_normal_alarm;
-
-/**
- * @}
- */
-#endif // _CALENDAR_SVC_TYPEDEF_H_
diff --git a/src/cals-utils.c b/src/cals-utils.c
deleted file mode 100755 (executable)
index 6239faf..0000000
+++ /dev/null
@@ -1,431 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdbool.h>
-
-#include "cals-typedef.h"
-#include "cals-utils.h"
-#include "cals-db.h"
-#include "cals-db-info.h"
-#include "cals-internal.h"
-#include "cals-sqlite.h"
-
-#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
-{
-       CAL_SCH_TERM_ONE_DAY,
-       CAL_SCH_TERM_OVER_2_DAYS,
-       CAL_SCH_TERM_OVER_7_DAYS,
-       CAL_SCH_TERM_OVER_1_MONTH,
-       CAL_SCH_TERM_OVER_1_YEAR,
-       CAL_SCH_TERM_ERROR
-} __cal_sch_term_status_t;
-
-static const char *CALS_NOTI_EVENT_CHANGED="/opt/data/calendar-svc/.CALENDAR_SVC_EVENT_CHANGED";
-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;
-
-static bool event_change=false;
-static bool todo_change=false;
-static bool calendar_change=false;
-#endif
-
-static inline void _cals_notify_event_change(void)
-{
-       int fd = open(CALS_NOTI_EVENT_CHANGED, O_TRUNC | O_RDWR);
-       if (0 <= fd) {
-               close(fd);
-               event_change = false;
-       }
-}
-
-static inline void _cals_notify_todo_change(void)
-{
-       int fd = open(CALS_NOTI_TODO_CHANGED, O_TRUNC | O_RDWR);
-       if (0 <= fd) {
-               close(fd);
-               todo_change = false;
-       }
-}
-
-static inline void _cals_notify_calendar_change(void)
-{
-       int fd = open(CALS_NOTI_CALENDAR_CHANGED, O_TRUNC | O_RDWR);
-       if (0 <= fd) {
-               close(fd);
-               calendar_change = false;
-       }
-}
-
-const char* cals_noti_get_file_path(int type)
-{
-       const char *noti;
-       switch (type)
-       {
-       case CALS_NOTI_TYPE_EVENT:
-               noti = CALS_NOTI_EVENT_CHANGED;
-               break;
-       case CALS_NOTI_TYPE_TODO:
-               noti = CALS_NOTI_TODO_CHANGED;
-               break;
-       case CALS_NOTI_TYPE_CALENDAR:
-               noti = CALS_NOTI_CALENDAR_CHANGED;
-               break;
-       default:
-               ERR("The type(%d) is not supported", type);
-               return NULL;
-       }
-
-       return noti;
-}
-
-int cals_notify(cals_noti_type type)
-{
-       if (0 < transaction_cnt) {
-               switch (type) {
-               case CALS_NOTI_TYPE_EVENT:
-                       event_change = true;
-                       break;
-               case CALS_NOTI_TYPE_TODO:
-                       todo_change = true;
-                       break;
-               case CALS_NOTI_TYPE_CALENDAR:
-                       calendar_change = true;
-                       break;
-               default:
-                       ERR("The type(%d) is not supported", type);
-                       return CAL_ERR_ARG_INVALID;
-               }
-               return CAL_SUCCESS;
-       }
-
-       switch(type) {
-       case CALS_NOTI_TYPE_EVENT:
-               _cals_notify_event_change();
-               break;
-       case CALS_NOTI_TYPE_TODO:
-               _cals_notify_todo_change();
-               break;
-       case CALS_NOTI_TYPE_CALENDAR:
-               _cals_notify_calendar_change();
-               break;
-       default:
-               ERR("The type(%d) is not supported", type);
-               return CAL_ERR_ARG_INVALID;
-       }
-
-       return CAL_SUCCESS;
-}
-
-#define CAL_COMMIT_TRY_MAX 500000
-int cals_begin_trans(void)
-{
-       if(transaction_cnt <= 0)
-       {
-               int ret, progress;
-
-               progress = 100000;
-               ret = cals_query_exec("BEGIN IMMEDIATE TRANSACTION");
-               while(CAL_ERR_DB_LOCK == ret && progress < CAL_COMMIT_TRY_MAX) {
-                       usleep(progress);
-                       ret = cals_query_exec("BEGIN IMMEDIATE TRANSACTION");
-                       progress *= 2;
-               }
-               retvm_if(CAL_SUCCESS != ret, ret, "cals_query_exec() Failed(%d)", ret);
-
-               transaction_cnt = 0;
-               const char *query = "SELECT ver FROM "CALS_TABLE_VERSION;
-               transaction_ver = cals_query_get_first_int_result(query);
-               version_up = false;
-       }
-       transaction_cnt++;
-       CALS_DBG("transaction_cnt : %d", transaction_cnt);
-
-       return CAL_SUCCESS;
-}
-
-
-static inline void _cals_cancel_changes(void)
-{
-       event_change = false;
-       calendar_change = false;
-       todo_change = false;
-}
-
-
-int cals_end_trans(bool is_success)
-{
-       int ret;
-       int progress = 0;
-       char query[CALS_SQL_MIN_LEN];
-
-       transaction_cnt--;
-
-       if (0 != transaction_cnt) {
-               CALS_DBG("transaction_cnt : %d", transaction_cnt);
-               return CAL_SUCCESS;
-       }
-
-       if (false == is_success) {
-               _cals_cancel_changes();
-               ret = cals_query_exec("ROLLBACK TRANSACTION");
-               return CAL_SUCCESS;
-       }
-
-       if (version_up) {
-               transaction_ver++;
-               snprintf(query, sizeof(query), "UPDATE %s SET ver = %d",
-                               CALS_TABLE_VERSION, transaction_ver);
-               ret = cals_query_exec(query);
-               warn_if(CAL_SUCCESS != ret, "cals_query_exec(version up) Failed(%d).", ret);
-       }
-
-       progress = 400000;
-       ret = cals_query_exec("COMMIT TRANSACTION");
-       while (CAL_ERR_DB_LOCK == ret && progress < CAL_COMMIT_TRY_MAX) {
-               usleep(progress);
-               ret = cals_query_exec("COMMIT TRANSACTION");
-               progress *= 2;
-       }
-       if (CAL_SUCCESS != ret) {
-               int tmp_ret;
-               ERR("cals_query_exec() Failed(%d)", ret);
-               _cals_cancel_changes();
-               tmp_ret = cals_query_exec("ROLLBACK TRANSACTION");
-               warn_if(CAL_SUCCESS != tmp_ret, "cals_query_exec(ROLLBACK) Failed(%d).", tmp_ret);
-               return ret;
-       }
-       if (event_change) _cals_notify_event_change();
-       if (todo_change) _cals_notify_todo_change();
-       if (calendar_change) _cals_notify_calendar_change();
-
-       return transaction_ver;
-}
-
-API int calendar_svc_begin_trans(void)
-{
-       CALS_FN_CALL;
-       return cals_begin_trans();
-}
-
-
-API int calendar_svc_end_trans(bool is_success)
-{
-       CALS_FN_CALL;
-       return cals_end_trans(is_success);
-}
-
-int cals_get_next_ver(void)
-{
-       const char *query;
-
-       if (0 < transaction_cnt) {
-               version_up = true;
-               return transaction_ver + 1;
-       }
-
-       query = "SELECT ver FROM "CALS_TABLE_VERSION;
-       return (1 + cals_query_get_first_int_result(query));
-}
-
-bool cal_db_get_text_from_stmt(sqlite3_stmt *stmt,char** p_str_dst,int column)
-{
-       char *str_temp = NULL;
-       int str_len = 0;
-
-       str_temp = (char *)sqlite3_column_text(stmt, column);
-       str_len = sqlite3_column_bytes(stmt, column);
-
-       if(0 == str_len)
-       {
-               *p_str_dst = NULL;
-               return true;
-       }
-
-       CAL_FREE(*p_str_dst);
-
-
-       *p_str_dst = (char*)malloc(str_len+1);
-       retvm_if(NULL == *p_str_dst, false, "failed to malloc str_dst");
-
-       memcpy(*p_str_dst,str_temp,str_len);
-       (*p_str_dst)[str_len] = '\0';
-
-       return true;
-}
-
-bool cal_db_get_blob_from_stmt(sqlite3_stmt *stmt,struct tm* p_tm,int column)
-{
-       struct tm* temp = NULL;
-
-       if(NULL == p_tm)
-       {
-               return false;
-       }
-
-       temp = (struct tm*)sqlite3_column_blob(stmt, column);
-       if(NULL == temp)
-       {
-               return false;
-       }
-
-       memcpy(p_tm,temp,sizeof(struct tm));
-       return true;
-}
-
-
-bool cal_db_service_convert_stmt_to_tz_info(sqlite3_stmt *stmt,cal_timezone_t * tz_info)
-{
-       CALS_FN_CALL;
-
-       int count = 0;
-
-       tz_info->index = sqlite3_column_int(stmt, count++);
-       tz_info->tz_offset_from_gmt = sqlite3_column_int(stmt, count++);
-
-       cal_db_get_text_from_stmt(stmt,&(tz_info->standard_name),count++);
-
-       tz_info->std_start_month = sqlite3_column_int(stmt, count++);
-       tz_info->std_start_position_of_week = sqlite3_column_int(stmt, count++);
-       tz_info->std_start_day = sqlite3_column_int(stmt, count++);
-       tz_info->std_start_hour = sqlite3_column_int(stmt, count++);
-       tz_info->standard_bias = sqlite3_column_int(stmt, count++);
-
-       cal_db_get_text_from_stmt(stmt,&(tz_info->day_light_name),count++);
-
-       tz_info->day_light_start_month = sqlite3_column_int(stmt, count++);
-       tz_info->day_light_start_position_of_week = sqlite3_column_int(stmt, count++);
-       tz_info->day_light_start_day = sqlite3_column_int(stmt, count++);
-       tz_info->day_light_start_hour = sqlite3_column_int(stmt, count++);
-       tz_info->day_light_bias = sqlite3_column_int(stmt, count++);
-
-       return true;
-}
-
-inline cals_updated* cals_updated_schedule_add_mempool(void)
-{
-       int i;
-       cals_updated *mempool;
-
-       mempool = calloc(1, sizeof(cals_updated));
-//     for (i = 0; i < CALS_MALLOC_DEFAULT_NUM-1; i++) {
-//             mempool[i].next = &mempool[i+1];
-//     }
-       return mempool;
-}
-
-inline int cals_updated_schedule_free_mempool(cals_updated *mempool)
-{
-       cals_updated *memseg, *tmp;
-
-       retv_if(NULL == mempool, CAL_ERR_ARG_NULL);
-
-       memseg = mempool;
-       while (memseg) {
-               tmp = memseg->next;
-//             tmp = memseg[CALS_MALLOC_DEFAULT_NUM-1].next;
-               free(memseg);
-               memseg = tmp;
-       }
-
-       return CAL_SUCCESS;
-}
-
-char cal_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-
-
-//long long int _get_utime(int y, int mon, int d, int h, int min, int s)
-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);
-}
-
diff --git a/src/cals-utils.h b/src/cals-utils.h
deleted file mode 100755 (executable)
index 7f0f5d0..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#ifndef __CALENDAR_SVC_UTILS_H__
-#define __CALENDAR_SVC_UTILS_H__
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include "db-util.h"
-#include <glib.h>
-
-/* sec to 1970 1 1 0:0:0 */
-#define D19700101 62167219200
-
-//SQL operation type. May be used for other usage.
-typedef enum
-{
-       CAL_SQL_TYPE_INSERT = 0,
-       CAL_SQL_TYPE_UPDATE
-} cal_sql_type_t;
-
-
-/**
-* @enum __cal_sch_field_t
-* This enumeration Schedule database field index.
-*/
-typedef enum
-{
-       CAL_SCH_FIELD_INDEX = 0,                                        /**< This is an invalid type. */
-       CAL_SCH_FIELD_TYPE,                                             /**< This is an calendar type. */
-       CAL_SCH_FIELD_CATEGORY,                                 /**< This is an schedule category type. */
-       CAL_SCH_FIELD_SUMMARY,                                  /**< This is an schedule summary */
-       CAL_SCH_FIELD_DESCRIPTION,                              /**< This is description */
-       CAL_SCH_FIELD_LOCATION,                                 /**< This is location */
-       CAL_SCH_FIELD_ALL_DAY_EVENT,                            /**< This is all day event */
-       CAL_SCH_FIELD_START_DATE_TIME,                  /**< This is start date time */
-       CAL_SCH_FIELD_END_DATE_TIME,                    /**< This is end date time */
-       CAL_SCH_FIELD_ALARM_TIME,                               /**< This is alarm time */
-       CAL_SCH_FIELD_REMIND_TICK,                              /**< This is remind tick */
-       CAL_SCH_FIELD_REMIND_TICK_UNIT,                 /**< This is remind tick unit */
-       CAL_SCH_FIELD_ALARM_ID,                                 /**< This is alarm id */
-       CAL_SCH_FIELD_REPEAT_TERM,                              /**< This is repeat term */
-       CAL_SCH_FIELD_REPEAT_INTERVAL,                  /**< Interval of repeat term */
-       CAL_SCH_FIELD_REPEAT_END_DATE,                  /**< This is repead end date */
-       CAL_SCH_FIELD_REPEAT_SUN_MOON,                  /**< Using sun or lunar calendar */
-       CAL_SCH_FIELD_REPEAT_WEEK_START,                /**< Start day of a week */
-       CAL_SCH_FIELD_REPEAT_WEEK_FLAG,                 /**< Indicate which day is select in a week */
-       CAL_SCH_FIELD_REPEAT_DAY_DATE,                  /**< 0- for weekday(sun,mon,etc.) , 1 - for specific day(1,2.. Etc) */
-       CAL_SCH_FIELD_MISSED,                                           /**< This is missed flag */
-       CAL_SCH_FIELD_CALENDAR_TYPE,                    /**< Calendar type */
-       CAL_SCH_FIELD_TIME_ZOON,                                        /**< This is time zoon of calendar event */
-       CAL_SCH_FIELD_DST,                                              /**< This is dst of an event*/
-
-       CAL_SCH_FIELD_CNT_MAX                   /**< This is count max */
-} __cal_sch_field_t;
-
-
-typedef struct
-{
-       int     mname;  // month
-       int     day;    // day count
-} cal_month_tab;
-
-bool cal_db_get_text_from_stmt(sqlite3_stmt * stmt,char * * p_str_dst,int column);
-
-bool cal_db_get_blob_from_stmt(sqlite3_stmt * stmt,struct tm * p_tm,int column);
-
-bool cal_db_service_convert_stmt_to_tz_info(sqlite3_stmt *stmt,cal_timezone_t * tz_info);
-bool cal_util_convert_query_string(const char *src, char *dst);
-
-int cals_notify(cals_noti_type operation_type);
-int cals_begin_trans(void);
-int cals_end_trans(bool is_success);
-int cals_get_next_ver(void);
-const char* cals_noti_get_file_path(int type);
-inline cals_updated* cals_updated_schedule_add_mempool(void);
-inline int cals_updated_schedule_free_mempool(cals_updated *mempool);
-
-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 /* __CALENDAR_SVC_UTILS_H__ */
diff --git a/test/Makefile b/test/Makefile
deleted file mode 100755 (executable)
index b0777a1..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-C = gcc
-
-REQUIRED_PKG = calendar-service
-CFLAGS = -g -Wall
-LDFLAGS = # -L../ -lefence -pthread
-ifdef REQUIRED_PKG
-       CFLAGS += `pkg-config --cflags $(REQUIRED_PKG)`
-       LDFLAGS += `pkg-config --libs $(REQUIRED_PKG)`
-endif
-
-SRCS = recur-add.c eve-add.c recur-add.c eve-see.c
-TIMESRC = timetest.c
-OBJECTS = $(SRCS:.c=.o)
-TIMEOBJ = $(TIMESRC:.c=.o)
-TARGETS = $(OBJECTS:.o=)
-#A:.c=.o  //A안에 있는 .c를 .o로 바꿔라
-
-
-all: $(OBJECTS) $(TARGETS)
-#-mv test1 testlocal /usr/
-
-$(TARGETS): $(TIMEOBJ)
-$(TIMEOBJ): timetest.h
-
-% : %.o
-       $(CC) -o $@ $< $(TIMEOBJ) $(LDFLAGS)
-
-clean:
-       rm -rf $(OBJECTS) $(TARGETS) $(TIMEOBJ)
-
diff --git a/test/allday.c b/test/allday.c
deleted file mode 100644 (file)
index 2e0eb20..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-
-#include <stdio.h>
-#include <time.h>
-#include <calendar-svc-provider.h>
-
-int main(int argc, char **argv)
-{
-       int ret;
-       time_t tt;
-       cal_struct *cs = NULL;
-
-       cs = calendar_svc_struct_new(CAL_STRUCT_SCHEDULE);
-       if (cs == NULL) {
-               printf("Failed to new calendar\n");
-               return -1;
-       }
-
-       tt = time(NULL);
-
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_ACCOUNT_ID, 1);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_TASK_STATUS, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_PRIORITY, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_FILE_ID, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_CONTACT_ID, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_BUSY_STATUS, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_SENSITIVITY, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_CALENDAR_TYPE, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_MEETING_STATUS, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_LOCATION_TYPE, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_CALENDAR_ID, 1);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_SYNC_STATUS, 1);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_DST, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_ORIGINAL_EVENT_ID, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_EMAIL_ID, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_AVAILABILITY, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_PROGRESS, 0);
-
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_CATEGORIES, "event categories");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_SUMMARY, "event summary");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_DESCRIPTION, "event description");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_LOCATION, "event location");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_UID, "event uid");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_ORGANIZER_NAME, "event org name");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_ORGANIZER_EMAIL, "event org email");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_GCAL_ID, "event gcal id");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_UPDATED, "event udpated");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_LOCATION_SUMMARY, "event loc summary");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_ETAG, "event etag");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_EDIT_URL, "event url");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_GEDERID, "event gederid");
-
-       calendar_svc_struct_set_double(cs, CAL_VALUE_DBL_LATITUDE, 0.1);
-       calendar_svc_struct_set_double(cs, CAL_VALUE_DBL_LONGITUDE, 0.2);
-
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_TYPE, CALS_TIME_LOCALTIME);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_YEAR, 2012);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_MONTH, 7);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_MDAY, 1);
-       calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_DTSTART_UTIME, 1339833600);
-       calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_DTSTART_TZID, "Europe/London");
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_TYPE, CALS_TIME_UTIME);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_YEAR, 2012);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_MONTH, 7);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_MDAY, 1);
-       calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_DTEND_UTIME, 1339837200);
-       calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_DTEND_TZID, "Europe/London");
-
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_MONTHLY);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_RANGE_TYPE, CALS_RANGE_UNTIL);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_TYPE, CALS_TIME_LOCALTIME);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_YEAR, 2013);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_MONTH, 5);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_MDAY, 1);
-       calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_RRULE_UNTIL_UTIME, 1452483199);
-//     calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_COUNT, 6);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_INTERVAL, 2);
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYSECOND, "bysecond");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMINUTE, "byminute");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYHOUR, "byhour");
-       calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYDAY, "3SA,3TU");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYDAY, "SA,TU");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMONTHDAY, "4,27");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYYEARDAY, "byyearday");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYWEEKNO, "byweekno");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMONTH, "7");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYSETPOS, "bysetpos");
-
-       calendar_svc_connect();
-       ret = calendar_svc_insert(cs);
-       calendar_svc_close();
-
-       calendar_svc_struct_free(&cs);
-       return ret;
-}
diff --git a/test/calendar-test.c b/test/calendar-test.c
deleted file mode 100644 (file)
index c56fa34..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <calendar-svc-provider.h>
-
-#include "test-log.h"
-
-static inline int insert_calendar1()
-{
-       int ret;
-       cal_struct *calendar = NULL;
-
-       calendar = calendar_svc_struct_new(CAL_STRUCT_CALENDAR);
-
-       calendar_svc_struct_set_int(calendar, CAL_TABLE_INT_ACCOUNT_ID, 1);
-       calendar_svc_struct_set_int(calendar, CAL_TABLE_INT_VISIBILITY, 1);
-       calendar_svc_struct_set_str(calendar, CAL_TABLE_TXT_NAME, "Test Calendar1");
-       calendar_svc_struct_set_str(calendar, CAL_TABLE_TXT_DESCRIPTION, "Event only calendar");
-       calendar_svc_struct_set_int(calendar, CAL_TABLE_INT_STORE_TYPE, CALS_CALENDAR_TYPE_EVENT);
-
-       ret = calendar_svc_insert(calendar);
-       calendar_svc_struct_free(&calendar);
-
-       if (ret < CAL_SUCCESS) {
-               ERR("calendar_svc_insert() Failed(%d)", ret);
-               return -1;
-       } else {
-               DBG("calendar_svc_insert() return %d", ret);
-               return ret;
-       }
-}
-
-
-static inline int insert_calendar2()
-{
-       int ret;
-       cal_struct *calendar = NULL;
-
-       calendar = calendar_svc_struct_new(CAL_STRUCT_CALENDAR);
-
-       calendar_svc_struct_set_int(calendar, CAL_TABLE_INT_ACCOUNT_ID, 1);
-       calendar_svc_struct_set_int(calendar, CAL_TABLE_INT_VISIBILITY, 1);
-       calendar_svc_struct_set_str(calendar, CAL_TABLE_TXT_NAME, "Test Calendar2");
-       calendar_svc_struct_set_str(calendar, CAL_TABLE_TXT_DESCRIPTION, "Event and Todo calendar");
-       calendar_svc_struct_set_int(calendar, CAL_TABLE_INT_STORE_TYPE, CALS_CALENDAR_TYPE_EVENT|CALS_CALENDAR_TYPE_TODO);
-
-       ret = calendar_svc_insert(calendar);
-       calendar_svc_struct_free(&calendar);
-
-       if (ret < CAL_SUCCESS) {
-               ERR("calendar_svc_insert() Failed(%d)", ret);
-               return -1;
-       } else {
-               DBG("calendar_svc_insert() return %d", ret);
-               return ret;
-       }
-}
-
-static inline void get_calendar(int index)
-{
-       int ret;
-       cal_struct *calendar = NULL;
-
-       ret = calendar_svc_get(CAL_STRUCT_CALENDAR, index, NULL, &calendar);
-       if (ret < CAL_SUCCESS) {
-               ERR("calendar_svc_get() Failed(%d)", ret);
-               return;
-       }
-
-       printf("%s(%s)\n\t acc = %d\n\t type = %d\n",
-                       calendar_svc_struct_get_str(calendar, CAL_TABLE_TXT_NAME),
-                       calendar_svc_struct_get_str(calendar, CAL_TABLE_TXT_DESCRIPTION),
-                       calendar_svc_struct_get_int(calendar, CAL_TABLE_INT_ACCOUNT_ID),
-                       calendar_svc_struct_get_int(calendar, CAL_TABLE_INT_STORE_TYPE));
-
-       calendar_svc_struct_free(&calendar);
-}
-
-int main(int argc, char **argv)
-{
-       int ret;
-
-       calendar_svc_connect();
-
-       ret = insert_calendar1();
-       DBG("get_calendar");
-       get_calendar(ret);
-
-       ret = insert_calendar2();
-       DBG("get_calendar");
-       get_calendar(ret);
-
-       calendar_svc_close();
-
-       return 0;
-}
-
-
diff --git a/test/eve-add.c b/test/eve-add.c
deleted file mode 100644 (file)
index 0aaa8ba..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-
-#include <stdio.h>
-#include <time.h>
-#include <calendar-svc-provider.h>
-#include "utime.h"
-
-int main(int argc, char **argv)
-{
-       int ret;
-       time_t tt;
-       cal_struct *cs = NULL;
-
-       cs = calendar_svc_struct_new(CAL_STRUCT_SCHEDULE);
-       if (cs == NULL) {
-               printf("Failed to new calendar\n");
-               return -1;
-       }
-
-       tt = time(NULL);
-
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_ACCOUNT_ID, 1);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_TASK_STATUS, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_PRIORITY, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_FILE_ID, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_CONTACT_ID, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_BUSY_STATUS, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_SENSITIVITY, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_CALENDAR_TYPE, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_MEETING_STATUS, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_LOCATION_TYPE, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_CALENDAR_ID, 1);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_SYNC_STATUS, 1);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_DST, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_ORIGINAL_EVENT_ID, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_EMAIL_ID, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_AVAILABILITY, 0);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_PROGRESS, 0);
-
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_CATEGORIES, "event categories");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_SUMMARY, "event summary");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_DESCRIPTION, "event description");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_LOCATION, "event location");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_UID, "event uid");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_ORGANIZER_NAME, "event org name");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_ORGANIZER_EMAIL, "event org email");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_GCAL_ID, "event gcal id");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_UPDATED, "event udpated");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_LOCATION_SUMMARY, "event loc summary");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_ETAG, "event etag");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_EDIT_URL, "event url");
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_GEDERID, "event gederid");
-
-       calendar_svc_struct_set_double(cs, CAL_VALUE_DBL_LATITUDE, 0.1);
-       calendar_svc_struct_set_double(cs, CAL_VALUE_DBL_LONGITUDE, 0.2);
-
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_TYPE, CALS_TIME_UTIME);
-       calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_DTSTART_UTIME, D20120701T000000);
-       calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_DTSTART_TZID, "Europe/London");
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_TYPE, CALS_TIME_UTIME);
-       calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_DTEND_UTIME, D20120901T000000);
-       calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_DTEND_TZID, "Europe/London");
-
-/*
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_TYPE, CALS_TIME_LOCALTIME);
-       calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_DTSTART_TZID, "Europe/London");
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_YEAR, 2012);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_MONTH, 6);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_MDAY, 1);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_TYPE, CALS_TIME_LOCALTIME);
-       calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_DTEND_TZID, "Europe/London");
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_YEAR, 2012);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_MONTH, 6);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_MDAY, 1);
-*/
-
-
-
-//     calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_WEEKLY);
-//     calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_RANGE_TYPE, CALS_RANGE_COUNT);
-//     calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_TYPE, CALS_TIME_UTIME);
-//     calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_RRULE_UNTIL_UTIME, 1452483199);
-//     calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_YEAR, 2012);
-//     calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_MONTH, 9);
-//     calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_MDAY, 31);
-
-
-//     calendar_svc_struct_set_lli(cs, CALS_VALUE_INT_RRULE_UNTIL_YEAR, "2012");
-//     calendar_svc_struct_set_lli(cs, CALS_VALUE_INT_RRULE_UNTIL_MONTH, "8");
-//     calendar_svc_struct_set_lli(cs, CALS_VALUE_INT_RRULE_UNTIL_MDAY, "12");
-//     calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_COUNT, 6);
-//     calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_INTERVAL, 2);
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYSECOND, "bysecond");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMINUTE, "byminute");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYHOUR, "byhour");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYDAY, "3SA,3TU");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYDAY, "SA,TU");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMONTHDAY, "4,27");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYYEARDAY, "byyearday");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYWEEKNO, "byweekno");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMONTH, "7");
-//     calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYSETPOS, "bysetpos");
-
-       calendar_svc_connect();
-       ret = calendar_svc_insert(cs);
-
-       long long int get_lli;
-       get_lli = calendar_svc_struct_get_lli(cs, CALS_VALUE_LLI_DTSTART_UTIME);
-       printf("%lld\n", get_lli);
-
-
-       calendar_svc_close();
-
-       calendar_svc_struct_free(&cs);
-       return ret;
-}
diff --git a/test/eve-del.c b/test/eve-del.c
deleted file mode 100644 (file)
index e94d2ad..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-
-#include <stdio.h>
-#include <time.h>
-#include <calendar-svc-provider.h>
-
-int main(int argc, char **argv)
-{
-       int ret;
-       int index;
-
-       if (argc < 2) {
-               printf("needs 2 arguments\n");
-               return -1;
-       }
-
-       index = atoi(argv[1]);
-       if (index < 0) {
-               printf("Invalid index (%d)\n", index);
-               return -1;
-       }
-
-       calendar_svc_connect();
-       printf("id(%d)\n", index);
-       ret = calendar_svc_delete(CAL_STRUCT_SCHEDULE, index);
-       if (ret != CAL_SUCCESS) {
-               printf("Failed to delete\n");
-               return -1;
-       }
-       calendar_svc_close();
-       return 0;
-}
diff --git a/test/eve-period.c b/test/eve-period.c
deleted file mode 100644 (file)
index 06deabc..0000000
+++ /dev/null
@@ -1,413 +0,0 @@
-
-#include <stdio.h>
-#include <time.h>
-#include <calendar-svc-provider.h>
-
-#define D20120601T000000 1338508800
-#define D20120931T100000 1349085600
-
-int _get_iter_period_normal_onoff(int calendar_id, long long int llis, long long int llie)
-{
-       int index;
-       int is_exist = 0;
-       long long int s;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_event_get_normal_list_by_period(calendar_id, CALS_LIST_PERIOD_NORMAL_ONOFF,
-                       llis, llie, &iter);
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               is_exist = 1;
-               cs = NULL;
-               calendar_svc_iter_get_info(iter, &cs);
-               index = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_ONOFF_INT_EVENTID);
-               s = calendar_svc_struct_get_lli(cs, CALS_LIST_PERIOD_NORMAL_ONOFF_LLI_DTSTART_UTIME);
-               printf("index(%d)dtstart utime:%lld\n", index, s);
-       }
-       calendar_svc_iter_remove(&iter);
-       return is_exist;
-}
-
-int _get_iter_period_allday_onoff(int calendar_id,
-               int sy, int sm, int sd, int ey, int em, int ed)
-{
-       int index;
-       int dtstart_year, dtstart_month, dtstart_mday;
-       int is_exist = 0;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_event_get_allday_list_by_period(calendar_id, CALS_LIST_PERIOD_ALLDAY_ONOFF,
-                       sy, sm, sd, ey, em, ed, &iter);
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               is_exist = 1;
-               cs = NULL;
-               calendar_svc_iter_get_info(iter, &cs);
-               index = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_EVENTID);
-               dtstart_year = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_YEAR);
-               dtstart_month = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_MONTH);
-               dtstart_mday = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_MDAY);
-
-               printf("index(%d)dtstart datetime(%04d/%02d/%02d)\n", index, dtstart_year, dtstart_month, dtstart_mday);
-       }
-       calendar_svc_iter_remove(&iter);
-       return is_exist;
-}
-
-int _get_iter_period_normal_basic(int calendar_id, long long int llis, long long int llie)
-{
-       int index;
-       int is_exist = 0;
-       char *sum, *loc;
-       long long int s, e;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_event_get_normal_list_by_period(calendar_id, CALS_LIST_PERIOD_NORMAL_BASIC,
-                       llis, llie, &iter);
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               is_exist = 1;
-               cs = NULL;
-               calendar_svc_iter_get_info(iter, &cs);
-               index = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_BASIC_INT_EVENTID);
-               s = calendar_svc_struct_get_lli(cs, CALS_LIST_PERIOD_NORMAL_BASIC_LLI_DTSTART_UTIME);
-               e = calendar_svc_struct_get_lli(cs, CALS_LIST_PERIOD_NORMAL_BASIC_LLI_DTEND_UTIME);
-               sum = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_NORMAL_BASIC_TXT_SUMMARY);
-               loc = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_NORMAL_BASIC_TXT_LOCATION);
-               printf("index(%d) s(%lld) e(%lld), sum(%s) loc(%s)\n", index, s, e, sum, loc);
-       }
-       calendar_svc_iter_remove(&iter);
-       return is_exist;
-}
-
-int _get_iter_period_allday_basic(int calendar_id,
-               int sy, int sm, int sd, int ey, int em, int ed)
-{
-       int index;
-       int dtstart_year, dtstart_month, dtstart_mday;
-       int dtend_year, dtend_month, dtend_mday;
-       int is_exist = 0;
-       char *sum, *loc;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_event_get_allday_list_by_period(calendar_id, CALS_LIST_PERIOD_ALLDAY_BASIC,
-                       sy, sm, sd, ey, em, ed, &iter);
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               is_exist = 1;
-               cs = NULL;
-               calendar_svc_iter_get_info(iter, &cs);
-               index = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_EVENTID);
-               dtstart_year = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_YEAR);
-               dtstart_month = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_MONTH);
-               dtstart_mday = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_MDAY);
-               dtend_year = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_YEAR);
-               dtend_month = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_MONTH);
-               dtend_mday = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_MDAY);
-               sum = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_TXT_SUMMARY);
-               loc = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_TXT_LOCATION);
-
-               printf("index(%d) (%04d/%02d/%02d) - (%04d/%02d/%02d)sum(%s) loc(%s)\n",
-                               index,
-                               dtstart_year, dtstart_month, dtstart_mday,
-                               dtend_year, dtend_month, dtend_mday,
-                               sum, loc);
-       }
-       calendar_svc_iter_remove(&iter);
-       return is_exist;
-}
-
-
-
-int _get_iter_period_normal_osp(int calendar_id, long long int llis, long long int llie)
-{
-       int index, cal_id, busy, meeting, prio, sensi;
-       int is_exist = 0;
-       char *sum, *loc, *dsc;
-       long long int s, e;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_event_get_normal_list_by_period(calendar_id, CALS_LIST_PERIOD_NORMAL_OSP,
-                       llis, llie, &iter);
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               is_exist = 1;
-               cs = NULL;
-               calendar_svc_iter_get_info(iter, &cs);
-               index = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_OSP_INT_EVENTID);
-               cal_id = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_OSP_INT_CALENDAR_ID);
-               busy = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_OSP_INT_BUSY_STATUS);
-               meeting = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_OSP_INT_STATUS);
-               prio = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_OSP_INT_PRIORITY);
-               sensi = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_OSP_INT_VISIBILITY);
-               s = calendar_svc_struct_get_lli(cs, CALS_LIST_PERIOD_NORMAL_OSP_LLI_DTSTART_UTIME);
-               e = calendar_svc_struct_get_lli(cs, CALS_LIST_PERIOD_NORMAL_OSP_LLI_DTEND_UTIME);
-               sum = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_NORMAL_OSP_TXT_SUMMARY);
-               loc = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_NORMAL_OSP_TXT_LOCATION);
-               dsc = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_NORMAL_OSP_TXT_DESCRIPTION);
-               printf("index(%d) s(%lld) e(%lld), sum(%s) loc(%s) "
-                               "dsc(%s) cal_id(%d) busy(%d) meeting(%d) prio(%d) sensi(%d)\n",
-                               index, s, e, sum, loc, dsc, cal_id, busy, meeting, prio, sensi);
-       }
-       calendar_svc_iter_remove(&iter);
-       return is_exist;
-}
-
-int _get_iter_period_allday_osp(int calendar_id,
-               int sy, int sm, int sd, int ey, int em, int ed)
-{
-       int index, cal_id, busy, meeting, prio, sensi;
-       int dtstart_year, dtstart_month, dtstart_mday;
-       int dtend_year, dtend_month, dtend_mday;
-       int is_exist = 0;
-       char *sum, *loc, *dsc;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_event_get_allday_list_by_period(calendar_id, CALS_LIST_PERIOD_ALLDAY_OSP,
-                       sy, sm, sd, ey, em, ed, &iter);
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               is_exist = 1;
-               cs = NULL;
-               calendar_svc_iter_get_info(iter, &cs);
-               index = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_EVENTID);
-               dtstart_year = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_YEAR);
-               dtstart_month = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_MONTH);
-               dtstart_mday = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_MDAY);
-               dtend_year = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_YEAR);
-               dtend_month = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_MONTH);
-               dtend_mday = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_MDAY);
-               sum = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_ALLDAY_OSP_TXT_SUMMARY);
-               loc = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_ALLDAY_OSP_TXT_LOCATION);
-               cal_id = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_CALENDAR_ID);
-               busy = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_BUSY_STATUS);
-               meeting = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_STATUS);
-               prio = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_PRIORITY);
-               sensi = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_VISIBILITY);
-               dsc = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_ALLDAY_OSP_TXT_DESCRIPTION);
-
-               printf("index(%d) (%04d/%02d/%02d) - (%04d/%02d/%02d)sum(%s) loc(%s) "
-                               "dsc(%s) cal_id(%d) busy(%d) meeting(%d) prio(%d) sensi(%d)\n",
-                               index,
-                               dtstart_year, dtstart_month, dtstart_mday,
-                               dtend_year, dtend_month, dtend_mday,
-                               sum, loc,
-                               dsc, cal_id, busy, meeting, prio, sensi);
-       }
-       calendar_svc_iter_remove(&iter);
-       return is_exist;
-}
-
-int main(int argc, char **argv)
-{
-       int index;
-       int is_exist;;
-       long long int lli;
-
-       calendar_svc_connect();
-
-       printf("======= CALS_LIST_PERIOD_NORMAL_ONOFF ======\n");
-       printf("\nall calendar(-1)\n");
-       is_exist = _get_iter_period_normal_onoff(-1, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(1)\n");
-       is_exist = _get_iter_period_normal_onoff(1, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(2)\n");
-       is_exist = _get_iter_period_normal_onoff(2, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("======= CALS_LIST_PERIOD_ALLDAY_ONOFF ======\n");
-       printf("\nall calendar(-1)\n");
-       is_exist = _get_iter_period_allday_onoff(-1, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(1)\n");
-       is_exist = _get_iter_period_allday_onoff(1, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(2)\n");
-       is_exist = _get_iter_period_allday_onoff(2, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("======= CALS_LIST_PERIOD_NORMAL_BASIC ======\n");
-       printf("\nall calendar(-1)\n");
-       is_exist = _get_iter_period_normal_basic(-1, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(1)\n");
-       is_exist = _get_iter_period_normal_basic(1, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(2)\n");
-       is_exist = _get_iter_period_normal_basic(2, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("======= CALS_LIST_PERIOD_ALLDAY_BASIC ======\n");
-       printf("\nall calendar(-1)\n");
-       is_exist = _get_iter_period_allday_basic(-1, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(1)\n");
-       is_exist = _get_iter_period_allday_basic(1, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(2)\n");
-       is_exist = _get_iter_period_allday_basic(2, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("======= CALS_LIST_PERIOD_NORMAL_OSP ======\n");
-       printf("\nall calendar(-1)\n");
-       is_exist = _get_iter_period_normal_osp(-1, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(1)\n");
-       is_exist = _get_iter_period_normal_osp(1, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(2)\n");
-       is_exist = _get_iter_period_normal_osp(2, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("======= CALS_LIST_PERIOD_ALLDAY_OSP ======\n");
-       printf("\nall calendar(-1)\n");
-       is_exist = _get_iter_period_allday_osp(-1, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(1)\n");
-       is_exist = _get_iter_period_allday_osp(1, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(2)\n");
-       is_exist = _get_iter_period_allday_osp(2, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       calendar_svc_close();
-
-
-       long long int ts;
-       int i, y, m, d, h, min, s;
-       char mon[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-       long long int th = 62167219200;
-
-       y = 1970;
-       m = 1;
-       d = 1;
-
-       ts = y*365;
-       printf("%lld\n", ts);
-       ts = ts + (int)y/4 - (int)y/100 + (int)y/400;
-       printf("%lld\n", ts);
-       for (i = 0; i < m-1; i++) {
-               ts += mon[i];
-       }
-       ts = ts + d;
-       printf("%lld\n", ts);
-       ts = ts * 24;
-       printf("%lld\n", ts);
-       ts = ts * 60;
-       printf("%lld\n", ts);
-       ts = ts * 60;
-       printf("bb:%lld\n", ts);
-       th = ts;
-
-
-       y = 2012;
-       m = 6;
-       d = 1;
-
-       ts = y*365;
-       printf("%lld\n", ts);
-       ts = ts + (int)y/4 - (int)y/100 + (int)y/400;
-       printf("%lld\n", ts);
-       for (i = 0; i < m-1; i++) {
-               ts += mon[i];
-       }
-       ts = ts + d;
-       printf("%lld\n", ts);
-       ts = ts * 24;
-       printf("%lld\n", ts);
-       ts = ts * 60;
-       printf("%lld\n", ts);
-       ts = ts * 60;
-       printf("%lld\n", ts);
-       ts = ts - 62167219200;
-       printf("aa%lld\n", ts);
-
-       ts = 1338508800;
-       ts = ts / 60;
-       printf("%lld\n", ts);
-       ts = ts / 60;
-       printf("%lld\n", ts);
-       ts = ts / 24;
-       printf("%lld\n", ts);
-
-       printf("%lld\n", ts / 365);
-       printf("%lld\n", ts % 365);
-
-       ts = ts - mon[m-1] - d;
-       printf("%lld\n", ts);
-       ts = ts - y/4 + y/100 - y/400;
-       printf("%lld\n", ts);
-
-
-
-       ts = 1338508800;
-       ts += 62167219200;
-       s = ts % 60;
-       ts /= 60;
-       min = ts % 60;
-       ts /= 60;
-       h = ts % 24;
-       ts /= 24;
-       y = (ts * 400) / (365 * 400 + 100 - 4 + 1);
-       ts = ts - (y * 365) - (y/4) + (y/100) - (y/400);
-       m = 0;
-       while (ts > mon[m]) {
-               ts -= mon[m];
-               m++;
-       }
-       m++;
-       d = ts;
-       printf("%04d/%02d/%02d %d:%d:%d\n", y, m, d, h, min, s);
-
-       return 0;
-}
diff --git a/test/eve-see.c b/test/eve-see.c
deleted file mode 100644 (file)
index b0ab259..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <calendar-svc-provider.h>
-#include "utime.h"
-
-int main(int argc, char **argv)
-{
-       int ret;
-       int idx;
-       int intv;
-       long long int get_lli;
-       cal_struct *cs = NULL;
-
-       if (argc < 2)
-               return -1;
-
-       idx = atoi(argv[1]);
-
-       calendar_svc_connect();
-
-       calendar_svc_get(CAL_STRUCT_SCHEDULE, idx, NULL, &cs);
-
-       get_lli = calendar_svc_struct_get_lli(cs, CALS_VALUE_LLI_DTSTART_UTIME);
-       printf("%lld\n", get_lli);
-       get_lli = calendar_svc_struct_get_lli(cs, CALS_VALUE_LLI_DTEND_UTIME);
-       printf("%lld\n", get_lli);
-
-
-       intv = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_RRULE_ID);
-       printf("id:%d\n", intv);
-       intv = calendar_svc_struct_get_int(cs, CALS_VALUE_INT_RRULE_FREQ);
-       printf("freq:%d\n", intv);
-
-       calendar_svc_close();
-
-       calendar_svc_struct_free(&cs);
-       return ret;
-}
diff --git a/test/ical-export.c b/test/ical-export.c
deleted file mode 100644 (file)
index 5764cda..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <calendar-svc-provider.h>
-
-int main(int argc, char **argv)
-{
-       int r;
-       int calendar_id;
-       char *path;
-
-       calendar_id = atoi(argv[1]);
-       printf("calendar id(%d)\n", calendar_id);
-
-       path = argv[2];
-       printf("path(%s)\n", path);
-
-       calendar_svc_connect();
-
-       r = calendar_svc_calendar_export(calendar_id, path);
-       if (r != CAL_SUCCESS) {
-               printf("Failed to export schedules\n");
-               return -1;
-       }
-
-       calendar_svc_close();
-       return 0;
-}
diff --git a/test/ical-import.c b/test/ical-import.c
deleted file mode 100644 (file)
index 6af96be..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <calendar-svc-provider.h>
-
-/*
- * argv[1]: path
- * argv[2]: calendar_id
- */
-int main(int argc, char **argv)
-{
-       int ret, calendar_id;
-       char *path;
-
-       if (argc < 3) {
-               printf("argument needs 3\n");
-               return -1;
-       }
-
-       if (argv[1] == NULL || argv[2] == NULL) {
-               printf("Invalid argument\n");
-               return -1;
-       }
-
-       path = argv[1];
-       calendar_id = atoi(argv[2]);
-
-       calendar_svc_connect();
-
-       ret = calendar_svc_calendar_import(path, calendar_id);
-       if (ret != CAL_SUCCESS) {
-               printf("Failed to import path(%s) to calendar id(%d)\n", path, calendar_id);
-               return -1;
-       }
-
-       calendar_svc_close();
-       return 0;
-}
diff --git a/test/ical-read.c b/test/ical-read.c
deleted file mode 100644 (file)
index 565f0b2..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <time.h>
-#include <glib.h>
-#include <calendar-svc-provider.h>
-
-static char* _get_stream(const char *path)
-{
-       FILE *file;
-       int buf_size, len;
-       char *stream;
-       char buf[1024];
-
-       file = fopen(path, "r");
-
-       len = 0;
-       buf_size = 1024;
-       stream = malloc(1024);
-
-       while (fgets(buf, sizeof(buf), file)) {
-               if (len + sizeof(buf) < buf_size) {
-                       len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
-
-               } else {
-                       char *new_stream;
-                       buf_size *= 2;
-                       new_stream = realloc(stream, buf_size);
-                       if (new_stream) {
-                               stream = new_stream;
-                       } else {
-                               free(stream);
-                               fclose(file);
-                               printf("out of memory\n");
-                               return NULL;
-                       }
-                       len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
-               }
-       }
-       fclose(file);
-       return stream;
-}
-
-static int _do_import_with_newapi(char *stream)
-{
-       int ret;
-       char *vals;
-       char buf[256];
-       time_t tt;
-       cal_struct *cs = NULL;
-       cal_value *cv = NULL;
-       GList *ls, *schedules = NULL;
-       GList *lc, *categories = NULL;
-
-       if (stream == NULL) {
-               printf("Invalid argument: stream is NULL\n");
-               return -1;
-       }
-
-       ret = calendar_svc_read_schedules(stream, &schedules);
-       if (ret != CAL_SUCCESS) {
-               printf("Failed to read schedules(errno:%d)\n", ret);
-               return -1;
-       }
-
-       if (schedules == NULL) {
-               printf("No schedules\n");
-               return -1;
-       }
-
-       ls = schedules;
-       while (ls) {
-               cs = ls->data;
-               if (cs == NULL) {
-                       ls = g_list_next(ls);
-                       continue;
-               }
-               vals = NULL;
-               vals = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_SUMMARY);
-               printf("summary:%s\n", vals);
-
-               vals = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_CATEGORIES);
-               printf("categories:%s\n", vals);
-
-               tt = calendar_svc_struct_get_time(cs,
-                               CAL_VALUE_GMT_START_DATE_TIME, CAL_TZ_FLAG_LOCAL);
-               ctime_r(&tt, buf);
-               printf("stime:%s", buf);
-
-               tt = calendar_svc_struct_get_time(cs,
-                               CAL_VALUE_GMT_END_DATE_TIME, CAL_TZ_FLAG_LOCAL);
-               ctime_r(&tt, buf);
-               printf("etime:%s", buf);
-
-               vals = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_DESCRIPTION);
-               if (vals) {
-                       printf("desc(%s)\n", vals);
-               } else {
-                       printf("No description\n");
-               }
-
-               ls = g_list_next(ls);
-       }
-       return 0;
-}
-
-/*
- * argv[1]: file path
- */
-int main(int argc, char **argv)
-{
-       int sel;
-       char *stream = NULL;
-       stream = _get_stream(argv[1]);
-
-       _do_import_with_newapi(stream);
-
-printf("%d\n", __LINE__);
-//     if (stream) free(stream);
-
-       return 0;
-}
diff --git a/test/ical-write.c b/test/ical-write.c
deleted file mode 100644 (file)
index 98bdc4d..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <calendar-svc-provider.h>
-
-int main(int argc, char **argv)
-{
-       int ret;
-       char *stream;
-       GList *schedules = NULL;
-       cal_struct *cs = NULL;
-
-       cs = calendar_svc_struct_new(CAL_STRUCT_CALENDAR);
-       if (cs == NULL) {
-               printf("Failed to calloc\n");
-               return-1;
-       }
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_SUMMARY, "title");
-       /* set data in cs... */
-
-       schedules = g_list_append(schedules, cs);
-
-       ret = calendar_svc_write_schedules(schedules, &stream);
-       if (ret != CAL_SUCCESS) {
-               printf("Failed to read schedules(errno:%d)\n", ret);
-               return -1;
-       }
-
-       if (stream == NULL) {
-               printf("stream is NULL\n");
-               return -1;
-       }
-
-       return 0;
-}
diff --git a/test/instance-del.c b/test/instance-del.c
deleted file mode 100644 (file)
index 98b19c2..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-
-#include <stdio.h>
-#include <time.h>
-#include <calendar-svc-provider.h>
-#include "utime.h"
-
-int main(int argc, char **argv)
-{
-       int ret;
-       int index;
-
-       if (argc < 2) {
-               printf("needs 2 arguments\n");
-               return -1;
-       }
-
-       index = atoi(argv[1]);
-       if (index < 0) {
-               printf("Invalid index (%d)\n", index);
-               return -1;
-       }
-
-       calendar_svc_connect();
-//     calendar_svc_event_delete_normal_instance(index, 1445299200);
-       calendar_svc_event_delete_allday_instance(index, 2013, 9, 22);
-       calendar_svc_close();
-       return 0;
-}
diff --git a/test/list.c b/test/list.c
deleted file mode 100644 (file)
index 60fac1f..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-
-#include <stdio.h>
-#include <time.h>
-#include <calendar-svc-provider.h>
-
-
-int main(int argc, char **argv)
-{
-       int index;
-       int ret;
-       int cal_id, acc_id;
-       char *sum;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_connect();
-
-       ret = calendar_svc_get_list(0, 0, CAL_STRUCT_SCHEDULE, NULL, 0, 10, &iter);
-       if (ret != CAL_SUCCESS) {
-               printf("Failed to get list\n");
-               return -1;
-       }
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               cs = NULL;
-               ret = calendar_svc_iter_get_info(iter, &cs);
-               if (ret != CAL_SUCCESS) {
-                       printf("Failed to get info\n");
-                       break;
-               }
-               sum = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_SUMMARY);
-               printf("summary(%s)\n", sum);
-       }
-       calendar_svc_iter_remove(&iter);
-       calendar_svc_close();
-
-       return 0;
-}
diff --git a/test/period.c b/test/period.c
deleted file mode 100644 (file)
index 334054a..0000000
+++ /dev/null
@@ -1,388 +0,0 @@
-
-#include <stdio.h>
-#include <time.h>
-#include <calendar-svc-provider.h>
-
-#define D20120601T000000 1338508800
-#define D20120931T100000 1349085600
-
-int _get_iter_period_normal_onoff(int calendar_id, long long int llis, long long int llie)
-{
-       int index;
-       int is_exist = 0;
-       long long int s;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_event_get_normal_list_by_period(calendar_id, CALS_LIST_PERIOD_NORMAL_ONOFF,
-                       llis, llie, &iter);
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               is_exist = 1;
-               cs = NULL;
-               calendar_svc_iter_get_info(iter, &cs);
-               index = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_ONOFF_INT_EVENTID);
-               s = calendar_svc_struct_get_lli(cs, CALS_LIST_PERIOD_NORMAL_ONOFF_LLI_DTSTART_UTIME);
-               printf("index(%d)dtstart utime:%lld\n", index, s);
-       }
-       return is_exist;
-}
-
-int _get_iter_period_allday_onoff(int calendar_id,
-               int sy, int sm, int sd, int ey, int em, int ed)
-{
-       int index;
-       int dtstart_year, dtstart_month, dtstart_mday;
-       int is_exist = 0;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_event_get_allday_list_by_period(calendar_id, CALS_LIST_PERIOD_ALLDAY_ONOFF,
-                       sy, sm, sd, ey, em, ed, &iter);
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               is_exist = 1;
-               cs = NULL;
-               calendar_svc_iter_get_info(iter, &cs);
-               index = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_EVENTID);
-               dtstart_year = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_YEAR);
-               dtstart_month = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_MONTH);
-               dtstart_mday = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_ONOFF_INT_DTSTART_MDAY);
-
-               printf("index(%d)dtstart datetime(%04d/%02d/%02d)\n", index, dtstart_year, dtstart_month, dtstart_mday);
-       }
-       return is_exist;
-}
-
-int _get_iter_period_normal_basic(int calendar_id, long long int llis, long long int llie)
-{
-       int index;
-       int is_exist = 0;
-       char *sum, *loc;
-       long long int s, e;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_event_get_normal_list_by_period(calendar_id, CALS_LIST_PERIOD_NORMAL_BASIC,
-                       llis, llie, &iter);
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               is_exist = 1;
-               cs = NULL;
-               calendar_svc_iter_get_info(iter, &cs);
-               index = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_BASIC_INT_EVENTID);
-               s = calendar_svc_struct_get_lli(cs, CALS_LIST_PERIOD_NORMAL_BASIC_LLI_DTSTART_UTIME);
-               e = calendar_svc_struct_get_lli(cs, CALS_LIST_PERIOD_NORMAL_BASIC_LLI_DTEND_UTIME);
-               sum = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_NORMAL_BASIC_TXT_SUMMARY);
-               loc = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_NORMAL_BASIC_TXT_LOCATION);
-               printf("index(%d) s(%lld) e(%lld), sum(%s) loc(%s)\n", index, s, e, sum, loc);
-       }
-       return is_exist;
-}
-
-int _get_iter_period_allday_basic(int calendar_id,
-               int sy, int sm, int sd, int ey, int em, int ed)
-{
-       int index;
-       int dtstart_year, dtstart_month, dtstart_mday;
-       int dtend_year, dtend_month, dtend_mday;
-       int is_exist = 0;
-       char *sum, *loc;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_event_get_allday_list_by_period(calendar_id, CALS_LIST_PERIOD_ALLDAY_BASIC,
-                       sy, sm, sd, ey, em, ed, &iter);
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               is_exist = 1;
-               cs = NULL;
-               calendar_svc_iter_get_info(iter, &cs);
-               index = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_EVENTID);
-               dtstart_year = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_YEAR);
-               dtstart_month = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_MONTH);
-               dtstart_mday = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTSTART_MDAY);
-               dtend_year = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_YEAR);
-               dtend_month = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_MONTH);
-               dtend_mday = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_INT_DTEND_MDAY);
-               sum = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_TXT_SUMMARY);
-               loc = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_ALLDAY_BASIC_TXT_LOCATION);
-
-               printf("index(%d) (%04d/%02d/%02d) - (%04d/%02d/%02d)sum(%s) loc(%s)\n",
-                               index,
-                               dtstart_year, dtstart_month, dtstart_mday,
-                               dtend_year, dtend_month, dtend_mday,
-                               sum, loc);
-       }
-       return is_exist;
-}
-
-
-
-int _get_iter_period_normal_osp(int calendar_id, long long int llis, long long int llie)
-{
-       int index, cal_id, busy, meeting, prio, sensi;
-       int is_exist = 0;
-       char *sum, *loc, *dsc;
-       long long int s, e;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_event_get_normal_list_by_period(calendar_id, CALS_LIST_PERIOD_NORMAL_OSP,
-                       llis, llie, &iter);
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               is_exist = 1;
-               cs = NULL;
-               calendar_svc_iter_get_info(iter, &cs);
-               index = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_OSP_INT_EVENTID);
-               cal_id = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_OSP_INT_CALENDAR_ID);
-               busy = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_OSP_INT_BUSY_STATUS);
-               meeting = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_OSP_INT_STATUS);
-               prio = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_OSP_INT_PRIORITY);
-               sensi = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_NORMAL_OSP_INT_VISIBILITY);
-               s = calendar_svc_struct_get_lli(cs, CALS_LIST_PERIOD_NORMAL_OSP_LLI_DTSTART_UTIME);
-               e = calendar_svc_struct_get_lli(cs, CALS_LIST_PERIOD_NORMAL_OSP_LLI_DTEND_UTIME);
-               sum = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_NORMAL_OSP_TXT_SUMMARY);
-               loc = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_NORMAL_OSP_TXT_LOCATION);
-               dsc = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_NORMAL_OSP_TXT_DESCRIPTION);
-               printf("index(%d) s(%lld) e(%lld), sum(%s) loc(%s) "
-                               "dsc(%s) cal_id(%d) busy(%d) meeting(%d) prio(%d) sensi(%d)\n",
-                               index, s, e, sum, loc, dsc, cal_id, busy, meeting, prio, sensi);
-       }
-       return is_exist;
-}
-
-int _get_iter_period_allday_osp(int calendar_id,
-               int sy, int sm, int sd, int ey, int em, int ed)
-{
-       int index, cal_id, busy, meeting, prio, sensi;
-       int dtstart_year, dtstart_month, dtstart_mday;
-       int dtend_year, dtend_month, dtend_mday;
-       int is_exist = 0;
-       char *sum, *loc, *dsc;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_event_get_allday_list_by_period(calendar_id, CALS_LIST_PERIOD_ALLDAY_OSP,
-                       sy, sm, sd, ey, em, ed, &iter);
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               is_exist = 1;
-               cs = NULL;
-               calendar_svc_iter_get_info(iter, &cs);
-               index = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_EVENTID);
-               dtstart_year = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_YEAR);
-               dtstart_month = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_MONTH);
-               dtstart_mday = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTSTART_MDAY);
-               dtend_year = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_YEAR);
-               dtend_month = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_MONTH);
-               dtend_mday = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_DTEND_MDAY);
-               sum = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_ALLDAY_OSP_TXT_SUMMARY);
-               loc = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_ALLDAY_OSP_TXT_LOCATION);
-               cal_id = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_CALENDAR_ID);
-               busy = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_BUSY_STATUS);
-               meeting = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_STATUS);
-               prio = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_PRIORITY);
-               sensi = calendar_svc_struct_get_int(cs, CALS_LIST_PERIOD_ALLDAY_OSP_INT_VISIBILITY);
-               dsc = calendar_svc_struct_get_str(cs, CALS_LIST_PERIOD_ALLDAY_OSP_TXT_DESCRIPTION);
-
-               printf("index(%d) (%04d/%02d/%02d) - (%04d/%02d/%02d)sum(%s) loc(%s) "
-                               "dsc(%s) cal_id(%d) busy(%d) meeting(%d) prio(%d) sensi(%d)\n",
-                               index,
-                               dtstart_year, dtstart_month, dtstart_mday,
-                               dtend_year, dtend_month, dtend_mday,
-                               sum, loc,
-                               dsc, cal_id, busy, meeting, prio, sensi);
-       }
-       return is_exist;
-}
-
-int main(int argc, char **argv)
-{
-       int index;
-       int is_exist;;
-       long long int lli;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_connect();
-
-       printf("======= CALS_LIST_PERIOD_NORMAL_ONOFF ======\n");
-       printf("\nall calendar(-1)\n");
-       is_exist = _get_iter_period_normal_onoff(-1, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(1)\n");
-       is_exist = _get_iter_period_normal_onoff(1, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(2)\n");
-       is_exist = _get_iter_period_normal_onoff(2, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("======= CALS_LIST_PERIOD_ALLDAY_ONOFF ======\n");
-       printf("\nall calendar(-1)\n");
-       is_exist = _get_iter_period_allday_onoff(-1, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(1)\n");
-       is_exist = _get_iter_period_allday_onoff(1, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(2)\n");
-       is_exist = _get_iter_period_allday_onoff(2, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("======= CALS_LIST_PERIOD_NORMAL_BASIC ======\n");
-       printf("\nall calendar(-1)\n");
-       is_exist = _get_iter_period_normal_basic(-1, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(1)\n");
-       is_exist = _get_iter_period_normal_basic(1, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(2)\n");
-       is_exist = _get_iter_period_normal_basic(2, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("======= CALS_LIST_PERIOD_ALLDAY_BASIC ======\n");
-       printf("\nall calendar(-1)\n");
-       is_exist = _get_iter_period_allday_basic(-1, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(1)\n");
-       is_exist = _get_iter_period_allday_basic(1, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(2)\n");
-       is_exist = _get_iter_period_allday_basic(2, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("======= CALS_LIST_PERIOD_NORMAL_OSP ======\n");
-       printf("\nall calendar(-1)\n");
-       is_exist = _get_iter_period_normal_osp(-1, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(1)\n");
-       is_exist = _get_iter_period_normal_osp(1, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(2)\n");
-       is_exist = _get_iter_period_normal_osp(2, D20120601T000000, D20120931T100000);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("======= CALS_LIST_PERIOD_ALLDAY_OSP ======\n");
-       printf("\nall calendar(-1)\n");
-       is_exist = _get_iter_period_allday_osp(-1, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(1)\n");
-       is_exist = _get_iter_period_allday_osp(1, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-       printf("\ncalendar(2)\n");
-       is_exist = _get_iter_period_allday_osp(2, 2012, 6, 1, 2012, 9, 31);
-       if (is_exist == 0) {
-               printf("no data exist\n");
-       }
-
-
-
-       long long int ts;
-       int i, y, m, d;
-       char mon[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-       long long int th = 62167219200;
-
-       y = 1970;
-       m = 1;
-       d = 1;
-
-       ts = y*365;
-       printf("%lld\n", ts);
-       ts = ts + (int)y/4 - (int)y/100 + (int)y/400;
-       printf("%lld\n", ts);
-       for (i = 0; i < m-1; i++) {
-               ts += mon[i];
-       }
-       ts = ts + d;
-       printf("%lld\n", ts);
-       ts = ts * 24;
-       printf("%lld\n", ts);
-       ts = ts * 60;
-       printf("%lld\n", ts);
-       ts = ts * 60;
-       printf("bb:%lld\n", ts);
-       th = ts;
-
-
-       y = 2012;
-       m = 6;
-       d = 1;
-
-       ts = y*365;
-       printf("%lld\n", ts);
-       ts = ts + (int)y/4 - (int)y/100 + (int)y/400;
-       printf("%lld\n", ts);
-       for (i = 0; i < m-1; i++) {
-               ts += mon[i];
-       }
-       ts = ts + d;
-       printf("%lld\n", ts);
-       ts = ts * 24;
-       printf("%lld\n", ts);
-       ts = ts * 60;
-       printf("%lld\n", ts);
-       ts = ts * 60;
-       printf("%lld\n", ts);
-       ts = ts - 62167219200;
-       printf("aa%lld\n", ts);
-
-       ts = 1338508800;
-       ts = ts / 60;
-       printf("%lld\n", ts);
-       ts = ts / 60;
-       printf("%lld\n", ts);
-       ts = ts / 24;
-       printf("%lld\n", ts);
-
-       printf("%lld\n", ts / 365);
-       printf("%lld\n", ts % 365);
-
-       ts = ts - mon[m-1] - d;
-       printf("%lld\n", ts);
-       ts = ts - y/4 + y/100 - y/400;
-       printf("%lld\n", ts);
-
-       calendar_svc_close();
-       return 0;
-}
diff --git a/test/recur-add.c b/test/recur-add.c
deleted file mode 100644 (file)
index 26bab2d..0000000
+++ /dev/null
@@ -1,244 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <time.h>
-#include <calendar-svc-provider.h>
-#include "utime.h"
-
-#define D19700101 62167219200
-char cal_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-
-long long int _mkutime(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;
-}
-
-char *_mkdatetime(long long int lli)
-{
-       int y, mon, d, h, min, s;
-       long long int t;
-       static char buf[17];
-
-       t = lli + D19700101;
-       s = t % 60;
-       t /= 60;
-       min = t % 60;
-       t /= 60;
-       h = t % 24;
-       t /= 24;
-       y = (t * 400) / (365 * 400 + 100 - 4 + 1);
-       t = t - (y * 365) - (y/4) + (y/100) - (y/400);
-       mon = 0;
-       while (t > cal_month[mon]) {
-               if (t == 29 && mon == 1 && y % 4 == 0) {
-                       if (y % 100 == 0 && y % 400 != 0) {
-                               break;
-                       }
-               } else {
-                       t -= cal_month[mon];
-                       mon++;
-               }
-       }
-       mon++;
-       d = t;
-       snprintf(buf, sizeof(buf), "%04d/%02d/%02d %02d:%02d:%02dZ", y, mon, d, h, min, s);
-       return strdup(buf);
-}
-
-int main(int argc, char **argv)
-{
-       int ret;
-       int index = 0;
-       cal_struct *cs = NULL;
-
-       if (argc < 2) {
-               printf("needs 2 arguments\n");
-               return -1;
-       }
-
-       index = atoi(argv[1]);
-       if (index < 0) {
-               printf("Invalid index (%d)\n", index);
-               return -1;
-       }
-
-       cs = calendar_svc_struct_new(CAL_STRUCT_SCHEDULE);
-       if (cs == NULL) {
-               printf("Failed to new calendar\n");
-               return -1;
-       }
-
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_ACCOUNT_ID, -1);
-       calendar_svc_struct_set_int(cs, CAL_VALUE_INT_CALENDAR_ID, 1);
-
-       calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_SUMMARY, "event summary");
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_TYPE, CALS_TIME_UTIME);
-       calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_DTSTART_UTIME, D20120701T000000);
-       calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_DTSTART_TZID, "Europe/London");
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_TYPE, CALS_TIME_UTIME);
-       calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_DTEND_UTIME, D20120701T060000);
-       calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_DTEND_TZID, "Europe/London");
-
-
-       /* freq */
-
-       switch (index) {
-
-/* yearly */
-       case 0: // bad
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_YEARLY);
-               break;
-
-       case 1: // bad
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_YEARLY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMONTH, "7");
-               break;
-
-       case 2: // bad
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_YEARLY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYWEEKNO, "5, 6");
-               break;
-
-       case 3: // bad
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_YEARLY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYYEARDAY, "5");
-               break;
-
-       case 4:
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_YEARLY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMONTHDAY, "5");
-               break;
-
-/* monthly */
-       case 10: // bad
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_MONTHLY);
-               break;
-
-       case 11: // bad: not working bymonth
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_MONTHLY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMONTH, "3, 7");
-               break;
-
-       case 12: // good
-               printf("every 11st, 25th in a month\n");
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_MONTHLY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMONTHDAY, "11, 25");
-               break;
-
-       case 13: // good
-               printf("eveny 2nd Monday, 3rd Friday in a month\n");
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_MONTHLY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYDAY, "2MO,3FR");
-               break;
-
-       case 14: // bad
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_MONTHLY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYDAY, "2MO,3FR");
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYSETPOS, "2");
-               break;
-
-/* weekly */
-       case 20: // bad
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_WEEKLY);
-               break;
-
-       case 21: // bad
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_WEEKLY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMONTH, "3, 7");
-               break;
-
-       case 22: // good
-               printf("every Saturday, Tuesday in a week\n");
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_WEEKLY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYDAY, "SA,TU");
-               break;
-
-       case 23: // bad
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_WEEKLY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYDAY, "SA,TU");
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYSETPOS, "2");
-               break;
-
-/* daily */
-       case 30: //good
-               printf("every day\n");
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_DAILY);
-               break;
-
-       case 31: // bad
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_DAILY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMONTH, "3, 9");
-               break;
-
-       case 32: // bad
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_DAILY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYMONTHDAY, "10, 15");
-               break;
-
-       case 33: // bad
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_FREQ, CALS_FREQ_DAILY);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_RRULE_BYDAY, "SA");
-               break;
-
-       default:
-               break;
-
-       }
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_INTERVAL, 1);
-
-       /* until */
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_RANGE_TYPE, CALS_RANGE_COUNT);
-       calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_COUNT, 4);
-//     calendar_svc_struct_set_int(cs, CALS_VALUE_INT_RRULE_UNTIL_TYPE, CALS_TIME_UTIME);
-//     calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_RRULE_UNTIL_UTIME, D20150701T000000);
-
-       calendar_svc_connect();
-       ret = calendar_svc_insert(cs);
-       calendar_svc_struct_free(&cs);
-
-
-       int cnt = 0;
-       long long int dtstart_utime;
-       long long int from, to;
-       char *str;
-       cal_iter *iter = NULL;
-
-       from = _mkutime(2012, 1, 1, 0, 0, 0);
-       to = _mkutime(2012, 12, 31, 0, 0, 0);
-       calendar_svc_event_get_normal_list_by_period(1,
-                       CALS_LIST_PERIOD_NORMAL_ONOFF, from, to, &iter);
-
-       while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-               cs = NULL;
-               calendar_svc_iter_get_info(iter, &cs);
-               dtstart_utime = calendar_svc_struct_get_lli(cs,
-                               CALS_LIST_PERIOD_NORMAL_ONOFF_LLI_DTSTART_UTIME);
-               str = _mkdatetime(dtstart_utime);
-               printf("%02d dtstart_utime(%s)\n", ++cnt, str);
-               if (str) free(str);
-               calendar_svc_struct_free(&cs);
-       }
-
-//     calendar_svc_delete(CAL_STRUCT_SCHEDULE, ret);
-       calendar_svc_close();
-
-       return 0;
-}
diff --git a/test/schedule-test.c b/test/schedule-test.c
deleted file mode 100644 (file)
index f7b5229..0000000
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <stdio.h>
-#include <calendar-svc-provider.h>
-
-#include "test-log.h"
-
-#define ST_SUM "Weekly Meeting"
-#define ST_DESC "Review : Project status"
-#define ST_LOC "Meeting Room #1"
-#define ST_TZ "Asia/Seoul"
-#define ST_CTG "Business"
-#define ST_ATT1_NAME "David Lee"
-#define ST_ATT1_EMAIL "davidlee@gmail.com"
-#define ST_ATT2_NAME "Brian Kim"
-#define ST_ATT2_EMAIL "briankim@yahoo.com"
-
-static inline int insert()
-{
-       TEST_FN_START;
-
-       int ret;
-
-       cal_struct *event = NULL;
-       cal_value *attendee1 = NULL, *attendee2 = NULL;
-       GList *attendee_list=NULL;
-
-       time_t cur_time = time(NULL)+240;
-
-       event = calendar_svc_struct_new(CAL_STRUCT_SCHEDULE);
-
-       calendar_svc_struct_set_str(event, CAL_VALUE_TXT_SUMMARY, ST_SUM);
-       calendar_svc_struct_set_str(event, CAL_VALUE_TXT_DESCRIPTION, ST_DESC);
-       calendar_svc_struct_set_str(event, CAL_VALUE_TXT_LOCATION, ST_LOC);
-       calendar_svc_struct_set_int(event, CAL_VALUE_INT_REPEAT_TERM, 1);
-       calendar_svc_struct_set_int(event, CAL_VALUE_INT_REPEAT_INTERVAL, 3);
-       calendar_svc_struct_set_int(event, CAL_VALUE_INT_REPEAT_UNTIL_TYPE, CALS_REPEAT_UNTIL_TYPE_DATETIME);
-
-       calendar_svc_struct_set_time(event, CAL_VALUE_GMT_START_DATE_TIME, CAL_TZ_FLAG_GMT, cur_time);
-       calendar_svc_struct_set_time(event, CAL_VALUE_GMT_END_DATE_TIME, CAL_TZ_FLAG_GMT, cur_time+(60*60));
-       calendar_svc_struct_set_time(event, CAL_VALUE_GMT_REPEAT_END_DATE, CAL_TZ_FLAG_GMT, cur_time+(60*60*24*7));
-       calendar_svc_struct_set_str(event,CAL_VALUE_TXT_CATEGORIES, ST_CTG);
-       calendar_svc_struct_set_str(event,CAL_VALUE_TXT_TZ_NAME, ST_TZ);
-       calendar_svc_struct_set_double(event,CAL_VALUE_DBL_LATITUDE, 0.1);
-       calendar_svc_struct_set_double(event,CAL_VALUE_DBL_LONGITUDE, 0.2);
-
-       calendar_svc_struct_set_int(event, CAL_VALUE_INT_SYNC_STATUS,1);
-
-       attendee1 = calendar_svc_value_new(CAL_VALUE_LST_ATTENDEE_LIST);
-       if(attendee1) {
-               calendar_svc_value_set_str(attendee1, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME, ST_ATT1_NAME);
-               calendar_svc_value_set_str(attendee1, CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL, ST_ATT1_EMAIL);
-               calendar_svc_value_set_int(attendee1, CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS, 1);
-               calendar_svc_value_set_int(attendee1, CAL_VALUE_INT_ATTENDEE_DETAIL_CT_INDEX, 1);
-               attendee_list = g_list_append(attendee_list, attendee1);
-       }
-
-       attendee2 = calendar_svc_value_new(CAL_VALUE_LST_ATTENDEE_LIST);
-       if(attendee2) {
-               calendar_svc_value_set_str(attendee2, CAL_VALUE_TXT_ATTENDEE_DETAIL_NAME, ST_ATT2_NAME);
-               calendar_svc_value_set_str(attendee2, CAL_VALUE_TXT_ATTENDEE_DETAIL_EMAIL, ST_ATT2_EMAIL);
-               calendar_svc_value_set_int(attendee2, CAL_VALUE_INT_ATTENDEE_DETAIL_STATUS, 0);
-               calendar_svc_value_set_int(attendee2, CAL_VALUE_INT_ATTENDEE_DETAIL_CT_INDEX, 2);
-               attendee_list = g_list_append(attendee_list, attendee2);
-       }
-
-       ret = calendar_svc_struct_store_list(event, CAL_VALUE_LST_ATTENDEE_LIST, attendee_list);
-
-       ret = calendar_svc_insert(event);
-       calendar_svc_struct_free(&event);
-
-       return ret;
-}
-
-static inline void get(int index)
-{
-       TEST_FN_START;
-
-       cal_struct *event = NULL;
-       int ct_value = 0;
-       int repeat_term = 0;
-       int interval = 0;
-       int until_type = -1;
-       time_t r_end_date_time = 0;
-       GList *attendee_list=NULL;
-       time_t cur_time = time(NULL)+240;
-
-       event = NULL;
-       calendar_svc_get(CAL_STRUCT_SCHEDULE, index, NULL, &event);
-       repeat_term = calendar_svc_struct_get_int(event, CAL_VALUE_INT_REPEAT_TERM);
-       interval = calendar_svc_struct_get_int(event, CAL_VALUE_INT_REPEAT_INTERVAL);
-       until_type = calendar_svc_struct_get_int(event, CAL_VALUE_INT_REPEAT_UNTIL_TYPE);
-       r_end_date_time = calendar_svc_struct_get_time(event, CAL_VALUE_GMT_REPEAT_END_DATE,CAL_TZ_FLAG_LOCAL);
-
-       char *location = calendar_svc_struct_get_str(event,CAL_VALUE_TXT_LOCATION);
-       char *categories = calendar_svc_struct_get_str(event,CAL_VALUE_TXT_CATEGORIES);
-       char *tz_name = calendar_svc_struct_get_str(event,CAL_VALUE_TXT_TZ_NAME);
-
-       DBG("%s = %s", ST_TZ, tz_name);
-       DBG("%s = %s", ST_LOC, location);
-       DBG("%s = %s", ST_CTG, categories);
-
-       attendee_list = NULL;
-       calendar_svc_struct_get_list(event,CAL_VALUE_LST_ATTENDEE_LIST,&attendee_list);
-       ct_value = calendar_svc_value_get_int(attendee_list->data,CAL_VALUE_INT_ATTENDEE_DETAIL_CT_INDEX);
-
-       calendar_svc_struct_free(&event);
-}
-
-int search()
-{
-       TEST_FN_START;
-       int ret;
-       cal_struct *cs;
-       cal_iter *it;
-       char *summary;
-       char *location;
-       char *desc;
-       int id;
-
-       calendar_svc_connect();
-       int search_field;
-
-       search_field = CALS_SEARCH_FIELD_NONE;
-       search_field |= CALS_SEARCH_FIELD_SUMMARY;
-       search_field |= CALS_SEARCH_FIELD_DESCRIPTION;
-       search_field |= CALS_SEARCH_FIELD_LOCATION;
-       search_field |= CALS_SEARCH_FIELD_ATTENDEE;
-
-       ret = calendar_svc_event_search(search_field, "Brian", &it);
-       if (ret < 0) {
-               ERR("calendar_svc_event_search failed(%d)", ret);
-               return ret;
-       }
-
-       while (calendar_svc_iter_next(it) == CAL_SUCCESS) {
-               cs = NULL;
-               ret = calendar_svc_iter_get_info(it, &cs);
-               if (ret < 0) {
-                       ERR("calendar_svc_iter_get_info failed (%d)\n", ret);
-                       return ret;
-               }
-
-               id = calendar_svc_struct_get_int(cs, CAL_VALUE_INT_INDEX);
-               summary = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_SUMMARY);
-               desc = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_DESCRIPTION);
-               location = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_LOCATION);
-               DBG("\t%s = %s", ST_SUM, summary);
-               DBG("\t%s = %s", ST_DESC, desc);
-               DBG("\t%s = %s", ST_LOC, location);
-               calendar_svc_struct_free(&cs);
-       }
-
-       calendar_svc_iter_remove(&it);
-
-       calendar_svc_close();
-
-       return 0;
-}
-
-int smartsearch()
-{
-       TEST_FN_START;
-       int ret;
-       cal_struct *cs;
-       cal_iter *it;
-       char *summary;
-       char *location;
-       char *desc;
-       int id;
-
-       calendar_svc_connect();
-
-       ret = calendar_svc_smartsearch_excl("weekly", -1, 10, &it);
-       if (ret < 0) {
-               ERR("calendar_svc_event_search failed(%d)", ret);
-               return ret;
-       }
-
-       while (calendar_svc_iter_next(it) == CAL_SUCCESS) {
-               cs = NULL;
-               ret = calendar_svc_iter_get_info(it, &cs);
-               if (ret < 0) {
-                       ERR("calendar_svc_iter_get_info failed (%d)\n", ret);
-                       return ret;
-               }
-
-               id = calendar_svc_struct_get_int(cs, CAL_VALUE_INT_INDEX);
-               summary = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_SUMMARY);
-               desc = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_DESCRIPTION);
-               location = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_LOCATION);
-               DBG("ID = %d", id);
-               DBG("\t%s = %s", ST_SUM, summary);
-               DBG("\t%s = %s", ST_DESC, desc);
-               DBG("\t%s = %s", ST_LOC, location);
-               calendar_svc_struct_free(&cs);
-       }
-
-       calendar_svc_iter_remove(&it);
-
-       calendar_svc_close();
-
-       return 0;
-}
-
-
-int main(int argc, char **argv)
-{
-       int id;
-
-       calendar_svc_connect();
-
-       id = insert();
-       if (id) {
-               get(id);
-       }
-       search();
-       smartsearch();
-
-       calendar_svc_close();
-
-       return 0;
-}
-
diff --git a/test/test-alarm.c b/test/test-alarm.c
deleted file mode 100644 (file)
index 457957f..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-#include <unistd.h>
-#include <string.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <glib.h>
-#define _GNU_SOURCE
-#include <time.h>
-
-#include <calendar-svc-provider.h>
-
-#define ICALENAR_BUFFER_MAX 1024*1024
-
-static const char* calendar_svc_get_stream_from_ics(const char *path)
-{
-       FILE *file;
-       int buf_size, len;
-       char *stream;
-       char buf[1024];
-
-       file = fopen(path, "r");
-
-       len = 0;
-       buf_size = ICALENAR_BUFFER_MAX;
-       stream = malloc(ICALENAR_BUFFER_MAX);
-
-       while (fgets(buf, sizeof(buf), file)) {
-               if (len + sizeof(buf) < buf_size) {
-                       len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
-
-               } else {
-                       char *new_stream;
-                       buf_size *= 2;
-                       new_stream = realloc(stream, buf_size);
-                       if (new_stream) {
-                               stream = new_stream;
-                       } else {
-                               free(stream);
-                               fclose(file);
-                               printf("out of memory\n");
-                               return NULL;
-                       }
-                       len += snprintf(stream + len, strlen(buf) +1, "%s", buf);
-               }
-       }
-       fclose(file);
-       return stream;
-}
-
-
-
-int main(int argc, char **argv)
-{
-fprintf(stdout, "%s\n", __func__);
-       const char *stream;
-       GList *list_sch = NULL, *l;
-       int i = 0;
-
-       if (argc < 2) return -1;
-
-       fprintf(stdout, "file path:%s\n", argv[1]);
-       if (access(argv[1], F_OK) != 0) {
-               fprintf(stdout, "Failed to access (%s)\n", argv[1]);
-               return -1;
-       }
-
-       stream = calendar_svc_get_stream_from_ics(argv[1]);
-       calendar_svc_ics_to_sch(stream, &list_sch);
-
-       if (list_sch == NULL) {
-               fprintf(stdout, "No list\n");
-               return 0;
-       }
-
-
-       l = list_sch;
-       while (l) {
-               cal_struct *event;
-               char *str;
-               printf("%d\n", i++);
-/*
-               calendar_svc_get(CAL_STRUCT_SCHDULE, 1, NULL, &event);
-               str = calendar_svc_struct_get_str(l->data, CAL_VALUE_TXT_SUMMARY);
-               if (str) {
-                       printf("summary(%s)\n", str);
-               }
-*/
-               l = g_list_next(l);
-       }
-
-//     calendar_svc_struct_free(&event);
-
-       l = list_sch;
-       while (l = g_list_next(l)) {
-               if (l) {
-                       fprintf(stdout, "exist\n");
-               }
-       }
-
-
-       if (stream) {
-               free(stream);
-       }
-       return 0;
-}
diff --git a/test/timetest.c b/test/timetest.c
deleted file mode 100644 (file)
index f1cb97d..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Calendar Service
- *
- * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/time.h>
-#include "timetest.h"
-#include "test-log.h"
-
-FILE *outfp;
-double correction;
-
-double set_start_time(void)
-{
-       //      TEST_FN_START;
-
-       struct timeval tv;
-       double curtime;
-
-       gettimeofday(&tv, NULL);
-       curtime = tv.tv_sec * 1000 + (double)tv.tv_usec/1000;
-       return curtime;
-}
-
-double exec_time(double start)
-{
-       //      TEST_FN_START;
-
-       double end = set_start_time();
-       return (end - start - correction);
-}
-
-int init_time(void)
-{
-       //      TEST_FN_START;
-
-       double temp_t;
-       temp_t = set_start_time();
-       correction = exec_time(temp_t);
-
-       return 0;
-}
-
-int print_time(char *prn_args, double time)
-{
-       TEST_FN_START;
-
-#ifdef USE_STD_OUT
-       printf("%200s =\t", prn_args);
-       printf("%f \n", time);
-#else
-       fprintf(outfp, "%.50s\t", prn_args);
-       fprintf(outfp, "%f \n", time);
-#endif
-
-       return 0;
-}
-
-
-int print_argument(char *prn_args)
-{
-       TEST_FN_START;
-
-#ifdef USE_STD_OUT
-       printf("%s", prn_args);
-#else
-       fprintf(outfp, "%s\n", prn_args);
-#endif
-
-       return 0;
-}
-
-
-
-int print_milestone(char *prn_args, int level)
-{
-       TEST_FN_START;
-       int i;
-
-       if (level > 1) {
-               for (i=0;i<level;i++)
-                       printf("\n##################################################################\n");
-               printf("\n%s =\n", prn_args);
-               for (i=0;i<level;i++)
-                       printf("\n##################################################################\n");
-       }
-
-#ifdef USE_STD_OUT
-       if (1 == level)
-               printf("\n##################################################################\n");
-       printf("\n%s =\n", prn_args);
-       printf("\n##################################################################\n");
-#else
-       for (i=0;i<level;i++)
-               fprintf(outfp, "\n##################################################################\n");
-       fprintf(outfp, "%s \n", prn_args);
-       for (i=0;i<level;i++)
-               fprintf(outfp, "\n##################################################################\n");
-#endif
-
-
-       return 0;
-}
-
-int std_output(char *prn_args, double time)
-{
-       TEST_FN_START;
-
-       printf("%.50s =\t", prn_args);
-       printf("%f \n", time);
-
-       return 0;
-}
-
-
-int file_print_init(char *filename)
-{
-       TEST_FN_START;
-
-       outfp = fopen(filename, "w"); //"aw"
-       if (NULL == outfp) {
-               ERR("(%s) Open Error", filename);
-               return -1;
-
-       }
-       return 0;
-}
-
diff --git a/test/todo-add.c b/test/todo-add.c
deleted file mode 100644 (file)
index cc2ed09..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-
-#include <stdio.h>
-#include <time.h>
-#include <calendar-svc-provider.h>
-#include "utime.h"
-
-int main(int argc, char **argv)
-{
-       int i;
-       int ret;
-       char buf[32] = {0};
-       cal_struct *cs = NULL;
-
-       calendar_svc_connect();
-
-       for (i = 0; i < 10; i++) {
-               printf("start insert priority:%d\n", i);
-               cs = calendar_svc_struct_new(CAL_STRUCT_TODO);
-               if (cs == NULL) {
-                       printf("Failed to new calendar\n");
-                       return -1;
-               }
-
-               calendar_svc_struct_set_int(cs, CAL_VALUE_INT_ACCOUNT_ID, 1);
-               calendar_svc_struct_set_int(cs, CAL_VALUE_INT_TASK_STATUS, 1);
-               calendar_svc_struct_set_int(cs, CAL_VALUE_INT_CALENDAR_TYPE, 2);
-               calendar_svc_struct_set_int(cs, CAL_VALUE_INT_CALENDAR_ID, 1);
-               calendar_svc_struct_set_int(cs, CAL_VALUE_INT_PRIORITY, i);
-               snprintf(buf, sizeof(buf), "status:1 /priority:%d", i);
-               calendar_svc_struct_set_str(cs, CAL_VALUE_TXT_SUMMARY, buf);
-
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTSTART_TYPE, CALS_TIME_UTIME);
-               calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_DTSTART_UTIME, D20120701T000000);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_DTSTART_TZID, "Europe/London");
-               calendar_svc_struct_set_int(cs, CALS_VALUE_INT_DTEND_TYPE, CALS_TIME_UTIME);
-               calendar_svc_struct_set_lli(cs, CALS_VALUE_LLI_DTEND_UTIME, D20120901T000000);
-               calendar_svc_struct_set_str(cs, CALS_VALUE_TXT_DTEND_TZID, "Europe/London");
-
-               ret = calendar_svc_insert(cs);
-               calendar_svc_struct_free(&cs);
-       }
-       calendar_svc_close();
-
-       return 0;
-}
-
-
-
diff --git a/test/todo-period.c b/test/todo-period.c
deleted file mode 100644 (file)
index 5d32501..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-
-#include <stdio.h>
-#include <time.h>
-#include <calendar-svc-provider.h>
-#include "utime.h"
-
-struct _pair {
-       int i;
-       char *s;
-};
-
-struct _pair is[8] = {
-       {CALS_TODO_PRIORITY_NONE, "CALS_TODO_PRIORITY_NONE"},
-       {CALS_TODO_PRIORITY_HIGH, "CALS_TODO_PRIORITY_HIGH"},
-       {CALS_TODO_PRIORITY_MID,"CALS_TODO_PRIORITY_MID"},
-       {CALS_TODO_PRIORITY_LOW,"CALS_TODO_PRIORITY_LOW"},
-       {CALS_TODO_PRIORITY_HIGH | CALS_TODO_PRIORITY_MID | CALS_TODO_PRIORITY_LOW, "CALS_TODO_PRIORITY_HIGH |MID | LOW"},
-       {CALS_TODO_PRIORITY_HIGH | CALS_TODO_PRIORITY_MID, "CALS_TODO_PRIORITY_HIGH | MID"},
-       {CALS_TODO_PRIORITY_HIGH | CALS_TODO_PRIORITY_LOW, "CALS_TODO_PRIORITY_HIGH | LOW"},
-       {CALS_TODO_PRIORITY_MID | CALS_TODO_PRIORITY_LOW, "CALS_TODO_PRIORITY_MID | LOW"}
-};
-
-
-int main(int argc, char **argv)
-{
-       int i, count;
-       int ret, is_exist;;
-       char *sum;
-       cal_iter *iter;
-       cal_struct *cs;
-
-       calendar_svc_connect();
-printf("%d\n", CALS_TODO_STATUS_NEEDS_ACTION | CALS_TODO_STATUS_COMPLETED | CALS_TODO_STATUS_IN_PROCESS | CALS_TODO_STATUS_CANCELLED);
-
-       for (i = 0; i < 8; i++) {
-               printf("start (priority:%d)%s\n", is[i].i, is[i].s);
-
-               calendar_svc_todo_get_count_by_period(1,
-//                             D20120601T000000, D20120931T100000, is[i].i, -1, &count);
-                               200, 400, is[i].i,
-                               CALS_TODO_STATUS_NEEDS_ACTION | CALS_TODO_STATUS_COMPLETED |
-                                       CALS_TODO_STATUS_IN_PROCESS | CALS_TODO_STATUS_CANCELLED,
-                               &count);
-               if (ret != CAL_SUCCESS) {
-                       printf("Failed to get count\n");
-                       return -1;
-               }
-               printf("count(%d)\n", count);
-
-
-
-               ret = calendar_svc_todo_get_list_by_period(1,
-//                             D20120601T000000, D20120931T100000, is[i].i, 0, &iter);
-                               200, 400, is[i].i,
-                               CALS_TODO_STATUS_NEEDS_ACTION | CALS_TODO_STATUS_COMPLETED |
-                                       CALS_TODO_STATUS_IN_PROCESS | CALS_TODO_STATUS_CANCELLED,
-                               &iter);
-               if (ret != CAL_SUCCESS) {
-                       printf("Failed to get list\n");
-                       break;
-               }
-               is_exist = 0;
-               while (calendar_svc_iter_next(iter) == CAL_SUCCESS) {
-                       is_exist = 1;
-                       cs = NULL;
-                       calendar_svc_iter_get_info(iter, &cs);
-                       sum = calendar_svc_struct_get_str(cs, CAL_VALUE_TXT_SUMMARY);
-                       printf("sum(%s)\n", sum);
-               }
-               if (is_exist == 0) {
-                       printf("No date\n");
-               }
-       }
-       calendar_svc_close();
-       return 0;
-}
-
-
-
-
-
diff --git a/test/utime.h b/test/utime.h
deleted file mode 100644 (file)
index 818ac52..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-
-#define D20120601T000000 1338508800
-#define D20120701T000000 1341100800
-#define D20120701T060000 1341122400
-#define D20120801T000000 1343779200
-#define D20120901T000000 1346457600
-#define D20120931T100000 1349085600
-#define D20150701T000000 1435708800
diff --git a/test/versiontest.c b/test/versiontest.c
deleted file mode 100644 (file)
index 55bbd50..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-#include <calendar-svc-provider.h>
-#include <stdio.h>
-
-int main(void)
-{
-       int ret;
-       cal_struct *cs;
-       cal_iter *it;
-       int id;
-       int type;
-       int ver;
-
-       calendar_svc_connect();
-
-       ret = calendar_svc_event_get_changes(1, 0, &it);
-       if (ret < 0)
-               return -1;
-
-       while (calendar_svc_iter_next(it) == CAL_SUCCESS) {
-               cs = NULL;
-               ret = calendar_svc_iter_get_info(it, &cs);
-               if (ret != CAL_SUCCESS) {
-                       printf("calendar_svc_iter_get_info failed (%d)\n", ret);
-                       return -1;
-               }
-
-               type = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_TYPE);
-               id = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_ID);
-               ver = calendar_svc_struct_get_int(cs, CALS_STRUCT_UPDATED_INT_VERSION);
-               printf("type = %d id = %d ver = %d\n", type, id, ver);
-               calendar_svc_struct_free(&cs);
-       }
-
-       calendar_svc_iter_remove(&it);
-
-       calendar_svc_close();
-
-       return 0;
-}
-
-