From 0225bbf56460f0295024275366847dacf9880b3a Mon Sep 17 00:00:00 2001 From: Jeesun Kim Date: Fri, 29 Mar 2013 18:43:56 +0900 Subject: [PATCH] [misc] mod reminder noti callback --- calendar.pc | 2 +- client/cal_client_reminder.c | 12 ++----- client/cal_client_reminder.h | 1 + client/calendar-service2.pc | 2 +- common/cal_time.cpp | 8 ++++- common/cal_time.h | 1 + common/cal_vcalendar_make.c | 71 +++++++++++++++++++++++++++----------- common/cal_vcalendar_parse.c | 25 ++++++-------- include/calendar2.h | 30 ++++++++++++----- include/calendar_types2.h | 5 ++- native/cal_db_instance.c | 12 ++++--- native/cal_db_plugin_event.c | 75 ++++++++++++++++++++++++++++++----------- native/cal_db_rrule.c | 62 +++++++++++++++++++++++++--------- packaging/calendar-service.spec | 2 +- server/cal_server_reminder.c | 66 +++++++++++++++++++++++++++--------- 15 files changed, 260 insertions(+), 114 deletions(-) diff --git a/calendar.pc b/calendar.pc index 6969f74..65f36aa 100755 --- a/calendar.pc +++ b/calendar.pc @@ -8,6 +8,6 @@ includedir=${prefix}/include/calendar-service2 Name: calendar-service2 Description: calendar-service2 library Version: 0.1.8 -Requires: glib-2.0 alarm-service bundle +Requires: glib-2.0 alarm-service Libs: -L${libdir} -lcalendar-service2 Cflags: -I${includedir} diff --git a/client/cal_client_reminder.c b/client/cal_client_reminder.c index 3d525a5..1aa0d40 100644 --- a/client/cal_client_reminder.c +++ b/client/cal_client_reminder.c @@ -355,7 +355,7 @@ int _cal_client_reminder_destroy_for_subscribe(void) static void __cal_client_reminder_subscribe_callback(pims_ipc_h ipc, pims_ipc_data_h data, void *user_data) { unsigned int size = 0; - const unsigned char *str = NULL; + const char *str = NULL; int len = 0; subscribe_info_s *info = user_data; @@ -367,7 +367,7 @@ static void __cal_client_reminder_subscribe_callback(pims_ipc_h ipc, pims_ipc_da ERR("pims_ipc_data_get() failed"); return; } - str = (const unsigned char *)pims_ipc_data_get(data, &size); + str = (const char *)pims_ipc_data_get(data, &size); if (!str) { ERR("pims_ipc_data_get() failed"); @@ -382,13 +382,7 @@ static void __cal_client_reminder_subscribe_callback(pims_ipc_h ipc, pims_ipc_da callback_info_s *cb_info = l->data; if (NULL == cb_info) continue; - bundle *b = NULL; - b = bundle_decode(str, len); - if (b) - { - cb_info->cb(b, cb_info->user_data); - bundle_free(b); - } + cb_info->cb(str, cb_info->user_data); } } } diff --git a/client/cal_client_reminder.h b/client/cal_client_reminder.h index 39ea4cf..6dd4ceb 100644 --- a/client/cal_client_reminder.h +++ b/client/cal_client_reminder.h @@ -21,5 +21,6 @@ #define __CAL_CLIENT_REMINDER_H__ int _cal_client_reminder_create_for_subscribe(void); +int _cal_client_reminder_destroy_for_subscribe(void); #endif // __CAL_CLIENT_REMINDER_H__ diff --git a/client/calendar-service2.pc b/client/calendar-service2.pc index 579da21..d08e10a 100755 --- a/client/calendar-service2.pc +++ b/client/calendar-service2.pc @@ -7,7 +7,7 @@ includedir=${prefix}/include/calendar-service2 Name: calendar-service2 Description: calendar-service2 library -Version: 0.1.13 +Version: 0.1.14 Requires: glib-2.0 alarm-service Libs: -L${libdir} -lcalendar-service2 Cflags: -I${includedir} diff --git a/common/cal_time.cpp b/common/cal_time.cpp index 3625e53..f1a0bd3 100644 --- a/common/cal_time.cpp +++ b/common/cal_time.cpp @@ -444,6 +444,11 @@ char * _cal_time_extract_by(const char *tzid, int wkst, calendar_time_s *ct, int 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); @@ -507,7 +512,7 @@ char * _cal_time_convert_ltos(const char *tzid, long long int lli) 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; + UCalendar *ucal = NULL; UErrorCode status = U_ZERO_ERROR; ucal = _cal_time_get_ucal(tzid, -1); @@ -518,6 +523,7 @@ long long int _cal_time_convert_itol(const char *tzid, int y, int mon, int d, in 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); diff --git a/common/cal_time.h b/common/cal_time.h index 8281ea1..5d47259 100644 --- a/common/cal_time.h +++ b/common/cal_time.h @@ -46,6 +46,7 @@ int _cal_time_get_timezone_from_table(const char *tzid, calendar_record_h *timez int _cal_time_get_like_tzid(const char *tzid, calendar_record_h timezone, char **like_tzid); enum cal_extract_field { + CAL_MONTH, CAL_DAY_OF_WEEK, CAL_DATE, }; diff --git a/common/cal_vcalendar_make.c b/common/cal_vcalendar_make.c index baa650a..7945f9f 100644 --- a/common/cal_vcalendar_make.c +++ b/common/cal_vcalendar_make.c @@ -230,7 +230,7 @@ static inline int __cal_vcalendar_make_created(cal_make_s *b, long long int t) return CALENDAR_ERROR_NONE; } -static inline int __cal_vcalendar_make_dtstart(cal_make_s *b, char *tzid, calendar_time_s *caltime) +static inline int __cal_vcalendar_make_dtstart(int version, cal_make_s *b, char *tzid, calendar_time_s *caltime) { retvm_if(caltime == NULL, -1, "Invalid argument: calendar_time_s is NULL"); @@ -245,7 +245,7 @@ static inline int __cal_vcalendar_make_dtstart(cal_make_s *b, char *tzid, calend case CALENDAR_TIME_UTIME: { char* str_time = NULL; - if (NULL != tzid && strlen(tzid) > 0) + if (version != 1 && NULL != tzid && strlen(tzid) > 0) { str_time = _cal_time_convert_ltos(tzid, caltime->time.utime); if (str_time) @@ -269,9 +269,20 @@ static inline int __cal_vcalendar_make_dtstart(cal_make_s *b, char *tzid, calend break; case CALENDAR_TIME_LOCALTIME: - __cal_vcalendar_make_printf(b, "DTSTART;VALUE=DATE:", - __cal_vcalendar_make_itos(caltime->time.date.year, - caltime->time.date.month, caltime->time.date.mday)); + if (version == 1) + { + char buf[16] = {0}; + snprintf(buf, sizeof(buf), "%04d%02d%02dT000000", + caltime->time.date.year, caltime->time.date.month, caltime->time.date.mday); + __cal_vcalendar_make_printf(b, "DTSTART:", buf); + + } + else + { + __cal_vcalendar_make_printf(b, "DTSTART;VALUE=DATE:", + __cal_vcalendar_make_itos(caltime->time.date.year, + caltime->time.date.month, caltime->time.date.mday)); + } break; } @@ -333,7 +344,7 @@ int __cal_vcalendar_make_dtstamp(cal_make_s *b, char *tzid) return CALENDAR_ERROR_NONE; } -static inline int __cal_vcalendar_make_dtend(cal_make_s *b, char *tzid, calendar_time_s *caltime) +static inline int __cal_vcalendar_make_dtend(int version, cal_make_s *b, char *tzid, calendar_time_s *caltime) { retvm_if(caltime == NULL, -1, "Invalid argument: calendar_time_s is NULL"); @@ -348,7 +359,7 @@ static inline int __cal_vcalendar_make_dtend(cal_make_s *b, char *tzid, calendar case CALENDAR_TIME_UTIME: { char* str_time = NULL; - if (NULL != tzid && strlen(tzid) > 0) + if (version != 1 && NULL != tzid && strlen(tzid) > 0) { str_time = _cal_time_convert_ltos(tzid, caltime->time.utime); if (str_time) @@ -372,16 +383,27 @@ static inline int __cal_vcalendar_make_dtend(cal_make_s *b, char *tzid, calendar break; case CALENDAR_TIME_LOCALTIME: - __cal_vcalendar_make_printf(b, "DTEND;VALUE=DATE:", - __cal_vcalendar_make_itos(caltime->time.date.year, - caltime->time.date.month, caltime->time.date.mday)); + if (version == 1) + { + char buf[16] = {0}; + snprintf(buf, sizeof(buf), "%04d%02d%02dT000000", + caltime->time.date.year, caltime->time.date.month, caltime->time.date.mday); + __cal_vcalendar_make_printf(b, "DTEND:", buf); + + } + else + { + __cal_vcalendar_make_printf(b, "DTEND;VALUE=DATE:", + __cal_vcalendar_make_itos(caltime->time.date.year, + caltime->time.date.month, caltime->time.date.mday)); + } break; } return CALENDAR_ERROR_NONE; } -static inline int __cal_vcalendar_make_due(cal_make_s *b, char *tzid, calendar_time_s *caltime) +static inline int __cal_vcalendar_make_due(int version, cal_make_s *b, char *tzid, calendar_time_s *caltime) { retvm_if(caltime == NULL, -1, "Invalid argument: calendar_time_s is NULL"); @@ -396,7 +418,7 @@ static inline int __cal_vcalendar_make_due(cal_make_s *b, char *tzid, calendar_ case CALENDAR_TIME_UTIME: { char* str_time = NULL; - if (NULL != tzid && strlen(tzid) > 0) + if (version != 1 && NULL != tzid && strlen(tzid) > 0) { str_time = _cal_time_convert_ltos(tzid, caltime->time.utime); if (str_time) @@ -420,9 +442,20 @@ static inline int __cal_vcalendar_make_due(cal_make_s *b, char *tzid, calendar_ break; case CALENDAR_TIME_LOCALTIME: - __cal_vcalendar_make_printf(b, "DUE:", - __cal_vcalendar_make_itos(caltime->time.date.year, - caltime->time.date.month, caltime->time.date.mday)); + if (version == 1) + { + char buf[16] = {0}; + snprintf(buf, sizeof(buf), "%04d%02d%02dT000000", + caltime->time.date.year, caltime->time.date.month, caltime->time.date.mday); + __cal_vcalendar_make_printf(b, "DUE:", buf); + + } + else + { + __cal_vcalendar_make_printf(b, "DUE:", + __cal_vcalendar_make_itos(caltime->time.date.year, + caltime->time.date.month, caltime->time.date.mday)); + } break; } @@ -1286,7 +1319,7 @@ int __cal_vcalendar_make_schedule(int version, cal_make_s *b, calendar_record_h ERR("Failed to get start_time(%d)", ret); return -1; } - ret = __cal_vcalendar_make_dtstart(b, tzid, &caltime); + ret = __cal_vcalendar_make_dtstart(version, b, tzid, &caltime); retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get dtstart(%d)", ret); @@ -1376,7 +1409,7 @@ int __cal_vcalendar_make_schedule(int version, cal_make_s *b, calendar_record_h retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get end_time(%d)", ret); - ret = __cal_vcalendar_make_dtend(b, tzid, &caltime); + ret = __cal_vcalendar_make_dtend(version, b, tzid, &caltime); retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get end(%d)", ret); // categories @@ -1509,7 +1542,7 @@ int __cal_vcalendar_make_todo(int version, cal_make_s *b, calendar_record_h reco ERR("Failed to get start_time(%d)", ret); return -1; } - ret = __cal_vcalendar_make_dtstart(b, tzid, &caltime); + ret = __cal_vcalendar_make_dtstart(version, b, tzid, &caltime); retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get dtstart(%d)", ret); @@ -1567,7 +1600,7 @@ int __cal_vcalendar_make_todo(int version, cal_make_s *b, calendar_record_h reco retvm_if(ret != CALENDAR_ERROR_NONE, -1, "Failed to get due_time(%d)", ret); - ret = __cal_vcalendar_make_due(b, tzid, &caltime); + ret = __cal_vcalendar_make_due(version, b, tzid, &caltime); retvm_if(ret != CALENDAR_ERROR_NONE, -1, "__cal_vcalendar_make_due() failed(%d)", ret); // categories diff --git a/common/cal_vcalendar_parse.c b/common/cal_vcalendar_parse.c index a60ad8b..04466fc 100644 --- a/common/cal_vcalendar_parse.c +++ b/common/cal_vcalendar_parse.c @@ -608,7 +608,6 @@ static int __cal_vcalendar_parse_uid(int type, calendar_list_h list, calendar_re static int __cal_vcalendar_parse_get_tzid_from_list(calendar_list_h list, const char *tzid, calendar_record_h *timezone) { GList *l = NULL; - int ret = 0; if (list == NULL || tzid == NULL) { @@ -623,22 +622,20 @@ static int __cal_vcalendar_parse_get_tzid_from_list(calendar_list_h list, const char *uri = NULL; calendar_record_h record = (calendar_record_h)l->data; calendar_record_get_uri_p(record, &uri); - if (CALENDAR_ERROR_NONE == ret) + if (strncmp(uri, _calendar_timezone._uri, strlen(_calendar_timezone._uri))) { - if (strncmp(uri, _calendar_timezone._uri, strlen(_calendar_timezone._uri))) - { - l = g_list_next(l); - continue; - } + 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; - } + 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); } diff --git a/include/calendar2.h b/include/calendar2.h index 91f5b6f..de3afd3 100755 --- a/include/calendar2.h +++ b/include/calendar2.h @@ -528,11 +528,11 @@ /** * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE - * @defgroup CAPI_SOCIAL_CALENDAR_SVC_RECORD_MODULE Record + * @defgroup CAPI_SOCIAL_CALENDAR_SVC_FILTER_MODULE Filter * - * @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. + * @brief The calendar database API provides the set of the definitions and interfaces that enable you to handle filter. * - * @section CAPI_SOCIAL_CALENDAR_SVC_RECORD_MODULE_HEADER Required Header + * @section CAPI_SOCIAL_CALENDAR_SVC_FILTER_MODULE_HEADER Required Header * \#include * *
@@ -552,11 +552,11 @@ /** * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE - * @defgroup CAPI_SOCIAL_CALENDAR_SVC_FILTER_MODULE Filter + * @defgroup CAPI_SOCIAL_CALENDAR_SVC_QUERY_MODULE Query * - * @brief The calendar database API provides the set of the definitions and interfaces that enable you to handle filter. + * @brief The calendar database API provides the set of the definitions and interfaces that enable you to handle query. * - * @section CAPI_SOCIAL_CALENDAR_SVC_FILTER_MODULE_HEADER Required Header + * @section CAPI_SOCIAL_CALENDAR_SVC_QUERY_MODULE_HEADER Required Header * \#include * *
@@ -564,11 +564,23 @@ /** * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE - * @defgroup CAPI_SOCIAL_CALENDAR_SVC_QUERY_MODULE Query + * @defgroup CAPI_SOCIAL_CALENDAR_SVC_RECORD_MODULE Record * - * @brief The calendar database API provides the set of the definitions and interfaces that enable you to handle query. + * @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_QUERY_MODULE_HEADER Required Header + * @section CAPI_SOCIAL_CALENDAR_SVC_RECORD_MODULE_HEADER Required Header + * \#include + * + *
+ */ + +/** + * @ingroup CAPI_SOCIAL_CALENDAR_SVC_MODULE + * @defgroup CAPI_SOCIAL_CALENDAR_SVC_REMINDER_MODULE Reminder + * + * @brief The calendar record API provides the set of the definitions and interfaces that enable you to get/set reminder. + * + * @section CAPI_SOCIAL_CALENDAR_SVC_REMINDER_MODULE_HEADER Required Header * \#include * *
diff --git a/include/calendar_types2.h b/include/calendar_types2.h index 5fe2ef5..975db0a 100644 --- a/include/calendar_types2.h +++ b/include/calendar_types2.h @@ -20,7 +20,6 @@ #include #include #include -#include #ifdef __cplusplus extern "C" { @@ -113,12 +112,12 @@ typedef void (*calendar_db_changed_cb)(const char* view_uri, void* user_data); /** * @brief Called when alarm is alerted. * - * @param[in] b bundle + * @param[in] consta char *param * @param[in] user_data The user data passed from the callback registration function * * @see calendar_db_add_changed_cb() */ -typedef void (*calendar_reminder_cb)(bundle *b, void* user_data); +typedef void (*calendar_reminder_cb)(const char *param, void* user_data); /** * @brief Definition for calendar connect flag diff --git a/native/cal_db_instance.c b/native/cal_db_instance.c index e74ea36..b7588d5 100644 --- a/native/cal_db_instance.c +++ b/native/cal_db_instance.c @@ -1654,13 +1654,9 @@ static int __cal_db_instance_publish_record_yearly(UCalendar *ucal, cal_event_s { __cal_db_instance_publish_with_wday(ucal, event, duration, UCAL_YEAR, until); } - else if (event->bymonthday && strlen(event->bymonthday) > 0) - { - __cal_db_instance_publish_with_mday(ucal, event, duration, UCAL_YEAR, until); - } else { - ERR("Not completed"); + __cal_db_instance_publish_with_mday(ucal, event, duration, UCAL_YEAR, until); } } @@ -1789,6 +1785,12 @@ static int __cal_db_instance_publish_record_details(UCalendar *ucal, cal_event_s event->freq = CALENDAR_RECURRENCE_NONE; } + DBG("event interval(%d)", event->interval); + if (event->interval < 1) + { + DBG("Invalid interval, so set 1"); + event->interval = 1; + } switch (event->range_type) { diff --git a/native/cal_db_plugin_event.c b/native/cal_db_plugin_event.c index 780a049..7197746 100644 --- a/native/cal_db_plugin_event.c +++ b/native/cal_db_plugin_event.c @@ -93,8 +93,6 @@ static int __cal_db_event_check_value_validation(cal_event_s *event) return CALENDAR_ERROR_INVALID_PARAMETER; } - long long int slli = 0; - long long int elli = 0; switch (event->start.type) { case CALENDAR_TIME_UTIME: @@ -130,16 +128,30 @@ static int __cal_db_event_check_value_validation(cal_event_s *event) } // check start > end - slli = _cal_time_convert_itol(NULL, event->start.time.date.year, - event->start.time.date.month, event->start.time.date.mday, 0, 0, 0); - elli = _cal_time_convert_itol(NULL, event->end.time.date.year, - event->end.time.date.month, event->end.time.date.mday, 0, 0, 0); - - if (slli > elli) + if (event->start.time.date.year > event->end.time.date.year) { - ERR("allday start(%lld) > end(%lld)", slli, elli); + ERR("allday start year(%d) > end year(%d)", + event->start.time.date.year > event->end.time.date.year); return CALENDAR_ERROR_INVALID_PARAMETER; } + else + { + if (event->start.time.date.month > event->end.time.date.month) + { + ERR("allday start month(%d) > end month(%d)", + event->start.time.date.month, event->end.time.date.month); + return CALENDAR_ERROR_INVALID_PARAMETER; + } + else + { + if (event->start.time.date.mday > event->end.time.date.mday) + { + ERR("allday start day(%d) > end day(%d)", + event->start.time.date.mday, event->end.time.date.mday); + return CALENDAR_ERROR_INVALID_PARAMETER; + } + } + } break; } @@ -391,7 +403,11 @@ static int __cal_db_event_insert_record(calendar_record_h record, int* id) _cal_db_rrule_set_default(record); _cal_db_rrule_get_rrule_from_event(record, &rrule); - _cal_db_rrule_insert_record(event_id, rrule); + if (rrule) + { + _cal_db_rrule_insert_record(event_id, rrule); + CAL_FREE(rrule); + } _cal_db_instance_publish_record(record); calendar_list_h list; @@ -450,7 +466,6 @@ static int __cal_db_event_insert_record(calendar_record_h record, int* id) DBG("No extended"); } - CAL_FREE(rrule); _cal_db_util_notify(CAL_NOTI_TYPE_EVENT); _cal_record_set_int(record, _calendar_event.id, tmp); @@ -766,8 +781,11 @@ static int __cal_db_event_update_record(calendar_record_h record) __cal_db_event_update_original_event_version(event->original_event_id, input_ver); _cal_db_rrule_get_rrule_from_event(record, &rrule); - _cal_db_rrule_update_record(event->index, rrule); - CAL_FREE(rrule); + if (rrule) + { + _cal_db_rrule_update_record(event->index, rrule); + CAL_FREE(rrule); + } ret = _cal_db_instance_discard_record(record); retvm_if(ret != CALENDAR_ERROR_NONE, CALENDAR_ERROR_DB_FAILED, @@ -858,10 +876,11 @@ static int __cal_db_event_add_exdate(calendar_record_h record) // add recurrence id to end of the exdate of original event. const unsigned char *temp; + int len = 0; char *exdate = NULL; if (CAL_DB_ROW == _cal_db_util_stmt_step(stmt)) { - temp = sqlite3_column_text(stmt, 1); + temp = sqlite3_column_text(stmt, 0); if (NULL == temp) { exdate = strdup(event->recurrence_id); @@ -874,8 +893,15 @@ static int __cal_db_event_add_exdate(calendar_record_h record) sqlite3_finalize(stmt); return CALENDAR_ERROR_NONE; } - exdate = strdup((char *)temp); - strcat(exdate, event->recurrence_id); + len = strlen((const char *)temp) + strlen(event->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, event->recurrence_id); } } else @@ -904,6 +930,7 @@ static int __cal_db_event_add_exdate(calendar_record_h record) 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: @@ -912,6 +939,8 @@ static int __cal_db_event_add_exdate(calendar_record_h record) return CALENDAR_ERROR_DB_FAILED; } } + if (exdate) free(exdate); + return CALENDAR_ERROR_NONE; } @@ -1732,8 +1761,11 @@ static int __cal_db_event_replace_record(calendar_record_h record, int id) __cal_db_event_update_original_event_version(event->original_event_id, input_ver); _cal_db_rrule_get_rrule_from_event(record, &rrule); - _cal_db_rrule_update_record(id, rrule); - CAL_FREE(rrule); + if (rrule) + { + _cal_db_rrule_update_record(id, rrule); + CAL_FREE(rrule); + } ret = _cal_db_instance_discard_record(record); retvm_if(ret != CALENDAR_ERROR_NONE, CALENDAR_ERROR_DB_FAILED, @@ -2610,8 +2642,11 @@ static int __cal_db_event_update_dirty(calendar_record_h record) cal_rrule_s *rrule = NULL; _cal_db_rrule_get_rrule_from_event(record, &rrule); - _cal_db_rrule_update_record(event->index, rrule); - CAL_FREE(rrule); + if (rrule) + { + _cal_db_rrule_update_record(event->index, rrule); + CAL_FREE(rrule); + } ret = _cal_db_instance_discard_record(record); retvm_if(ret != CALENDAR_ERROR_NONE, CALENDAR_ERROR_DB_FAILED, diff --git a/native/cal_db_rrule.c b/native/cal_db_rrule.c index 39bfe5d..5fe2996 100644 --- a/native/cal_db_rrule.c +++ b/native/cal_db_rrule.c @@ -25,39 +25,51 @@ #include "cal_view.h" #include "cal_time.h" -void _cal_db_rrule_set_default(calendar_record_h event) +void _cal_db_rrule_set_default(calendar_record_h record) { - cal_event_s *_event = NULL; - retm_if(event == NULL, "Invalid argument: rrule is NULL"); + cal_event_s *event = NULL; + retm_if(record == NULL, "Invalid argument: rrule is NULL"); - _event = (cal_event_s *)event; + event = (cal_event_s *)record; - switch (_event->freq) + switch (event->freq) { case CALENDAR_RECURRENCE_NONE: break; case CALENDAR_RECURRENCE_DAILY: break; case CALENDAR_RECURRENCE_WEEKLY: - if (_event->bymonthday || _event->byday) + if (event->bymonthday || event->byday) break; - _event->byday = _cal_time_extract_by(_event->start_tzid, - _event->wkst, &_event->start, CAL_DAY_OF_WEEK); - DBG("No byday so set default[%s]", _event->byday); + event->byday = _cal_time_extract_by(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 || _event->byday) + if (event->bymonthday || event->byday) break; - _event->bymonthday = _cal_time_extract_by(_event->start_tzid, - _event->wkst, &_event->start, CAL_DATE); - DBG("No bymonthday so set default[%s]", _event->bymonthday); + event->bymonthday = _cal_time_extract_by(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 && (event->bymonthday || event->byday)) + break; + else if (event->byyearday || event->byweekno) + break; + + event->bymonth = _cal_time_extract_by(event->start_tzid, event->wkst, + &event->start, CAL_MONTH); + event->bymonthday = _cal_time_extract_by(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; } @@ -69,8 +81,11 @@ void _cal_db_rrule_get_rrule_from_event(calendar_record_h event, cal_rrule_s **r 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"); @@ -213,7 +228,7 @@ void _cal_db_rrule_get_rrule_from_todo(calendar_record_h todo, cal_rrule_s **rru *rrule = _rrule; } -int _cal_db_rrule_insert_record(int id, cal_rrule_s *rrule) +int __cal_db_rrule_insert_record(int id, cal_rrule_s *rrule) { int rrule_id; int index; @@ -567,6 +582,21 @@ static int __cal_db_rrule_update_record(int id, cal_rrule_s *rrule) 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; @@ -589,7 +619,7 @@ int _cal_db_rrule_update_record(int id, cal_rrule_s *rrule) } else { - _cal_db_rrule_insert_record(id, rrule); + __cal_db_rrule_insert_record(id, rrule); } } return CALENDAR_ERROR_NONE; diff --git a/packaging/calendar-service.spec b/packaging/calendar-service.spec index 5d29d62..e21966c 100644 --- a/packaging/calendar-service.spec +++ b/packaging/calendar-service.spec @@ -1,7 +1,7 @@ Name: calendar-service Summary: DB library for calendar Version: 0.1.14 -Release: 84 +Release: 86 Group: System/Libraries License: Apache 2.0 Source0: %{name}-%{version}.tar.gz diff --git a/server/cal_server_reminder.c b/server/cal_server_reminder.c index ec4c54a..6878949 100644 --- a/server/cal_server_reminder.c +++ b/server/cal_server_reminder.c @@ -19,7 +19,6 @@ #include -#include #include #include "calendar2.h" @@ -33,9 +32,8 @@ #define CAL_SUBSCRIBE_MAX_LEN 1024 -static __thread unsigned char *__reminder_changed_info = NULL; -static __thread bundle *__b = NULL; -static __thread int __bundle_len = 0; +static __thread char *__data = NULL; +static __thread int __len_data = 0; static gboolean __cal_server_reminder_publish_changes_with_data(unsigned char *data, int len) { @@ -73,30 +71,68 @@ static gboolean __cal_server_reminder_publish_changes_with_data(unsigned char *d void __cal_server_reminder_clear_changed_info(void) { - if (__reminder_changed_info) + if (__data) { - bundle_free_encoded_rawdata(&__reminder_changed_info); - __reminder_changed_info = NULL; - __bundle_len = 0; + free(__data); + __data = NULL; + __len_data = 0; } } void _cal_server_reminder_publish(void) { - if (__b) + if (__data) { - bundle_encode(__b, &__reminder_changed_info, &__bundle_len); - __cal_server_reminder_publish_changes_with_data(__reminder_changed_info, __bundle_len); + __cal_server_reminder_publish_changes_with_data((unsigned char *)__data, __len_data); __cal_server_reminder_clear_changed_info(); } } -void _cal_server_reminder_add_callback_data(char *key, char *value) +int _cal_server_reminder_add_callback_data(char *key, char *value) { - if (NULL == __b) + int len_data = 0; + int len_key = 0; + int len_value = 0; + + if (NULL == key || NULL == value) { - __b = bundle_create(); + ERR("Invalid parameter"); + return CALENDAR_ERROR_INVALID_PARAMETER; } - bundle_add(__b, key, value); + + len_key = strlen(key); + len_value = strlen(value); + DBG("key[%s]value[%s]", key, value); + if (NULL == __data) + { + __len_data = len_key + len_value + 2; + __data = calloc(__len_data, sizeof(char)); + if (NULL == __data) + { + ERR("calloc() failed"); + return CALENDAR_ERROR_DB_FAILED; + } + snprintf(__data, __len_data, "%s=%s", key, value); + } + else + { + char *p = NULL; + len_data = strlen(__data); + + __len_data = len_data + len_key + len_value + 3; + p = calloc(__len_data, sizeof(char)); + if (NULL == __data) + { + ERR("recalloc() failed"); + return CALENDAR_ERROR_DB_FAILED; + } + snprintf(p, __len_data, "%s&%s=%s", __data, key, value); + free(__data); + __data = p; + + } + + DBG("data[%s]len(%d)", __data, __len_data); + return CALENDAR_ERROR_NONE; } -- 2.7.4