+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.
#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 */
/**
* @}
*/
//#define CALS_DEBUGGING
#ifdef CALS_DEBUGGING
-#define CALS_FN_CALL DBG(">>>>>>>>%s called", __FUNCTION__)
-#define CALS_FN_END DBG("<<<<<<<<%s ended", __FUNCTION__)
-#define CALS_DBG(fmt, arg...) DBG("%d " fmt, __LINE__, ##arg)
+ #if defined(CALS_IPC_SERVER)
+ #define CALS_FN_CALL DBG("SERVER:>>>>>>>>%s called", __FUNCTION__)
+ #define CALS_FN_END DBG("SERVER:<<<<<<<<%s ended", __FUNCTION__)
+ #elif defined(CALS_IPC_CLIENT)
+ #define CALS_FN_CALL DBG("CLIENT:>>>>>>>>%s called", __FUNCTION__)
+ #define CALS_FN_END DBG("CLIENT:<<<<<<<<%s ended", __FUNCTION__)
+ #else
+ #define CALS_FN_CALL DBG(">>>>>>>>%s called", __FUNCTION__)
+ #define CALS_FN_END DBG("<<<<<<<<%s ended", __FUNCTION__)
+ #endif
+
+ #if defined(CALS_IPC_SERVER)
+ #define CALS_DBG(fmt, arg...) DBG("SERVER:%d " fmt, __LINE__, ##arg)
+ #elif defined(CALS_IPC_CLIENT)
+ #define CALS_DBG(fmt, arg...) DBG("CLIENT:%d " fmt, __LINE__, ##arg)
+ #else
+ #define CALS_DBG(fmt, arg...) DBG("%d " fmt, __LINE__, ##arg)
+ #endif
#else /* CALS_DEBUGGING */
#define CALS_FN_CALL
#define CALS_FN_END
Name: libslp-calendar
Summary: DB library for calendar
Version: 0.1.13
-Release: 36
+Release: 41
Group: System/Libraries
License: Apache 2.0
Source0: %{name}-%{version}.tar.gz
CREATE TRIGGER trg_sch_del AFTER DELETE ON schedule_table
BEGIN
DELETE FROM alarm_table WHERE event_id = old.id;
+ DELETE FROM normal_instance_table WHERE event_id = (SELECT rowid FROM schedule_table WHERE original_event_id = old.id);
+ DELETE FROM allday_instance_table WHERE event_id = (SELECT rowid FROM schedule_table WHERE original_event_id = old.id);
+ DELETE FROM schedule_table WHERE original_event_id = old.id;
+ END;
+
+CREATE TRIGGER trig_original_mod AFTER UPDATE OF is_deleted ON schedule_table
+ BEGIN
+ DELETE FROM normal_instance_table WHERE event_id = (SELECT rowid FROM schedule_table WHERE original_event_id = old.id);
+ DELETE FROM allday_instance_table WHERE event_id = (SELECT rowid FROM schedule_table WHERE original_event_id = old.id);
+ UPDATE schedule_table SET is_deleted = 1 WHERE original_event_id = old.id;
END;
CREATE TABLE rrule_table
);
INSERT INTO version_table VALUES(0);
-INSERT INTO calendar_table VALUES(0,0,0,0,'Default event calendar',0,0,'224.167.79.255',0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,-1,0,3);
-INSERT INTO calendar_table VALUES(0,0,0,0,'Default todo calendar',0,0,'224.167.79.255',0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,-1,0,3);
+INSERT INTO calendar_table VALUES(0,0,0,0,'Default event calendar',0,0,'224.167.79.255',0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,-1,0,1);
+INSERT INTO calendar_table VALUES(0,0,0,0,'Default todo calendar',0,0,'41.177.227.255',0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,-1,0,2);
#define PKG_CALENDAR_APP "org.tizen.calendar"
+
int cals_alarm_remove(int type, int related_id)
{
int ret;
#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)
{
return true;
}
-bool cal_db_service_free_full_record(cal_sch_full_t *sch_full_record, int *error_code)
+int cals_db_free_alarm(cal_sch_full_t *record)
{
- retex_if(error_code == NULL, ,"error_code is NULL.");
- retex_if(sch_full_record == NULL, *error_code = CAL_ERR_ARG_INVALID,"sch_full_record is NULL.");
- cal_value *value = NULL;
- GList *head;
-
- CAL_FREE(sch_full_record->summary);
- CAL_FREE(sch_full_record->description);
- CAL_FREE(sch_full_record->location);
- CAL_FREE(sch_full_record->categories);
- CAL_FREE(sch_full_record->uid);
- CAL_FREE(sch_full_record->organizer_name);
- CAL_FREE(sch_full_record->organizer_email);
- CAL_FREE(sch_full_record->gcal_id);
- CAL_FREE(sch_full_record->updated);
- CAL_FREE(sch_full_record->location_summary);
- CAL_FREE(sch_full_record->etag);
- CAL_FREE(sch_full_record->edit_uri);
- CAL_FREE(sch_full_record->gevent_id);
-
- if (sch_full_record->attendee_list)
- {
- head = sch_full_record->attendee_list;
- while (sch_full_record->attendee_list)
- {
- value = sch_full_record->attendee_list->data;
- if(NULL != value)
- {
- if(NULL != value->user_data)
- {
- cal_db_service_free_participant((cal_participant_info_t*)value->user_data,error_code);
- CAL_FREE(value->user_data);
-
- }
- CAL_FREE(value);
- }
- sch_full_record->attendee_list = sch_full_record->attendee_list->next;
+ CALS_FN_CALL;
+ GList *l;
+ cal_value *cv;
+ cal_alarm_info_t *ai;
+
+ if (record == NULL) {
+ ERR("Invalid argument: record is NULL");
+ return -1;
+ }
+
+ if (record->alarm_list == NULL) {
+ DBG("No alarm list to free");
+ return 0;
+ }
+
+ l = record->alarm_list;
+ while (l) {
+ cv = (cal_value *)l->data;
+ if (cv == NULL) {
+ l = g_list_next(l);
+ continue;
+ }
+
+ ai = (cal_alarm_info_t *)cv->user_data;
+ if (ai == NULL) {
+ l = g_list_next(l);
+ continue;
}
- g_list_free(head);
- sch_full_record->attendee_list = NULL;
+
+ CAL_FREE(ai->alarm_tone);
+ CAL_FREE(ai->alarm_description);
+ CAL_FREE(ai);
+
+ CAL_FREE(cv);
+
+ l = g_list_next(l);
}
- return true;
+ g_list_free(record->alarm_list);
+ record->alarm_list = NULL;
-CATCH:
+ return 0;
+}
- return false;
+int cals_db_free_attendee(cal_sch_full_t *record)
+{
+ CALS_FN_CALL;
+ GList *l;
+ cal_value *cv;
+ cal_participant_info_t *pi;
+
+ if (record == NULL) {
+ ERR("Invalid argument: record is NULL");
+ return -1;
+ }
+
+ if (record->attendee_list == NULL) {
+ DBG("No attendee list to free");
+ return 0;
+ }
+
+ l = record->attendee_list;
+ while (l) {
+ cv = (cal_value *)l->data;
+ if (cv == NULL) {
+ l = g_list_next(l);
+ continue;
+ }
+
+ pi = (cal_participant_info_t *)cv->user_data;
+ if (pi == NULL) {
+ l = g_list_next(l);
+ continue;
+ }
+
+ CAL_FREE(pi->attendee_email);
+ CAL_FREE(pi->attendee_number);
+ CAL_FREE(pi->attendee_name);
+ CAL_FREE(pi);
+
+ CAL_FREE(cv);
+
+ l = g_list_next(l);
+ }
+ g_list_free(record->attendee_list);
+ record->attendee_list = NULL;
+
+ return 0;
+}
+
+int cal_db_service_free_full_record(cal_sch_full_t *record)
+{
+ if (record == NULL) {
+ ERR("Invalid argument: record is NULL");
+ return -1;
+ }
+
+ CAL_FREE(record->dtstart_tzid);
+ CAL_FREE(record->dtend_tzid);
+ CAL_FREE(record->summary);
+ CAL_FREE(record->description);
+ CAL_FREE(record->location);
+ CAL_FREE(record->categories);
+ CAL_FREE(record->uid);
+ CAL_FREE(record->organizer_name);
+ CAL_FREE(record->organizer_email);
+ CAL_FREE(record->gcal_id);
+ CAL_FREE(record->updated);
+ CAL_FREE(record->location_summary);
+ CAL_FREE(record->etag);
+ CAL_FREE(record->edit_uri);
+ CAL_FREE(record->gevent_id);
+
+ cals_db_free_alarm(record);
+ cals_db_free_attendee(record);
+
+ return 0;
}
/************************************************************************************************
*
* @return This function returns initialized record.
* @param[in] sch_full_record Points the field information for schedule table' s record.
- * @param[out] error_code Points the error code.
* @exception CAL_ERR_ARG_INVALID.
*/
-bool cal_db_service_free_full_record(cal_sch_full_t *sch_full_record, int *error_code);
+int cal_db_service_free_full_record(cal_sch_full_t *sch_full_record);
/**
#include "cals-schedule.h"
#include "cals-time.h"
-
-int cals_event_init(cal_sch_full_t *sch_full_record)
-{
- retvm_if(NULL == sch_full_record, CAL_ERR_ARG_INVALID , "sch_full_record is NULL");
-
- memset(sch_full_record,0,sizeof(cal_sch_full_t));
-
- sch_full_record->cal_type = CALS_SCH_TYPE_EVENT;
- sch_full_record->meeting_status = CALS_EVENT_STATUS_NONE;
- sch_full_record->calendar_id = DEFAULT_EVENT_CALENDAR_ID;
-
- sch_full_record->index = CALS_INVALID_ID;
- sch_full_record->timezone = -1;
- sch_full_record->contact_id = CALS_INVALID_ID;
- sch_full_record->calendar_type = CAL_PHONE_CALENDAR;
- sch_full_record->attendee_list = NULL;
- sch_full_record->busy_status = 2;
- sch_full_record->summary = NULL;
- sch_full_record->description = NULL;
- sch_full_record->location= NULL;
- sch_full_record->categories = NULL;
- sch_full_record->exdate = NULL;
- sch_full_record->organizer_email = NULL;
- sch_full_record->organizer_name = NULL;
- sch_full_record->uid= NULL;
- sch_full_record->gcal_id = NULL;
- sch_full_record->location_summary = NULL;
- sch_full_record->etag = NULL;
- sch_full_record->edit_uri = NULL;
- sch_full_record->gevent_id = NULL;
- sch_full_record->original_event_id = CALS_INVALID_ID;
-
- sch_full_record->sync_status = CAL_SYNC_STATUS_NEW;
- sch_full_record->account_id = -1;
- sch_full_record->is_deleted = 0;
- sch_full_record->latitude = 1000; // set default 1000 out of range(-180 ~ 180)
- sch_full_record->longitude = 1000; // set default 1000 out of range(-180 ~ 180)
- sch_full_record->freq = CALS_FREQ_ONCE;
-
- return CAL_SUCCESS;
-}
-
static inline void cals_event_make_condition(int calendar_id,
time_t start_time, time_t end_time, int all_day, char *dest, int dest_size)
{
}
snprintf(query, sizeof(query),
- "SELECT id, changed_ver, created_ver, is_deleted FROM %s "
+ "SELECT id, changed_ver, created_ver, is_deleted, calendar_id FROM %s "
"WHERE changed_ver > %d AND original_event_id = %d AND type = %d %s "
"UNION "
- "SELECT schedule_id, deleted_ver, -1, 1 FROM %s "
+ "SELECT schedule_id, deleted_ver, -1, 1, calendar_id FROM %s "
"WHERE deleted_ver > %d AND schedule_type = %d %s ",
CALS_TABLE_SCHEDULE,
version, CALS_INVALID_ID, CALS_SCH_TYPE_EVENT, buf,
} else {
result->type = CALS_UPDATED_TYPE_MODIFIED;
}
+ result->calendar_id = sqlite3_column_int(stmt, 4);
if (iter->info->head == NULL) {
iter->info->head = result;
} else {
DBG("append exdate");
len = strlen(exdate);
- p = calloc(len + strlen(", ") + len_datetime + 1, sizeof(char));
+ p = calloc(len + strlen(",") + len_datetime + 1, sizeof(char));
if (p == NULL) {
ERR("Failed to calloc");
sqlite3_finalize(stmt);
return CAL_ERR_OUT_OF_MEMORY;
}
str_datetime = cals_time_get_str_datetime(NULL, dtstart_utime);
- snprintf(p, len + 2 + len_datetime + 1, "%s, %s",
+ snprintf(p, len + strlen(",") + len_datetime + 1, "%s,%s",
exdate, str_datetime);
}
if (str_datetime) free(str_datetime);
} else {
DBG("append exdate");
len = strlen(exdate);
- p = calloc(len + strlen(", ") + len_datetime + 1, sizeof(char));
+ p = calloc(len + strlen(",") + len_datetime + 1, sizeof(char));
if (p == NULL) {
ERR("Failed to calloc");
sqlite3_finalize(stmt);
return CAL_ERR_OUT_OF_MEMORY;
}
- snprintf(p, len + 2 + len_datetime + 1, "%s, %s",
+ snprintf(p, len + strlen(",") + len_datetime + 1, "%s,%s",
exdate, buf);
}
sqlite3_finalize(stmt);
int cals_func_transp(int ver, cal_sch_full_t *sch, void *data);
int cals_func_url(int ver, cal_sch_full_t *sch, void *data);
int cals_func_recurid(int ver, cal_sch_full_t *sch, void *data);
-int cals_func_rrule(int ver, cal_sch_full_t *sch, void *data);
+int cals_func_rrule1(int ver, cal_sch_full_t *sch, void *data);
int cals_func_dtend(int ver, cal_sch_full_t *sch, void *data);
int cals_func_duration(int ver, cal_sch_full_t *sch, void *data);
int cals_func_attach(int ver, cal_sch_full_t *sch, void *data);
+
+
+enum {
+ ATTENDEE_CUTYPE = 0x0,
+ ATTENDEE_MEMBER,
+ ATTENDEE_ROLE,
+ ATTENDEE_PARTSTAT,
+ ATTENDEE_RSVP,
+ ATTENDEE_DELTO,
+ ATTENDEE_DELFROM,
+ ATTENDEE_SENTBY,
+ ATTENDEE_CN,
+ ATTENDEE_DIR,
+ ATTENDEE_MAX,
+};
+
+int cals_func_attendee_cutype(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_member(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_role(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_partstat(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_rsvp(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_delto(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_delfrom(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_sentby(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_cn(cal_sch_full_t *sch, void *data);
+int cals_func_attendee_dir(cal_sch_full_t *sch, void *data);
+
+struct _vala_func _attendee_list[ATTENDEE_MAX] =
+{
+ { "CUTYPE=", cals_func_attendee_cutype },
+ { "MEMBER=", cals_func_attendee_member },
+ { "ROLE=", cals_func_attendee_role },
+ { "PARTSTAT=", cals_func_attendee_partstat },
+ { "RSVP=", cals_func_attendee_rsvp },
+ { "DELTO=", cals_func_attendee_delto },
+ { "DELFROM=", cals_func_attendee_delfrom },
+ { "SENTBY=", cals_func_attendee_sentby },
+ { "CN=", cals_func_attendee_cn },
+ { "DIR=", cals_func_attendee_dir }
+};
+
int cals_func_attendee(int ver, cal_sch_full_t *sch, void *data);
int cals_func_categories(int ver, cal_sch_full_t *sch, void *data);
int cals_func_comment(int ver, cal_sch_full_t *sch, void *data);
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);
VEVE_DTEND,
// VEVE_DURATION,
// VEVE_ATTACH,
-// VEVE_ATTENDEE,
+ VEVE_ATTENDEE,
VEVE_CATEGORIES,
// VEVE_COMMENT,
// VEVE_CONTACT,
// VEVE_RELATED,
// VEVE_RESOURCES,
// VEVE_RDATE,
+ VEVE_AALARM, /* for ver 1.0 */
VEVE_MAX,
};
// { "TRANSP", cals_func_transp },
// { "URL", cals_func_url },
// { "RECURID", cals_func_recurid },
- { "RRULE", cals_func_rrule },
+ { "RRULE", cals_func_rrule1 },
{ "DTEND", cals_func_dtend },
// { "DURATION", cals_func_duration },
// { "ATTACH", cals_func_attach },
-// { "ATTENDEE", cals_func_attendee },
- { "CATEGORIES", cals_func_categories }//,
+ { "ATTENDEE", cals_func_attendee },
+ { "CATEGORIES", cals_func_categories },
// { "COMMENT", cals_func_comment },
// { "CONTACT", cals_func_contact },
// { "EXDATE", cals_func_exdate },
// { "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);
{ "WKST=", cals_func_wkst }
};
-int cals_func_related_trig(cal_sch_full_t *sch, void *data);
-int cals_func_value(cal_sch_full_t *sch, void *data);
+int cals_func_trig_related(cal_sch_full_t *sch, void *data);
+int cals_func_trig_value(cal_sch_full_t *sch, void *data);
enum {
TRIG_RELATED = 0x0,
struct _vala_func _trig_list[TRIG_MAX] =
{
- { "RELATED=", cals_func_related_trig },
- { "VALUE=", cals_func_value }
+ { "RELATED=", cals_func_trig_related },
+ { "VALUE=", cals_func_trig_value }
};
int cals_func_charset(int *val, void *data);
int cals_quoted_printable_decode(char *p, int *len)
{
+ CALS_FN_CALL;
int i = 0, j = 0;
char ch;
*schedules = l;
return ret;
}
-
+#ifndef CALS_IPC_CLIENT
int cals_do_importing(int calendar_id, char *stream, void *data)
{
int ret;
return ret;
}
-
+#endif
static const char* cals_get_stream_from_path(const char *path)
{
FILE *file;
}
return 0;
}
-
+#ifndef CALS_IPC_CLIENT
int cals_import_schedules(const char *path, int calendar_id)
{
FILE *file;
ret = cals_import_schedules(path, calendar_id);
return ret;
}
-
+#endif
// func ////////////////////////////////////////////////////////
p++;
sch->dtstart_tzid = strdup(buf);
} else {
- sch->dtstart_tzid = strdup("Europe/London");
+ sch->dtstart_tzid = strdup(CALS_TZID_0);
}
if (!strncmp(p, "VALUE=", strlen("VALUE="))) {
return 0;
}
-int cals_func_description(int ver, cal_sch_full_t *sch, void *data)
+int _work_description_property(cal_sch_full_t *sch, char *buf)
{
- char *p = (char *)data;
- int encoding = 0;
+ int i;
+ int ret = 0;
- while (*p != '\n' && *p != '\r' && *p != '\0') {
- if ( *p == ':') {
- p++;
- if (encoding == ENCODE_BASE64) {
- gsize len;
- sch->description = strdup((char *)g_base64_decode(p, &len));
+ for (i = 0; i < TEXT_MAX; i++) {
+ if (!strncmp(buf, _optional_list[i].prop, strlen(_optional_list[i].prop))) {
+ _optional_list[i].func(&ret, buf);
+ break;
+ }
+ }
+ return ret;
+}
- } else if (encoding == ENCODE_QUOTED_PRINTABLE) {
- if (ver == 1) {
- int len;
- cals_quoted_printable_decode(p, &len);
- sch->description = strdup(p);
- } else {
- CALS_DBG("only ver1.0 supports quoted printable\n");
- sch->summary = strdup(p);
- }
+int _work_description_switch(int me, int mode, char *buf, int *charset, int *encoding)
+{
+ CALS_FN_CALL;
+ switch (mode) {
+ case 1:
+ case 2:
+ if (!strncmp(buf, "CHARSET=UTF-8", strlen("CHARSET=UTF-8"))) {
+ DBG("CHARSET=UTF-8");
+ *charset = 1;
+
+ } else if (!strncmp(buf, "CHARSET=UTF-16",
+ strlen("CHARSET=UTF-16"))) {
+ DBG("CHARSET=UTF-16");
+ *charset = 1;
+
+ } else if (!strncmp(buf, "ENCODING=BASE64",
+ strlen("ENCODING=BASE64"))) {
+ DBG("ENCODE_BASE64");
+ *encoding = ENCODE_BASE64;
+
+ } else if (!strncmp(buf, "ENCODING=QUOTED-PRINTABLE",
+ strlen("ENCODING=QUOTED-PRINTABLE"))) {
+ DBG("ENCODE_QUOTED_PRINTABLE");
+ *encoding = ENCODE_QUOTED_PRINTABLE;
- } else {
- sch->description = strdup(p);
+ } else {
- }
+ }
+ mode = 0;
+ break;
+ default:
+ mode = me;
+ break;
+ }
+ return mode;
+}
- } else if (*p == ';') {
- p++;
- cals_get_optional_parameter(p, &encoding);
+int cals_func_description(int ver, cal_sch_full_t *sch, void *data)
+{
+ CALS_FN_CALL;
+ int i, j;
+ int len;
+ int out;
+ int mode;
+ int charset, encoding;
+ char buf[64] = {0};
+ char *p = (char *)data;
- } else {
- p++;
+ i = j = 0;
+ out = 0;
+ mode = 0;
+ charset = encoding = 0;
+ while (p[i] != '\0') {
+ switch (p[i]) {
+ case ':':
+ mode = 1;
+ out = 1;
+ break;
+
+ case ';':
+ buf[j] = '\0';
+ mode = _work_description_switch(2, mode, buf, &charset, &encoding);
+ j = 0;
+ break;
+
+ default:
+ buf[j] = p[i];
+ j++;
+ break;
}
+ i++;
+
+ if (out) {
+ DBG("out");
+ break;
+ }
+ }
+ _work_description_switch(0, mode, buf, &charset, &encoding);
+
+ DBG("charset(%d) encoding(%d)", charset, encoding);
+ if (encoding) {
+ cals_quoted_printable_decode(p+i, &len);
}
+ sch->description = strdup(p+i);
+
return 0;
}
int cals_func_summary(int ver, cal_sch_full_t *sch, void *data)
{
+ CALS_FN_CALL;
+ int i, j;
+ int len;
+ int out;
+ int mode;
+ int charset, encoding;
+ char buf[64] = {0};
char *p = (char *)data;
- int encoding = 0;
- while (*p != '\n' && *p != '\r' && *p != '\0') {
- if ( *p == ':') {
- p++;
- if (encoding == ENCODE_BASE64) {
- gsize len;
- sch->summary = strdup((char *)g_base64_decode(p, &len));
-
- } else if (encoding == ENCODE_QUOTED_PRINTABLE) {
- if (ver == 1) {
- int len;
- cals_quoted_printable_decode(p, &len);
- sch->summary = strdup(p);
- } else {
- CALS_DBG("only ver1.0 supports quoted printable\n");
- sch->summary = strdup(p);
- }
+ i = j = 0;
+ out = 0;
+ mode = 0;
+ charset = encoding = 0;
+ while (p[i] != '\0') {
+ switch (p[i]) {
+ case ':':
+ mode = 1;
+ out = 1;
+ break;
- } else {
- sch->summary = strdup(p);
- }
+ case ';':
+ buf[j] = '\0';
+ mode = _work_description_switch(2, mode, buf, &charset, &encoding);
+ j = 0;
break;
- } else if (*p == ';') {
- p++;
- cals_get_optional_parameter(p, &encoding);
+ default:
+ buf[j] = p[i];
+ j++;
+ break;
+ }
+ i++;
- } else {
- p++;
+ if (out) {
+ break;
}
}
+ _work_description_switch(0, mode, buf, &charset, &encoding);
+
+ DBG("charset(%d) encoding(%d)", charset, encoding);
+ if (encoding) {
+ cals_quoted_printable_decode(p+i, &len);
+ }
+ sch->summary = strdup(p+i);
+
DBG("ver(%d)summary(%s)\n", ver, sch->summary);
return 0;
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;
break;
case 2:
+ DBG("version 1");
/* Suppose vcalendar 1.0, if p == data */
if ((p - 1) == (char *)data) {
cals_ver1_func_rrule(sch, 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;
p++;
sch->dtend_tzid = strdup(buf);
} else {
- sch->dtend_tzid = strdup("Europe/London");
+ sch->dtend_tzid = strdup(CALS_TZID_0);
}
if (!strncmp(p, "VALUE=", strlen("VALUE="))) {
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;
return 0;
}
+
int cals_func_comment(int ver, cal_sch_full_t *sch, void *data)
{
return 0;
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,
/* 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 cals_func_trigger(cal_sch_full_t *sch, void *data)
{
int i = 0, out = 0;
+
char *p = (char *)data;
long long int dtstart_utime;
- int dur_t;
cal_value *val;
cal_alarm_info_t *alarm;
GList *l;
if (out == 1) {
break;
}
- p = cals_convert_sec_from_duration(p, &dur_t, NULL);
- alarm->alarm_time = dtstart_utime + (long long int)dur_t;
+ cals_func_trig_related(sch, p);
break;
}
return 0;
return 0;
}
-int cals_func_related_trig(cal_sch_full_t *sch, void *data)
+int _get_tick_unit(char *p, int *tick, int *unit)
+{
+ int d, c, i; /* direct, const, i */
+ int t, u; /* tick, unit */
+ char buf[8] = {0};
+
+ t = 0;
+ c = 0;
+ u = CAL_SCH_TIME_UNIT_OFF;
+ while (*p != '\0' && *p != '\n') {
+ switch (*p) {
+ case '+':
+ d = 1;
+ break;
+ case '-':
+ d = -1;
+ break;
+ case 'P':
+ i = 0;
+ break;
+ case 'T':
+ break;
+ case 'W':
+ c = atoi(buf);
+ DBG("W tick(%d)", c);
+ if (c == 0) break;
+ u = CAL_SCH_TIME_UNIT_WEEK;
+ t += c;
+ i = 0;
+ break;
+ case 'D':
+ c = atoi(buf);
+ DBG("D tick(%d)", c);
+ if (c == 0) break;
+ u = CAL_SCH_TIME_UNIT_DAY;
+ t += c;
+ i = 0;
+ break;
+ case 'H':
+ c = atoi(buf);
+ DBG("H tick(%d)", c);
+ if (c == 0) break;
+ u = CAL_SCH_TIME_UNIT_HOUR;
+ t += c;
+ i = 0;
+ break;
+ case 'M':
+ c = atoi(buf);
+ DBG("M tick(%d)", c);
+ if (c == 0) break;
+ u = CAL_SCH_TIME_UNIT_MIN;
+ t += c;
+ i = 0;
+ break;
+ case 'S':
+ i = 0;
+ break;
+ default:
+ buf[i] = *p;
+ i++;
+ break;
+ }
+ p++;
+ }
+ if (t != c) {
+ u = CAL_SCH_TIME_UNIT_SPECIFIC;
+ }
+ *tick = t;
+ *unit = u;
+ DBG("get tic(%d) unit(%d)", t, u);
+
+ return 0;
+}
+
+int cals_func_trig_related(cal_sch_full_t *sch, void *data)
{
CALS_DBG("%s\n", (char *)data);
+
+ int tick, unit;
+ char *p = (char *)data;
+ GList *l;
+ cal_value *cv;
+ cal_alarm_info_t *al = NULL;
+
+ if (p == NULL) {
+ return -1;
+ }
+
+ l = g_list_last(sch->alarm_list);
+ if (l == NULL) {
+ DBG("Faield to get list from alarm list");
+ return 0;
+ }
+
+ cv = (cal_value *)l->data;
+ if (cv == NULL) {
+ ERR("Failed to get cal value");
+ return -1;
+ }
+ al = (cal_alarm_info_t *)cv->user_data;
+ if (al == NULL) {
+ ERR("Failed to get alarm info");
+ return -1;
+ }
+
+ if (!strncmp(p, "START", strlen("START") + 1)) {
+ p += strlen("START") + 1;
+ DBG("related start and value[%s]", p);
+ _get_tick_unit(p, &tick, &unit);
+ al->remind_tick = tick;
+ al->remind_tick_unit = unit;
+
+ } else if (!strncmp(p, "END", strlen("END") +1)) {
+ p += strlen("END") + 1;
+ DBG("related end and value[%s]", p);
+ _get_tick_unit(p, &tick, &unit);
+ al->remind_tick = tick;
+ al->remind_tick_unit = unit;
+
+ } else {
+ DBG("no related and value[%s]", p);
+ _get_tick_unit(p, &tick, &unit);
+ al->remind_tick = tick;
+ al->remind_tick_unit = unit;
+
+ }
+
return 0;
}
-int cals_func_value(cal_sch_full_t *sch, void *data)
+long long int _get_utime_from_datetime(char *tzid, char *p)
+{
+ int y, mon, d, h, min, s;
+ int len;
+ char t, z;
+ if (p == NULL) {
+ return -1;
+ }
+ len = strlen(p);
+ if (len < strlen("YYYYMMDDTHHMMSS")) {
+ return -1;
+ }
+
+ sscanf(p, "%04d%02d%02d%c%02d%02d%02d%c",
+ &y, &mon, &d, &t, &h, &min, &s, &z);
+
+ return cals_time_date_to_utime(tzid, y, mon, d, h, min, s);
+}
+
+int cals_func_trig_value(cal_sch_full_t *sch, void *data)
{
CALS_DBG("%s\n", (char *)data);
+
+ char *p = (char *)data;
+ GList *l;
+ cal_value *cv;
+ cal_alarm_info_t *al = NULL;
+
+ l = g_list_last(sch->alarm_list);
+ if (l == NULL) {
+ DBG("No alarm");
+ return 0;
+ }
+
+ cv = (cal_value *)l->data;
+ al = (cal_alarm_info_t *)cv->user_data;
+
+ if (!strncmp(p, "DATE-TIME", strlen("DATE-TIME") + 1)) {
+ p += strlen("DATE-TIME") + 1;
+ al->remind_tick_unit = CAL_SCH_TIME_UNIT_SPECIFIC;
+ al->alarm_time = _get_utime_from_datetime(sch->dtstart_tzid, p);
+ } else {
+
+ }
+
return 0;
}
*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 CAL_SUCCESS;
}
-
+#ifndef CALS_IPC_CLIENT
API int calendar_svc_calendar_export(int calendar_id, const char *path)
{
int fd, r;
return CAL_SUCCESS;
}
+#endif
[CALS_DECEMBER] = UCAL_DECEMBER,
};
-static struct day days[] = {
+static struct day wdays[] = {
[CALS_SUNDAY] = {UCAL_SUNDAY, "SU"},
[CALS_MONDAY] = {UCAL_MONDAY, "MO"},
[CALS_TUESDAY] = {UCAL_TUESDAY, "TU"},
}
if (wkst >= CALS_SUNDAY && wkst <= CALS_SATURDAY)
- ucal_setAttribute(cal, UCAL_FIRST_DAY_OF_WEEK, days[wkst].uday);
+ ucal_setAttribute(cal, UCAL_FIRST_DAY_OF_WEEK, wdays[wkst].uday);
return cal;
}
ucal_set(cal, UCAL_MONTH, months[month]);
}
-static inline void _ucal_set_day(UCalendar *cal, int day)
-{
- int woy; /* week of year */
- int date, date_new; /* date */
- UErrorCode status = U_ZERO_ERROR;
- if (day == CALS_NODAY)
+static inline void _ucal_set_wday(UCalendar *cal, int wday)
+{
+ if (wday == CALS_NODAY) {
+ DBG("this is wday repeat, so pass this shift");
return;
- woy = ucal_get(cal, UCAL_WEEK_OF_YEAR, &status);
- date = ucal_get(cal, UCAL_DATE, &status);
- ucal_set(cal, UCAL_DAY_OF_WEEK, days[day].uday);
- ucal_set(cal, UCAL_WEEK_OF_YEAR, woy);
- date_new = ucal_get(cal, UCAL_DATE, &status);
- DBG("date old(%d) new(%d)", date, date_new);
- if (date_new < date) {
- ucal_add(cal, UCAL_DATE, 7, &status);
}
+ ucal_set(cal, UCAL_DAY_OF_WEEK, wdays[wday].uday);
}
-static inline void _ucal_set_week(UCalendar *cal, int week)
+static inline void _ucal_set_week(UCalendar *cal, int week, cal_sch_full_t *sch)
{
if (!week)
return;
- ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, week);
+
+ switch (inst_info[sch->freq].f) {
+ case UCAL_WEEK_OF_YEAR:
+ return;
+ default:
+ ucal_set(cal, UCAL_DAY_OF_WEEK_IN_MONTH, week);
+ break;
+ }
}
static void _ucal_get_instance(UCalendar *cal,
DBG("%d %d %d /%d %d %d", t1->year, t1->month, t1->mday,
t2->year, t2->month, t2->mday);
if (t1->year > t2->year) {
+ DBG("exit year");
return 1;
- } else if (t1->month > t2->month) {
- return 1;
- } else if (t1->mday > t2->mday) {
- return 1;
- } else {
+ } else if (t1->year < t2->year) {
return 0;
+ } else {
+ if (t1->month > t2->month) {
+ return 1;
+ } else if (t1->month < t2->month) {
+ return 0;
+ } else {
+ if (t1->mday > t2->mday) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
}
}
return 0;
}
+int _shift_to_valid_mday(UCalendar *cal, int mday, int wday, cal_sch_full_t *sch)
+{
+ CALS_FN_CALL;
+ int y, m, d, month;
+ UErrorCode status = U_ZERO_ERROR;
+
+ if (wday != CALS_NODAY) {
+ DBG("this is wday repeat, so pass this shift");
+ return 0;
+ }
+
+ DBG("mday(%d)wday%d)", mday, wday);
+ switch (inst_info[sch->freq].f) {
+ case UCAL_YEAR:
+ month = ucal_get(cal, UCAL_MONTH, &status);
+ d = ucal_get(cal, UCAL_DATE, &status);
+ while (d != mday && y < 9999 ) {
+ ucal_add(cal, inst_info[sch->freq].f, sch->interval, &status);
+ ucal_set(cal, UCAL_MONTH, month);
+ ucal_set(cal, UCAL_DATE, mday);
+ y = ucal_get(cal, UCAL_YEAR, &status);
+ m = ucal_get(cal, UCAL_MONTH, &status);
+ d = ucal_get(cal, UCAL_DATE, &status);
+ }
+ break;
+
+ case UCAL_MONTH:
+ d = ucal_get(cal, UCAL_DATE, &status);
+ while (d != mday && y < 9999 ) {
+ ucal_set(cal, UCAL_DATE, mday);
+ y = ucal_get(cal, UCAL_YEAR, &status);
+ m = ucal_get(cal, UCAL_MONTH, &status);
+ d = ucal_get(cal, UCAL_DATE, &status);
+ }
+ break;
+ default:
+ break;
+ }
+ DBG("shift to %04d/%02d/%02d and should be same %02d date", y, m, d, mday);
+ return 0;
+}
+
+int _shift_to_valid_wday(UCalendar *cal, int year, int month, int mday, int wday, int week, cal_sch_full_t *sch)
+{
+ CALS_FN_CALL;
+ int y, m, d; /* date */
+ UErrorCode status = U_ZERO_ERROR;
+
+ if (!week)
+ return 0;
+
+ y = ucal_get(cal, UCAL_YEAR, &status);
+ m = ucal_get(cal, UCAL_MONTH, &status) + 1;
+ d = ucal_get(cal, UCAL_DATE, &status);
+ DBG(" got next mday(%d) origin mday(%d)", d, mday);
+
+ switch (inst_info[sch->freq].f) {
+ case UCAL_YEAR:
+ if (y <= year && m <= month && d < mday) {
+ DBG("less than start date");
+ ucal_add(cal, UCAL_YEAR, 1, &status);
+ } else if (m < month) {
+ DBG("mismatched month");
+ ucal_add(cal, UCAL_MONTH, 1, &status);
+ }
+ _ucal_set_wday(cal, wday);
+ _ucal_set_week(cal, week, sch);
+ break;
+
+ case UCAL_MONTH:
+ if ((m <= month && d < mday) || (m < month)) {
+ DBG(" so, added 1 week");
+ ucal_add(cal, UCAL_MONTH, 1, &status);
+ _ucal_set_mday(cal, 15);
+ _ucal_set_wday(cal, wday);
+ _ucal_set_week(cal, week, sch);
+ }
+ break;
+
+ case UCAL_WEEK_OF_YEAR:
+ if (y <= year && m <= month && d < mday) {
+// while ((m <= month && d < mday) || (m < month)) {
+// ucal_add(cal, UCAL_WEEK_OF_YEAR, 1, &status);
+ ucal_add(cal, inst_info[sch->freq].f, sch->interval, &status);
+ m = ucal_get(cal, UCAL_MONTH, &status) + 1;
+ d = ucal_get(cal, UCAL_DATE, &status);
+// }
+ }
+ break;
+ default:
+ break;
+ }
+
+ _print_cal(cal);
+ return 0;
+}
+
+
static int _insert_instance(UCalendar *cal, int event_id,
- struct cals_time *st, int dr, int day, int week, cal_sch_full_t *sch)
+ struct cals_time *st, int dr, int wday, int week, cal_sch_full_t *sch)
{
+ CALS_FN_CALL;
int r;
int i;
int cnt;
int e_year;
int e_month;
int e_mday;
+ int year;
+ int month;
+ int mday;
UCalendar *e_cal;
UErrorCode status = U_ZERO_ERROR;
memset(&until, 0, sizeof(struct cals_time));
memset(&in, 0, sizeof(struct cals_time));
+ year = ucal_get(cal, UCAL_YEAR, &status);
+ month = ucal_get(cal, UCAL_MONTH, &status) + 1;
+ mday = ucal_get(cal, UCAL_DATE, &status);
cnt = _get_max_count(sch);
_set_until(&until, sch);
for (i = 0; i < cnt; i++) {
- _ucal_set_day(cal, day);
- _ucal_set_week(cal, week);
+ if (wday != CALS_NODAY) {
+ DBG("set 15th for wday");
+ switch (inst_info[sch->freq].f) {
+ case UCAL_YEAR:
+ case UCAL_MONTH:
+ _ucal_set_mday(cal, 15);
+ break;
+ default:
+ break;
+ }
+ }
+ _ucal_set_wday(cal, wday);
+ _ucal_set_week(cal, week, sch);
+ _shift_to_valid_wday(cal, year, month, mday, wday, week, sch);
_ucal_get_instance(cal, st, &in);
if (sch->freq != CALS_FREQ_ONCE && _is_after(&in, &until)) {
}
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;
}
return month;
}
-static inline int _get_mday(const char *str)
+static inline int _get_mday(const char *str, int *mday)
{
- int mday;
+ int d;
if (!str || !*str)
return -1;
- mday = atoi(str);
- if (mday < 1 || mday > 31)
+ d = atoi(str);
+ if (d < 1 || d > 31)
return -1;
- return mday;
+ *mday = d;
+ return 0;
+}
+
+int _adjust_valid_first_mday(UCalendar *cal, int year, int month, int mday, cal_sch_full_t *sch)
+{
+ CALS_FN_CALL;
+ int caly, calm, cald;
+ UErrorCode status = U_ZERO_ERROR;
+
+ caly = ucal_get(cal, UCAL_YEAR, &status);
+ calm = ucal_get(cal, UCAL_MONTH, &status) + 1;
+ cald = ucal_get(cal, UCAL_DATE, &status);
+
+ if (caly <= year && calm <= month, cald< mday) {
+ switch (inst_info[sch->freq].f) {
+ case UCAL_YEAR:
+ ucal_add(cal, UCAL_YEAR, 1, &status);
+ break;
+ case UCAL_MONTH:
+ ucal_add(cal, UCAL_MONTH, 1, &status);
+ break;
+ case UCAL_WEEK_OF_YEAR:
+ ucal_add(cal, UCAL_DATE, 7, &status);
+ break;
+ default:
+ break;
+ }
+ }
+ return 0;
+}
+
+int _set_valid_first_mday(UCalendar *cal, struct cals_time *st, cal_sch_full_t *sch)
+{
+ return 0;
}
static int insert_bymday(int event_id,
UCalendar *cal;
int r;
int i;
+ int y, m, d;
int mday;
char **t;
- const char *d = ",";
+ const char *dl = ",";
+ UErrorCode status = U_ZERO_ERROR;
- t = g_strsplit(sch->bymonthday, d, -1);
+ t = g_strsplit(sch->bymonthday, dl, -1);
if (!t) {
ERR("g_strsplit failed");
}
for (i = 0; t[i]; ++i) {
- mday = _get_mday(t[i]);
- if (mday < 0) {
+ r = _get_mday(t[i], &mday);
+ if (r < 0) {
+ ERR("Failed to get mday");
g_strfreev(t);
return CAL_ERR_ARG_INVALID;
}
if (!cal)
return CAL_ERR_FAIL;
_ucal_set_time(cal, st);
+ y = ucal_get(cal, UCAL_YEAR, &status);
+ m = ucal_get(cal, UCAL_MONTH, &status) + 1;
+ d = ucal_get(cal, UCAL_DATE, &status);
_ucal_set_month(cal, month);
_ucal_set_mday(cal, mday);
+ _adjust_valid_first_mday(cal, y, m, d, sch);
- r = _insert_instance(cal, event_id, st, dr, CALS_NODAY, 0, sch);
+ r = _insert_instance(cal, event_id, st, dr, CALS_NODAY, 0, sch);
if (r) {
ERR("_insert_bymday failed (%d)", r);
g_strfreev(t);
return _insert_instance(cal, event_id, st, dr, CALS_NODAY, 0, sch);
}
-static inline int _get_day(const char *str, int *week, int *day)
+static inline int _get_wday(const char *str, int *week, int *wday)
{
int i;
int d;
return -1;
if (!sscanf(str, "%d", &d)) {
- DBG("no week digit");
+ DBG("no digit in front of char, so set 1 as default");
if (sscanf(str, "%s", buf) != 1) {
- ERR("Failed to get day[%s]", str);
+ ERR("Failed to get wday[%s]", str);
return -1;
}
- d = 0;
+ d = 1;
} else {
if (sscanf(str, "%d%s", &d, buf) != 2) {
- ERR("Failed to get day[%s]", str);
+ ERR("Failed to get wday[%s]", str);
return -1;
}
}
- *week = d;
+ *week = d > 4 ? -1 : d;
buf[2] = '\0';
- DBG("[%s] and sets week (%d)", buf, d);
+ DBG("Sets week(%d) wday[%s]", d, buf);
- for (i = 0; i < sizeof(days)/sizeof(struct day); i++) {
- if (!strncmp(days[i].str, buf, 2)) {
- DBG("inserted wday[%s]and set[%s]", days[i].str, buf);
- *day = i;
+ for (i = 0; i < sizeof(wdays)/sizeof(struct day); i++) {
+ if (!strncmp(wdays[i].str, buf, 2)) {
+ DBG("inserted week(%d) wday[%s]", *week, wdays[i].str);
+ *wday = i;
break;
}
}
-
return 0;
}
static int insert_byday(int event_id,
struct cals_time *st, int dr, int month, cal_sch_full_t *sch)
{
+ CALS_FN_CALL;
UCalendar *cal;
int r;
int i;
- int day;
+ int wday;
int week;
char **t;
const char *d = ",";
return CAL_ERR_OUT_OF_MEMORY;
}
- day = 0;
+ wday = 0;
week = 0;
for (i = 0; t[i]; ++i) {
- r = _get_day(t[i], &week, &day);
+ r = _get_wday(t[i], &week, &wday);
if (r < 0) {
+ ERR("Failed to get wday");
g_strfreev(t);
- ERR("_get_day failed");
return CAL_ERR_ARG_INVALID;
}
_ucal_set_time(cal, st);
_ucal_set_month(cal, month);
- r = _insert_instance(cal, event_id, st, dr, day, week, sch);
+ r = _insert_instance(cal, event_id, st, dr, wday, week, sch);
if (r) {
ERR("_insert_bymday failed (%d)", r);
g_strfreev(t);
#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
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--;
cal_sch_full_t *sch_record = NULL;
sch_record = (*record)->user_data;
+ /*
+ * is_deleted = 0 is not included in query.
+ * instead, developer should check after getting data.
+ */
if (field_list) {
cals_rearrange_schedule_field(field_list, rearranged, sizeof(rearranged));
snprintf(sql_value, sizeof(sql_value),
- "SELECT %s FROM %s WHERE id = %d AND is_deleted = 0 ",
+ "SELECT %s FROM %s WHERE id = %d ",
CALS_TABLE_SCHEDULE, rearranged, index);
} else {
snprintf(sql_value, sizeof(sql_value),
- "SELECT * FROM %s WHERE id = %d AND is_deleted = 0 ",
+ "SELECT * FROM %s WHERE id = %d ",
CALS_TABLE_SCHEDULE, index);
}
retex_if(NULL == stmt,,"cals_query_prepare() Failed");
rc = cals_stmt_step(stmt);
- if (rc != CAL_TRUE) {
+ if (rc == CAL_SUCCESS) {
+ DBG("stmt done is called. No data(%d)", rc);
+ sqlite3_finalize(stmt);
+ if (malloc_inside && *record != NULL) {
+ calendar_svc_struct_free(record);
+ }
+ return CAL_ERR_NO_DATA;
+
+ } else if (rc != CAL_TRUE) {
ERR("Failed to step stmt(%d)", rc);
sqlite3_finalize(stmt);
if (malloc_inside && *record != NULL) {
sch_record->index = index;
- if (0 == strcmp(data_type,CAL_STRUCT_SCHEDULE)) {
- cal_db_service_get_participant_info_by_index(index,&(sch_record->attendee_list),&error_code);
- cals_get_alarm_info(index, &(sch_record->alarm_list));
- }
+ cal_db_service_get_participant_info_by_index(index,
+ &(sch_record->attendee_list),&error_code);
+ cals_get_alarm_info(index, &(sch_record->alarm_list));
}
else if(0 == strcmp(data_type,CAL_STRUCT_CALENDAR))
{
result->type = cursor->type;
result->id = cursor->id;
result->ver = cursor->ver;
+ result->calendar_id = cursor->calendar_id;
return;
}
if (sch_record->attendee_list)
{
+ DBG("attendee exists");
GList *list = g_list_first(sch_record->attendee_list);
cal_participant_info_t *participant_info = NULL;
}
list = g_list_next(list);
}
+ } else {
+ DBG("No attendee exists");
}
if (sch_record->alarm_list)
{
+ DBG("alarm exists");
GList *list = sch_record->alarm_list;
cal_alarm_info_t *alarm_info = NULL;
while (list)
{
cvalue = list->data;
- if (cvalue)
+ if (cvalue == NULL) {
+ ERR("Failed to fine value");
+ break;
+ }
+
+ alarm_info = cvalue->user_data;
+ if (alarm_info == NULL) {
+ ERR("Failed to find alarm info");
+ break;
+ }
+
+ if(alarm_info->is_deleted == 0)
{
- alarm_info = cvalue->user_data;
- if(alarm_info->is_deleted == 0)
+ DBG("type(%d) tick(%d) unit(%d)",
+ sch_record->cal_type,
+ alarm_info->remind_tick,
+ alarm_info->remind_tick_unit);
+ if (alarm_info->remind_tick != CALS_INVALID_ID)
{
- if (alarm_info->remind_tick != CALS_INVALID_ID)
- {
+ switch (sch_record->cal_type) {
+ case CALS_SCH_TYPE_EVENT:
ret = cals_alarm_add(index, alarm_info, &st);
warn_if(CAL_SUCCESS != ret, "cals_alarm_add() Failed(%d)", ret);
+ break;
+ case CALS_SCH_TYPE_TODO:
+ if (sch_record->dtend_utime == CALS_TODO_NO_DUE_DATE) {
+ DBG("no due date is set");
+ break;
+ }
+ ret = cals_alarm_add(index, alarm_info, &et);
+ warn_if(CAL_SUCCESS != ret, "cals_alarm_add() Failed(%d)", ret);
+ break;
}
}
}
list = list->next;
}
+ } else {
+ DBG("No alarm exists");
}
cals_end_trans(true);
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, "
"wkst = %d "
"WHERE event_id = %d",
CALS_TABLE_RRULE,
+ record->freq,
record->range_type,
record->until_type,
record->until_utime,
return r;
}
- r = _cals_delete_rrule(id);
- if (r) {
- ERR("_cals_delete_rrule (%d)", r);
- return r;
- }
-
r = cals_alarm_remove(CALS_ALARM_REMOVE_BY_EVENT_ID, id);
if (r) {
ERR("cals_alarm_remove() failed(%d)", r);
snprintf(query, sizeof(query), "SELECT A.* "
"FROM %s A LEFT JOIN %s B ON A.calendar_id = B.ROWID "
- "WHERE A.summary LIKE ('%%' || :key || '%%') AND B.visibility = 1 LIMIT %d OFFSET %d",
+ "WHERE A.summary LIKE ('%%' || :key || '%%') "
+ "AND B.visibility = 1 LIMIT %d OFFSET %d",
CALS_TABLE_SCHEDULE, CALS_TABLE_CALENDAR, limit, offset);
stmt = cals_query_prepare(query);
#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)
{
}
while (src[s_pos] != 0) {
- if (dest_size == d_pos - 1)
+ if (dest_size -1 == d_pos) {
break;
+ }
if ('%' == src[s_pos] || '_' == src[s_pos]) {
dest[d_pos++] = '\\';
}
}
dest[d_pos] = '\0';
-
return d_pos;
}
#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)
{
{
case CAL_STRUCT_TYPE_SCHEDULE:
case CAL_STRUCT_TYPE_TODO:
- cal_db_service_free_full_record((cal_sch_full_t*)(*event)->user_data,&ret);
+#ifdef CALS_IPC_CLIENT
+ __cal_free_full_record((cal_sch_full_t*)(*event)->user_data,&ret);
+#else
+ cal_db_service_free_full_record((cal_sch_full_t*)(*event)->user_data);
+#endif
CAL_FREE((*event)->user_data);
CAL_FREE(*event);
break;
{
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);
#ifndef _CALENDAR_SVC_STRUCT_INTERNAL_H_
#define _CALENDAR_SVC_STRUCT_INTERNAL_H_
+int cals_event_init(cal_sch_full_t *sch_full_record);
+int cals_todo_init(cal_sch_full_t *sch_full_record);
+
#endif // _CALENDAR_SVC_STRUCT_INTERNAL_H_
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;
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;
+ //UChar *_tzid;
long long int lli;
cal = _ucal_get_cal(tzid);
{
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
long long int cals_time_diff_with_now(struct cals_time *t);
char *cals_time_get_str_datetime(char *tzid, long long int t);
long long int cals_get_lli_now(void);
+long long int cals_time_date_to_utime(const char *tzid,
+ int year, int month, int mday, int hour, int minute, int second);
-#define CALS_TZID_0 "Europe/London"
+#ifdef CALS_IPC_CLIENT
+long long int _date_to_utime(int y, int mon, int d, int h, int min, int s);
+long long int _datetime_to_utime(char *datetime);
+#endif
+
+#define CALS_TZID_0 "Etc/Unknown"
#endif
return _todo_list_order[order];
}
-int cals_todo_init(cal_sch_full_t *sch_full_record)
-{
- retvm_if(NULL == sch_full_record, CAL_ERR_ARG_INVALID , "sch_full_record is NULL");
-
- memset(sch_full_record,0,sizeof(cal_sch_full_t));
-
- sch_full_record->cal_type = CALS_SCH_TYPE_TODO;
- sch_full_record->task_status = CALS_TODO_STATUS_NONE;
- sch_full_record->calendar_id = DEFAULT_TODO_CALENDAR_ID;
-
- sch_full_record->index = CALS_INVALID_ID;
- sch_full_record->timezone = -1;
- sch_full_record->contact_id = CALS_INVALID_ID;
- sch_full_record->calendar_type = CAL_PHONE_CALENDAR;
- sch_full_record->attendee_list = NULL;
- sch_full_record->busy_status = 2;
- sch_full_record->summary = NULL;
- sch_full_record->description = NULL;
- sch_full_record->location= NULL;
- sch_full_record->categories = NULL;
- sch_full_record->exdate = NULL;
- sch_full_record->organizer_email = NULL;
- sch_full_record->organizer_name = NULL;
- sch_full_record->uid= NULL;
- sch_full_record->gcal_id = NULL;
- sch_full_record->location_summary = NULL;
- sch_full_record->etag = NULL;
- sch_full_record->edit_uri = NULL;
- sch_full_record->gevent_id = NULL;
- sch_full_record->original_event_id = CALS_INVALID_ID;
-
- sch_full_record->sync_status = CAL_SYNC_STATUS_NEW;
- sch_full_record->account_id = -1;
- sch_full_record->is_deleted = 0;
- sch_full_record->latitude = 1000; // set default 1000 out of range(-180 ~ 180)
- sch_full_record->longitude = 1000; // set default 1000 out of range(-180 ~ 180)
- sch_full_record->freq = CALS_FREQ_ONCE;
-
- return CAL_SUCCESS;
-}
-
-
static int __todo_get_query_priority(int priority, char *query, int len)
{
switch (priority) {
{
cal_iter *it;
sqlite3_stmt *stmt = NULL;
- char buf_calendar_id[256] = {0};
+ char buf_id[256] = {0};
char buf_dtend_from[256] = {0};
char buf_dtend_to[256] = {0};
char buf_priority[256] = {0};
retv_if(order < CALS_TODO_LIST_ORDER_END_DATE || order > CALS_TODO_LIST_ORDER_STATUS, CAL_ERR_ARG_INVALID);
if (calendar_id > 0) {
- snprintf(buf_calendar_id, sizeof(buf_calendar_id), "AND calendar_id = %d ", calendar_id);
+ snprintf(buf_id, sizeof(buf_id), "AND calendar_id = %d ", calendar_id);
} else {
- memset(buf_calendar_id, 0x0, sizeof(buf_calendar_id));
+ memset(buf_id, 0x0, sizeof(buf_id));
}
- if (dtend_from >= 0) {
+ if (dtend_from != CALS_TODO_NO_DUE_DATE) {
snprintf(buf_dtend_from, sizeof(buf_dtend_from), "AND dtend_utime >= %lld ", dtend_from);
} else {
memset(buf_dtend_from, 0x0, sizeof(buf_dtend_from));
}
- if (dtend_to >= 0) {
+ if (dtend_to != CALS_TODO_NO_DUE_DATE) {
snprintf(buf_dtend_to, sizeof(buf_dtend_to), "AND dtend_utime <= %lld ", dtend_to);
} else {
memset(buf_dtend_to, 0x0, sizeof(buf_dtend_to));
"ORDER BY %s",
CALS_TABLE_SCHEDULE,
CAL_STRUCT_TYPE_TODO,
- buf_calendar_id, buf_dtend_from, buf_dtend_to, buf_priority, buf_status,
+ buf_id, buf_dtend_from, buf_dtend_to, buf_priority, buf_status,
cals_todo_get_order(order));
stmt = cals_query_prepare(query);
}
snprintf(query, sizeof(query),
- "SELECT id, changed_ver, created_ver, is_deleted FROM %s "
+ "SELECT id, changed_ver, created_ver, is_deleted, calendar_id FROM %s "
"WHERE changed_ver > %d AND original_event_id = %d AND type = %d %s "
"UNION "
- "SELECT schedule_id, deleted_ver, -1, 1 FROM %s "
+ "SELECT schedule_id, deleted_ver, -1, 1, calendar_id FROM %s "
"WHERE deleted_ver > %d AND schedule_type = %d %s",
CALS_TABLE_SCHEDULE,
version, CALS_INVALID_ID, CALS_SCH_TYPE_TODO, buf,
result->id = sqlite3_column_int(stmt, 0);
result->ver = sqlite3_column_int(stmt, 1);
- if (sqlite3_column_int(stmt, 3) == 1)
+ if (sqlite3_column_int(stmt, 3) == 1) {
result->type = CALS_UPDATED_TYPE_DELETED;
- else if (sqlite3_column_int(stmt, 2) == result->ver || version < sqlite3_column_int(stmt, 2))
+ } else if (sqlite3_column_int(stmt, 2) == result->ver || version < sqlite3_column_int(stmt, 2)) {
result->type = CALS_UPDATED_TYPE_INSERTED;
- else
+ } else {
result->type = CALS_UPDATED_TYPE_MODIFIED;
+ }
+ result->calendar_id = sqlite3_column_int(stmt, 4);
if (iter->info->head == NULL) {
iter->info->head = result;
snprintf(query, sizeof(query),
"SELECT * FROM %s "
"WHERE dtend_utime >= %lld AND dtend_utime <= %lld "
- "AND type = %d %s %s ",
+ "AND type = %d %s %s %s ",
CALS_TABLE_SCHEDULE,
due_from, dueto,
- CALS_SCH_TYPE_TODO, buf_prio, buf_stat);
+ CALS_SCH_TYPE_TODO, buf_prio, buf_stat, buf_id);
DBG("%s\n", query);
stmt = cals_query_prepare(query);
retvm_if(NULL == stmt, CAL_ERR_DB_FAILED, "Failed to query prepare");
{
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};
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));
snprintf(query, sizeof(query),
"SELECT count(*) FROM %s "
"WHERE dtend_utime >= %lld AND dtend_utime <= %lld "
- "AND type = %d %s %s ",
+ "AND type = %d %s %s %s ",
CALS_TABLE_SCHEDULE,
due_from, dueto,
- CALS_SCH_TYPE_TODO, buf_prio, buf_stat);
+ CALS_SCH_TYPE_TODO, buf_prio, buf_stat, buf_id);
DBG("%s\n", query);
stmt = cals_query_prepare(query);
int type;
int id;
int ver;
+ int calendar_id;
struct _updated *next;
} cals_updated;
#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
{
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 i;
cals_updated *mempool;
- mempool = calloc(CALS_MALLOC_DEFAULT_NUM, sizeof(cals_updated));
- for (i=0;i<CALS_MALLOC_DEFAULT_NUM-1;i++)
- mempool[i].next = &mempool[i+1];
+ mempool = calloc(1, sizeof(cals_updated));
+// for (i = 0; i < CALS_MALLOC_DEFAULT_NUM-1; i++) {
+// mempool[i].next = &mempool[i+1];
+// }
return mempool;
}
memseg = mempool;
while (memseg) {
- tmp = memseg[CALS_MALLOC_DEFAULT_NUM-1].next;
+ tmp = memseg->next;
+// tmp = memseg[CALS_MALLOC_DEFAULT_NUM-1].next;
free(memseg);
memseg = tmp;
}