diff options
42 files changed, 606 insertions, 436 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e79af0..7870785 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ SET(EXEC_PREFIX "\${prefix}") SET(LIBDIR "\${prefix}/lib") SET(INCLUDEDIR "\${prefix}/${DEST_INCLUDE_DIR}") SET(VERSION_MAJOR 0) -SET(VERSION "${VERSION_MAJOR}.5.2") +SET(VERSION "${VERSION_MAJOR}.6.1") EXECUTE_PROCESS(COMMAND build-util/generator.sh) @@ -54,8 +54,9 @@ FILE(GLOB HEADER_FILES ${SRC_INCLUDE_DIR}/contacts-svc*.h) INSTALL(FILES ${HEADER_FILES} DESTINATION ${DEST_INCLUDE_DIR}) INSTALL(FILES ${SRC_INCLUDE_DIR}/ContactsService_PG.h DESTINATION ${DEST_INCLUDE_DIR}) -FILE(GLOB NOTI_FILES ${CMAKE_SOURCE_DIR}/.CONTACTS_SVC_*_CHANGED) -INSTALL(FILES ${NOTI_FILES} DESTINATION /opt/data/contacts-svc) +FILE(GLOB NOTI_FILES ${CMAKE_SOURCE_DIR}/res/.CONTACTS_SVC_*) +INSTALL(FILES ${NOTI_FILES} DESTINATION /opt/data/contacts-svc + PERMISSIONS OWNER_WRITE OWNER_READ GROUP_WRITE GROUP_READ) INSTALL(DIRECTORY DESTINATION /opt/data/contacts-svc/img/vcard) diff --git a/debian/changelog b/debian/changelog index 04ff60e..89b5cd9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,7 @@ -contacts-service (0.5.2-37) unstable; urgency=low +contacts-service (0.6.1-10) unstable; urgency=low * release * Git: pkgs/c/contacts-service - * Tag: contacts-service_0.5.2-37 + * Tag: contacts-service_0.6.1-9 - -- Youngjae Shin <yj99.shin@samsung.com> Tue, 21 Feb 2012 18:36:56 +0900 + -- Youngjae Shin <yj99.shin@samsung.com> Mon, 09 Apr 2012 11:51:00 +0900 diff --git a/debian/libcontacts-service.postinst.in b/debian/libcontacts-service.postinst.in index 14aef55..d76c3a6 100755 --- a/debian/libcontacts-service.postinst.in +++ b/debian/libcontacts-service.postinst.in @@ -4,8 +4,9 @@ if [ "$USER" = "root" ] then # Change file owner chown root:root @PREFIX@/lib/libcontacts-service.so.* + #db_contact chown :6005 -R /opt/data/contacts-svc/img - chown :6005 /opt/data/contacts-svc/.CONTACTS_SVC_* + chown :6005 /opt/data/contacts-svc/.CONTACTS_SVC_*_CHANGED vconftool set -t int db/service/contacts/name_sorting_order 0 -g 6005 vconftool set -t int db/service/contacts/name_display_order 0 -g 6005 else @@ -15,7 +16,7 @@ fi # Change file permissions # chmod 644 /usr/lib/libcontacts-service.so -chmod 660 /opt/data/contacts-svc/.CONTACTS_SVC_* +chmod 660 /opt/data/contacts-svc/.CONTACTS_SVC_*_CHANGED chmod 770 -R /opt/data/contacts-svc/img echo "Done" diff --git a/helper/normalize.c b/helper/normalize.c index 241bbe8..b27160c 100755 --- a/helper/normalize.c +++ b/helper/normalize.c @@ -51,7 +51,7 @@ int helper_unicode_to_utf8(char *src, int src_len, char *dest, int dest_size) static inline int check_utf8(char c) { - if (c < 128) + if ((c & 0xff) < (128 & 0xff)) return 1; else if ((c & (char)0xe0) == (char)0xc0) return 2; diff --git a/helper/sim.c b/helper/sim.c index 13d9bb1..b99aa59 100755 --- a/helper/sim.c +++ b/helper/sim.c @@ -103,91 +103,34 @@ static int helper_deregister_tapi_sim_event(void) return CTS_SUCCESS; } -unsigned short HELPER_GSM7BitTable[128] = { - 0x0040, 0x00A3, 0x0024, 0x00A5, 0x00E8, 0x00E9, 0x00F9, 0x00EC, - 0x00F2, 0x00E7, 0x000A, 0x00D8, 0x00F8, 0x000D, 0x00C5, 0x00E5, - 0x0394, 0x005F, 0x03A6, 0x0393, 0x039B, 0x03A9, 0x03A0, 0x03A8, - 0x03A3, 0x0398, 0x039E, 0x00A0, 0x00C6, 0x00E6, 0x00DF, 0x00C9, - 0x0020, 0x0021, 0x0022, 0x0023, 0x00A4, 0x0025, 0x0026, 0x0027, - 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, - 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, - 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, - 0x00A1, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, - 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, - 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, - 0x0058, 0x0059, 0x005A, 0x00C4, 0x00D6, 0x00D1, 0x00DC, 0x00A7, - 0x00BF, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, - 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, - 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, - 0x0078, 0x0079, 0x007A, 0x00E4, 0x00F6, 0x00F1, 0x00FC, 0x00E0 -}; - -static int helper_sim_data_to_utf8(TelSimTextEncrypt_t type, - char *src, int src_len, char *dest, int dest_size) -{ - h_retvm_if(0 == src_len || NULL == src, CTS_ERR_ARG_INVALID, - "src(%p, len=%d) is invalid", src, src_len); - h_retvm_if(0 == dest_size || NULL == dest, CTS_ERR_ARG_INVALID, - "dest(%p, len=%d) is invalid", dest, dest_size); - - switch (type) - { - case TAPI_SIM_TEXT_ENC_GSM7BIT: - case TAPI_SIM_TEXT_ENC_ASCII: - memcpy(dest, src, CTS_MIN(dest_size, src_len)); - dest[CTS_MIN(dest_size-1, src_len)] = '\0'; - break; - case TAPI_SIM_TEXT_ENC_UCS2: - case TAPI_SIM_TEXT_ENC_HEX: - return helper_unicode_to_utf8(src, src_len, dest, dest_size); - default: - ERR("Unknown Encryption Type(%d)", type); - return CTS_ERR_ARG_INVALID; - } - - return CTS_SUCCESS; -} - #define HELPER_SIM_DATA_MAX_LENGTH 1024 -static int helper_insert_SDN(TelSimPb2GData_t *pb2g_data) +static int helper_insert_SDN(TelSimPbRecord_t *pb2g_data) { int ret; - char utf_data[HELPER_SIM_DATA_MAX_LENGTH]; - - ret = helper_sim_data_to_utf8(pb2g_data->NameEncryptType, (char *)pb2g_data->Name, - CTS_MIN(sizeof(pb2g_data->Name), pb2g_data->NameLen), - utf_data, sizeof(utf_data)); - h_retvm_if(ret != CTS_SUCCESS, ret, "helper_sim_data_to_utf8 is Failed(%d)", ret); - ret = helper_insert_SDN_contact(utf_data, (char *)pb2g_data->Number); + ret = helper_insert_SDN_contact((char *)pb2g_data->name, (char *)pb2g_data->number); h_retvm_if(ret != CTS_SUCCESS, ret, "helper_insert_SDN_contact() Failed(%d)", ret); return ret; } -static int helper_insert_2g_contact(int index, TelSimPb2GData_t *pb2g_data) +static int helper_insert_2g_contact(TelSimPbRecord_t *pb2g_data) { int ret, found_id; char uid[32]; - char utf_data[HELPER_SIM_DATA_MAX_LENGTH]; CTSstruct *contact; GSList *numbers=NULL; CTSvalue *name_val, *number_val, *base; - h_retvm_if(index <= 0, CTS_ERR_ARG_INVALID, "The index(%d) is invalid", index); + h_retvm_if(pb2g_data->index <= 0, CTS_ERR_ARG_INVALID, "The index(%d) is invalid", pb2g_data->index); snprintf(uid, sizeof(uid), "SIM:%s-%s-%s-%d", - TAPI_imsi.szMcc, TAPI_imsi.szMnc, TAPI_imsi.szMsin, index); + TAPI_imsi.szMcc, TAPI_imsi.szMnc, TAPI_imsi.szMsin, pb2g_data->index); HELPER_DBG("UID = %s", uid); found_id = contacts_svc_find_contact_by(CTS_FIND_BY_UID, uid); - ret = helper_sim_data_to_utf8(pb2g_data->NameEncryptType, (char *)pb2g_data->Name, - CTS_MIN(sizeof(pb2g_data->Name), pb2g_data->NameLen), - utf_data, sizeof(utf_data)); - h_retvm_if(ret != CTS_SUCCESS, ret, "helper_sim_data_to_utf8 is Failed(%d)", ret); - contact = contacts_svc_struct_new(CTS_STRUCT_CONTACT); base = contacts_svc_value_new(CTS_VALUE_CONTACT_BASE_INFO); @@ -199,7 +142,7 @@ static int helper_insert_2g_contact(int index, TelSimPb2GData_t *pb2g_data) name_val = contacts_svc_value_new(CTS_VALUE_NAME); if (name_val) { - contacts_svc_value_set_str(name_val, CTS_NAME_VAL_DISPLAY_STR, utf_data); + contacts_svc_value_set_str(name_val, CTS_NAME_VAL_DISPLAY_STR, (char *)pb2g_data->name); contacts_svc_struct_store_value(contact, CTS_CF_NAME_VALUE, name_val); contacts_svc_value_free(name_val); } @@ -207,7 +150,7 @@ static int helper_insert_2g_contact(int index, TelSimPb2GData_t *pb2g_data) number_val = contacts_svc_value_new(CTS_VALUE_NUMBER); if (number_val) { contacts_svc_value_set_str(number_val, CTS_NUM_VAL_NUMBER_STR, - (char *)pb2g_data->Number); + (char *)pb2g_data->number); contacts_svc_value_set_int(number_val, CTS_NUM_VAL_TYPE_INT, CTS_NUM_TYPE_CELL); contacts_svc_value_set_bool(number_val, CTS_NUM_VAL_DEFAULT_BOOL, true); } @@ -238,20 +181,40 @@ static int helper_insert_2g_contact(int index, TelSimPb2GData_t *pb2g_data) return ret; } -static int helper_insert_3g_contact(int index, TelSimPb3GData_t *pb3g_data) +static inline GSList* helper_insert_3g_contact_num(GSList *numbers, char *number) +{ + CTSvalue *value; + + value = contacts_svc_value_new(CTS_VALUE_NUMBER); + if (value) { + contacts_svc_value_set_str(value, CTS_NUM_VAL_NUMBER_STR, number); + //contacts_svc_value_set_int(value, CTS_NUM_VAL_TYPE_INT, CTS_NUM_TYPE_CELL); + } + return g_slist_append(numbers, value); +} + +static inline GSList* helper_insert_3g_contact_email(GSList *emails, char *email) { - int i, ret, found_id; + CTSvalue *value; + + value = contacts_svc_value_new(CTS_VALUE_EMAIL); + if (value) + contacts_svc_value_set_str(value, CTS_EMAIL_VAL_ADDR_STR, email); + return g_slist_append(emails, value); +} + +static int helper_insert_3g_contact(TelSimPbRecord_t *pb3g_data) +{ + int ret, found_id; char uid[32]; - char utf_data[HELPER_SIM_DATA_MAX_LENGTH]; CTSstruct *contact; - CTSvalue *name_val=NULL, *number_val, *email_val, *base; - TelSimPb3GFileDataInfo_t temp; + CTSvalue *name_val=NULL, *number_val, *base; GSList *numbers=NULL, *emails=NULL; - h_retvm_if(index <= 0, CTS_ERR_ARG_INVALID, "The index(%d) is invalid", index); + h_retvm_if(pb3g_data->index <= 0, CTS_ERR_ARG_INVALID, "The index(%d) is invalid", pb3g_data->index); snprintf(uid, sizeof(uid), "SIM:%s-%s-%s-%d", - TAPI_imsi.szMcc, TAPI_imsi.szMnc, TAPI_imsi.szMsin, index); + TAPI_imsi.szMcc, TAPI_imsi.szMnc, TAPI_imsi.szMsin, pb3g_data->index); HELPER_DBG("UID = %s", uid); found_id = contacts_svc_find_contact_by(CTS_FIND_BY_UID, uid); @@ -264,75 +227,35 @@ static int helper_insert_3g_contact(int index, TelSimPb3GData_t *pb3g_data) contacts_svc_value_free(base); } - for (i=0;i<pb3g_data->FileTypeCount;i++) - { - temp = pb3g_data->PbFileDataInfo[i]; - switch (temp.FileType) - { - case TAPI_PB_3G_NAME: - case TAPI_PB_3G_SNE: - ret = helper_sim_data_to_utf8(temp.FileDataType.EncryptionType, - (char *)temp.FileData, - CTS_MIN(sizeof(temp.FileData), temp.FileDataLength), - utf_data, sizeof(utf_data)); - if (ret != CTS_SUCCESS) { - ERR("helper_sim_data_to_utf8() Failed(%d)", ret); - goto CONVERT_3GPB_FAIL; - } - - if (!name_val) - name_val = contacts_svc_value_new(CTS_VALUE_NAME); - if (name_val) { - if (TAPI_PB_3G_NAME == temp.FileType) - contacts_svc_value_set_str(name_val, CTS_NAME_VAL_FIRST_STR, utf_data); - else - contacts_svc_value_set_str(name_val, CTS_NAME_VAL_LAST_STR, utf_data); - } + if (*pb3g_data->name) { + name_val = contacts_svc_value_new(CTS_VALUE_NAME); + if (name_val) + contacts_svc_value_set_str(name_val, CTS_NAME_VAL_FIRST_STR, (char *)pb3g_data->name); - contacts_svc_struct_store_value(contact, CTS_CF_NAME_VALUE, name_val); - break; - case TAPI_PB_3G_NUMBER: - case TAPI_PB_3G_ANR: - case TAPI_PB_3G_ANRA: - case TAPI_PB_3G_ANRB: - number_val = contacts_svc_value_new(CTS_VALUE_NUMBER); - if (number_val) { - contacts_svc_value_set_str(number_val, CTS_NUM_VAL_NUMBER_STR, - (char *)temp.FileData); - //contacts_svc_value_set_int(number_val, CTS_NUM_VAL_TYPE_INT, CTS_NUM_TYPE_CELL); - if (TAPI_PB_3G_NUMBER == temp.FileType) - contacts_svc_value_set_bool(number_val, CTS_NUM_VAL_DEFAULT_BOOL, true); - } - numbers = g_slist_append(numbers, number_val); - contacts_svc_struct_store_list(contact, CTS_CF_NUMBER_LIST, numbers); - contacts_svc_value_free(number_val); - break; - case TAPI_PB_3G_EMAIL: - ret = helper_sim_data_to_utf8(temp.FileDataType.EncryptionType, - (char *)temp.FileData, - CTS_MIN(sizeof(temp.FileData), temp.FileDataLength), - utf_data, sizeof(utf_data)); - if (ret != CTS_SUCCESS) { - ERR("helper_sim_data_to_utf8() Failed(%d)", ret); - goto CONVERT_3GPB_FAIL; - } + contacts_svc_struct_store_value(contact, CTS_CF_NAME_VALUE, name_val); + } - email_val = contacts_svc_value_new(CTS_VALUE_EMAIL); - if (email_val) { - contacts_svc_value_set_str(email_val, CTS_EMAIL_VAL_ADDR_STR, - (char *)temp.FileData); - contacts_svc_value_set_bool(email_val, CTS_NUM_VAL_DEFAULT_BOOL, true); - } - emails = g_slist_append(emails, email_val); - contacts_svc_struct_store_list(contact, CTS_CF_EMAIL_LIST, emails); - contacts_svc_value_free(email_val); - break; - default: - ERR("Unknown file type=%d", temp.FileType); - break; + if (*pb3g_data->number) { + number_val = contacts_svc_value_new(CTS_VALUE_NUMBER); + if (number_val) { + contacts_svc_value_set_str(number_val, CTS_NUM_VAL_NUMBER_STR, (char *)pb3g_data->number); + //contacts_svc_value_set_int(number_val, CTS_NUM_VAL_TYPE_INT, CTS_NUM_TYPE_CELL); + contacts_svc_value_set_bool(number_val, CTS_NUM_VAL_DEFAULT_BOOL, true); } + numbers = g_slist_append(numbers, number_val); } + numbers = helper_insert_3g_contact_num(numbers, (char *)pb3g_data->anr1); + numbers = helper_insert_3g_contact_num(numbers, (char *)pb3g_data->anr2); + numbers = helper_insert_3g_contact_num(numbers, (char *)pb3g_data->anr3); + contacts_svc_struct_store_list(contact, CTS_CF_NUMBER_LIST, numbers); + + emails = helper_insert_3g_contact_email(emails, (char *)pb3g_data->email1); + emails = helper_insert_3g_contact_email(emails, (char *)pb3g_data->email2); + emails = helper_insert_3g_contact_email(emails, (char *)pb3g_data->email3); + emails = helper_insert_3g_contact_email(emails, (char *)pb3g_data->email4); + contacts_svc_struct_store_list(contact, CTS_CF_EMAIL_LIST, emails); + if (0 < found_id) { CTSstruct *temp; ret = contacts_svc_get_contact(found_id, &temp); @@ -350,7 +273,6 @@ static int helper_insert_3g_contact(int index, TelSimPb3GData_t *pb3g_data) h_warn_if(ret < CTS_SUCCESS, "contacts_svc_insert_contact() Failed(%d)", ret); } -CONVERT_3GPB_FAIL: contacts_svc_struct_free(contact); return ret; } @@ -358,7 +280,7 @@ CONVERT_3GPB_FAIL: static int helper_sim_read_record_cb(const TelTapiEvent_t *sim_event, void *data) { int ret, saved_pb_num, i=0, req_id; - TelSimPbRecordData_t *sim_info; + TelSimPbRecord_t *sim_info; HELPER_FN_CALL; @@ -368,19 +290,19 @@ static int helper_sim_read_record_cb(const TelTapiEvent_t *sim_event, void *data "Unknown Event(EventClass = 0x%X, EventType = 0x%X", sim_event->EventClass, sim_event->EventType); - sim_info = (TelSimPbRecordData_t*)sim_event->pData; + sim_info = (TelSimPbRecord_t*)sim_event->pData; if (NULL == sim_info) { ERR("sim_info is NULL, Status = %d", sim_event->Status); goto ERROR_RETURN; } if (TAPI_SIM_PB_SUCCESS != sim_event->Status) { - if (TAPI_SIM_PB_SDN == sim_info->StorageFileType && + if (TAPI_SIM_PB_SDN == sim_info->phonebook_type && TAPI_SIM_PB_INVALID_INDEX == sim_event->Status) { - HELPER_DBG("Index = %d", sim_info->Index); - ret = tel_read_sim_pb_record(sim_info->StorageFileType, - sim_info->Index+1, &req_id); + HELPER_DBG("Index = %d", sim_info->index); + ret = tel_read_sim_pb_record(sim_info->phonebook_type, + sim_info->index+1, &req_id); if (TAPI_API_SUCCESS != ret) { ERR("tel_read_sim_pb_record() Failed(%d)", ret); goto ERROR_RETURN; @@ -391,7 +313,7 @@ static int helper_sim_read_record_cb(const TelTapiEvent_t *sim_event, void *data goto ERROR_RETURN; } - switch (sim_info->StorageFileType) + switch (sim_info->phonebook_type) { case TAPI_SIM_PB_SDN: saved_pb_num = sim_event->pDataLen / sizeof(TelSimPbRecordData_t); @@ -400,7 +322,7 @@ static int helper_sim_read_record_cb(const TelTapiEvent_t *sim_event, void *data goto ERROR_RETURN; } while (true) { - ret = helper_insert_SDN(&sim_info->ContactInfo.Pb2GData); + ret = helper_insert_SDN(sim_info); h_warn_if(ret < CTS_SUCCESS, "helper_insert_SDN() is Failed(%d)", ret); if (saved_pb_num == ++i) break; sim_info++; @@ -414,7 +336,7 @@ static int helper_sim_read_record_cb(const TelTapiEvent_t *sim_event, void *data goto ERROR_RETURN; } while (true) { - ret = helper_insert_2g_contact(sim_info->Index, &sim_info->ContactInfo.Pb2GData); + ret = helper_insert_2g_contact(sim_info); h_warn_if(ret < CTS_SUCCESS, "helper_insert_2g_contact() is Failed(%d)", ret); if (saved_pb_num == ++i) break; sim_info++; @@ -428,7 +350,7 @@ static int helper_sim_read_record_cb(const TelTapiEvent_t *sim_event, void *data goto ERROR_RETURN; } while (true) { - ret = helper_insert_3g_contact(sim_info->Index, &sim_info->ContactInfo.Pb3GData); + ret = helper_insert_3g_contact(sim_info); h_warn_if(ret < CTS_SUCCESS, "helper_insert_3g_contact() is Failed(%d)", ret); if (saved_pb_num == ++i) break; sim_info++; @@ -437,13 +359,13 @@ static int helper_sim_read_record_cb(const TelTapiEvent_t *sim_event, void *data case TAPI_SIM_PB_FDN: case TAPI_SIM_PB_MSISDN: default: - ERR("Unknown storage type(%d)", sim_info->StorageFileType); + ERR("Unknown storage type(%d)", sim_info->phonebook_type); goto ERROR_RETURN; } - if (sim_info->NextIndex && CTS_TAPI_SIM_PB_MAX != sim_info->NextIndex) { - HELPER_DBG("NextIndex = %d", sim_info->NextIndex); - ret = tel_read_sim_pb_record(sim_info->StorageFileType, - sim_info->NextIndex, &req_id); + if (sim_info->next_index && CTS_TAPI_SIM_PB_MAX != sim_info->next_index) { + HELPER_DBG("NextIndex = %d", sim_info->next_index); + ret = tel_read_sim_pb_record(sim_info->phonebook_type, + sim_info->next_index, &req_id); if (TAPI_API_SUCCESS != ret) { ERR("tel_read_sim_pb_record() Failed(%d)", ret); goto ERROR_RETURN; @@ -475,54 +397,6 @@ ERROR_RETURN: return CTS_ERR_TAPI_FAILED; } -int helper_sim_read_pb_record(void *data) -{ - int ret, req_id; - TelSimPbFileType_t storage; - TelSimCardType_t cardInfo; - - h_retvm_if(NULL != helper_import_sim_data, CTS_ERR_ENV_INVALID, - "Helper is already processing with sim"); - - ret = helper_register_tapi_sim_event(); - h_retvm_if(TAPI_API_SUCCESS != ret, ret, - "helper_register_tapi_sim_event() Failed(%d)", ret); - - ret = tel_get_sim_type(&cardInfo); - h_retvm_if(TAPI_API_SUCCESS != ret, CTS_ERR_TAPI_FAILED, - "tel_get_sim_type() Failed(%d)", ret); - - if (TAPI_SIM_CARD_TYPE_USIM == cardInfo) - storage = TAPI_SIM_PB_3GSIM; - else - storage = TAPI_SIM_PB_ADN; - - int first_id, sim_pb_inited; - TelSimPbList_t pb_list = {0}; - - ret = tel_get_sim_pb_init_info(&sim_pb_inited, &pb_list, &first_id); - h_retvm_if(TAPI_API_SUCCESS != ret, CTS_ERR_TAPI_FAILED, - "tel_get_sim_pb_init_info() Failed(%d)", ret); - HELPER_DBG("sim_pb_inited(%d), first_id(%d)", sim_pb_inited, first_id); - - tel_get_sim_imsi(&TAPI_imsi); - h_retvm_if(CTS_SUCCESS != ret, ret, "tel_get_sim_imsi() Failed(%d)", ret); - - if (sim_pb_inited) { - if (CTS_TAPI_SIM_PB_MAX == first_id) return CTS_ERR_NO_DATA; - ret = tel_read_sim_pb_record(storage, first_id, &req_id); - h_retvm_if(TAPI_API_SUCCESS != ret, CTS_ERR_TAPI_FAILED, - "tel_read_sim_pb_record() Failed(%d)", ret); - } - - ret = contacts_svc_begin_trans(); - h_retvm_if(CTS_SUCCESS != ret, ret, "contacts_svc_begin_trans() Failed(%d)", ret); - - helper_import_sim_data = data; - - return CTS_SUCCESS; -} - static int helper_sim_pb_count_cb(const TelTapiEvent_t *sim_event, void *data) { @@ -540,11 +414,13 @@ static int helper_sim_pb_count_cb(const TelTapiEvent_t *sim_event, void *data) sim_info = (TelSimPbStorageInfo_t *)sim_event->pData; if (NULL == sim_info) { ERR("sim_info is NULL, Status = %d", sim_event->Status); + ret = CTS_ERR_TAPI_FAILED; goto ERROR_RETURN; } if (TAPI_SIM_PB_SUCCESS != sim_event->Status) { ERR("SIM phonebook access Failed(%d)", sim_event->Status); + ret = CTS_ERR_TAPI_FAILED; goto ERROR_RETURN; } @@ -552,27 +428,96 @@ static int helper_sim_pb_count_cb(const TelTapiEvent_t *sim_event, void *data) { case TAPI_SIM_PB_SDN: if (sim_info->UsedRecordCount) { - ret = tel_read_sim_pb_record(TAPI_SIM_PB_SDN, 1, &req_id); - h_retvm_if(TAPI_API_SUCCESS != ret, CTS_ERR_TAPI_FAILED, - "tel_read_sim_pb_record() Failed(%d)", ret); + HELPER_DBG("SDN count = %d", sim_info->UsedRecordCount); + ret = tel_read_sim_pb_record(sim_info->StorageFileType, 1, &req_id); + if (TAPI_API_SUCCESS != ret) { + ERR("tel_read_sim_pb_record() Failed(%d)", ret); + ret = CTS_ERR_TAPI_FAILED; + goto ERROR_RETURN; + } } break; case TAPI_SIM_PB_ADN: case TAPI_SIM_PB_3GSIM: + if (sim_info->UsedRecordCount) { + HELPER_DBG("ADN count = %d", sim_info->UsedRecordCount); + ret = tel_read_sim_pb_record(sim_info->StorageFileType, 1, &req_id); + if (TAPI_API_SUCCESS != ret) { + ERR("tel_read_sim_pb_record() Failed(%d)", ret); + ret = CTS_ERR_TAPI_FAILED; + goto ERROR_RETURN; + } + ret = contacts_svc_begin_trans(); + if (CTS_SUCCESS != ret) { + ERR("contacts_svc_begin_trans() Failed(%d)", ret); + goto ERROR_RETURN; + } + } else { + helper_socket_return(helper_import_sim_data, CTS_ERR_NO_DATA, 0, NULL); + ret = CTS_SUCCESS; + goto ERROR_RETURN; + } + break; case TAPI_SIM_PB_FDN: case TAPI_SIM_PB_MSISDN: default: ERR("Unknown storage type(%d)", sim_info->StorageFileType); - goto ERROR_RETURN; + return CTS_ERR_TAPI_FAILED; } return CTS_SUCCESS; ERROR_RETURN: helper_deregister_tapi_sim_event(); - return CTS_ERR_TAPI_FAILED; + return ret; } + +int helper_sim_read_pb_record(void *data) +{ + int ret, req_id; + TelSimPbFileType_t storage; + TelSimCardType_t cardInfo; + + h_retvm_if(NULL != helper_import_sim_data, CTS_ERR_ENV_INVALID, + "Helper is already processing with sim"); + + ret = helper_register_tapi_sim_event(); + h_retvm_if(TAPI_API_SUCCESS != ret, ret, + "helper_register_tapi_sim_event() Failed(%d)", ret); + + ret = tel_get_sim_type(&cardInfo); + h_retvm_if(TAPI_API_SUCCESS != ret, CTS_ERR_TAPI_FAILED, + "tel_get_sim_type() Failed(%d)", ret); + + if (TAPI_SIM_CARD_TYPE_USIM == cardInfo) + storage = TAPI_SIM_PB_3GSIM; + else + storage = TAPI_SIM_PB_ADN; + + int first_id, sim_pb_inited; + TelSimPbList_t pb_list = {0}; + + ret = tel_get_sim_pb_init_info(&sim_pb_inited, &pb_list, &first_id); + h_retvm_if(TAPI_API_SUCCESS != ret, CTS_ERR_TAPI_FAILED, + "tel_get_sim_pb_init_info() Failed(%d)", ret); + HELPER_DBG("sim_pb_inited(%d), first_id(%d)", sim_pb_inited, first_id); + + tel_get_sim_imsi(&TAPI_imsi); + h_retvm_if(CTS_SUCCESS != ret, ret, "tel_get_sim_imsi() Failed(%d)", ret); + + if (sim_pb_inited) { + ret = tel_get_sim_pb_count(storage, &req_id); + h_retvm_if(TAPI_API_SUCCESS != ret, CTS_ERR_TAPI_FAILED, + "tel_get_sim_pb_count() Failed(%d)", ret); + } + + helper_import_sim_data = data; + + return CTS_SUCCESS; +} + + int helper_sim_read_SDN(void* data) { int ret, req_id, card_changed=0; diff --git a/include/contacts-svc-struct.head b/include/contacts-svc-struct.head index a0242be..d60a0d1 100755 --- a/include/contacts-svc-struct.head +++ b/include/contacts-svc-struct.head @@ -30,8 +30,8 @@ * @addtogroup CONTACTS_SVC_STRUCT * @{ * - * This interface provides methods to handle Structs (= collection of values)
- * and values of contacts service (individual properties of a contact).
+ * This interface provides methods to handle Structs (= collection of values) + * and values of contacts service (individual properties of a contact). * * @section sec1 Properties and Policies * - Memory always has to be freed by its creator, unless stated otherwise. diff --git a/packaging/contacts-service.spec b/packaging/contacts-service.spec index 0d87cd1..e7aabfb 100644 --- a/packaging/contacts-service.spec +++ b/packaging/contacts-service.spec @@ -1,7 +1,7 @@ Name: contacts-service Summary: Contacts Service -Version: 0.5.2 -Release: 3.6 +Version: 0.6.1 +Release: 10 Group: TO_BE/FILLED_IN License: Apache-2.0 Source0: %{name}-%{version}.tar.gz @@ -14,7 +14,6 @@ BuildRequires: vconf-keys-devel BuildRequires: pkgconfig(db-util) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(heynoti) BuildRequires: pkgconfig(sqlite3) BuildRequires: pkgconfig(tapi) BuildRequires: pkgconfig(glib-2.0) @@ -37,46 +36,54 @@ Contacts Service Library (devel) %build cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -make %{?jobs:-j%jobs} -mkdir -p %{buildroot}/opt/data/contacts-svc/img + +make %{?jobs:-j%jobs} %install +rm -rf %{buildroot} %make_install -%post +mkdir -p %{buildroot}/etc/rc.d/rc3.d/ +mkdir -p %{buildroot}/etc/rc.d/rc5.d/ +ln -s ../init.d/contacts-svc-helper.sh %{buildroot}/etc/rc.d/rc3.d/S50contacts-svc-helper +ln -s ../init.d/contacts-svc-helper.sh %{buildroot}/etc/rc.d/rc5.d/S50contacts-svc-helper + +%post /sbin/ldconfig + +# from contacts-service-bin.postinst contacts-svc-helper schema chown :6005 /opt/dbspace/.contacts-svc.db chown :6005 /opt/dbspace/.contacts-svc.db-journal +chown :6005 -R /opt/data/contacts-svc/img +chown :6005 /opt/data/contacts-svc/.CONTACTS_SVC_* +chmod 660 /opt/dbspace/.contacts-svc.db +chmod 660 /opt/dbspace/.contacts-svc.db-journal +chmod 770 -R /opt/data/contacts-svc/img/ +chmod 660 /opt/data/contacts-svc/.CONTACTS_SVC_* vconftool set -t int db/service/contacts/default_lang 1 + +# from libcontacts-service.postinst vconftool set -t int db/service/contacts/name_sorting_order 0 -g 6005 vconftool set -t int db/service/contacts/name_display_order 0 -g 6005 -mkdir -p /etc/rc.d/rc3.d/ -mkdir -p /etc/rc.d/rc5.d/ -ln -s /etc/init.d/contacts-svc-helper.sh /etc/rc.d/rc3.d/S50contacts-svc-helper -ln -s /etc/init.d/contacts-svc-helper.sh /etc/rc.d/rc5.d/S50contacts-svc-helper - %postun -p /sbin/ldconfig %files -%dir %attr(770,root,root) /opt/data/contacts-svc/img -%attr(0660,root,db_contact)/opt/data/contacts-svc/.CONTACTS_SVC_AB_CHANGED -%attr(0660,root,db_contact)/opt/data/contacts-svc/.CONTACTS_SVC_DB_CHANGED -%attr(0660,root,db_contact)/opt/data/contacts-svc/.CONTACTS_SVC_FAVOR_CHANGED -%attr(0660,root,db_contact)/opt/data/contacts-svc/.CONTACTS_SVC_GROUP_CHANGED -%attr(0660,root,db_contact)/opt/data/contacts-svc/.CONTACTS_SVC_PLOG_CHANGED -%attr(0660,root,db_contact)/opt/data/contacts-svc/.CONTACTS_SVC_SPEED_CHANGED -%attr(0660,root,db_contact)/opt/data/contacts-svc/.CONTACTS_SVC_MISSED_CHANGED -%{_libdir}/libcontacts-service.so.* -%{_bindir}/contacts-svc-helper +%defattr(-,root,root,-) +%{_libdir}/libcontacts-service.so* +%{_bindir}/contacts-svc-helper* %attr(0755,root,root) /etc/rc.d/init.d/contacts-svc-helper.sh +/etc/rc.d/rc*.d/S50contacts-svc-helper +/opt/data/contacts-svc/.CONTACTS_SVC_* +/opt/data/contacts-svc/img/* %files devel +%defattr(-,root,root,-) %{_libdir}/*.so %{_libdir}/pkgconfig/contacts-service.pc %{_includedir}/contacts-svc/*.h diff --git a/res/.CONTACTS_SVC_AB_CHANGED b/res/.CONTACTS_SVC_AB_CHANGED new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/res/.CONTACTS_SVC_AB_CHANGED diff --git a/res/.CONTACTS_SVC_DB_CHANGED b/res/.CONTACTS_SVC_DB_CHANGED new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/res/.CONTACTS_SVC_DB_CHANGED diff --git a/res/.CONTACTS_SVC_FAVOR_CHANGED b/res/.CONTACTS_SVC_FAVOR_CHANGED new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/res/.CONTACTS_SVC_FAVOR_CHANGED diff --git a/res/.CONTACTS_SVC_GROUP_CHANGED b/res/.CONTACTS_SVC_GROUP_CHANGED new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/res/.CONTACTS_SVC_GROUP_CHANGED diff --git a/res/.CONTACTS_SVC_MISSED_CHANGED b/res/.CONTACTS_SVC_MISSED_CHANGED new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/res/.CONTACTS_SVC_MISSED_CHANGED diff --git a/res/.CONTACTS_SVC_PLOG_CHANGED b/res/.CONTACTS_SVC_PLOG_CHANGED new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/res/.CONTACTS_SVC_PLOG_CHANGED diff --git a/res/.CONTACTS_SVC_SPEED_CHANGED b/res/.CONTACTS_SVC_SPEED_CHANGED new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/res/.CONTACTS_SVC_SPEED_CHANGED diff --git a/res/Not empty folder b/res/Not empty folder new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/res/Not empty folder @@ -57,11 +57,9 @@ uid TEXT, ringtone TEXT, note TEXT, image0 TEXT, -- normal image -image1 TEXT, -- full image -person_id INTEGER +image1 TEXT -- full image ); CREATE INDEX contacts_ver_idx ON contacts(changed_ver); -CREATE INDEX contacts_person_idx ON contacts(person_id); CREATE TRIGGER trg_contacts_del AFTER DELETE ON contacts BEGIN DELETE FROM data WHERE contact_id = old.contact_id; @@ -71,7 +69,7 @@ CREATE TRIGGER trg_contacts_del AFTER DELETE ON contacts CREATE TABLE deleteds ( -contact_id INTEGER, +contact_id INTEGER PRIMARY KEY, addrbook_id INTEGER, deleted_ver INTEGER ); @@ -118,8 +116,7 @@ data6 TEXT, data7 TEXT, data8 TEXT, data9 TEXT, -data10 TEXT, -person_id INTEGER +data10 TEXT ); CREATE TRIGGER trg_data_number_del AFTER DELETE ON data WHEN old.datatype = 8 @@ -139,7 +136,6 @@ CREATE INDEX data_idx7 ON data(data7); CREATE INDEX data_idx8 ON data(data8); CREATE INDEX data_idx9 ON data(data9); CREATE INDEX data_idx10 ON data(data10); -CREATE INDEX data_person_idx ON data(person_id); CREATE TABLE groups ( diff --git a/src/cts-addressbook.c b/src/cts-addressbook.c index bb7d516..c032754 100755 --- a/src/cts-addressbook.c +++ b/src/cts-addressbook.c @@ -28,7 +28,7 @@ static inline int cts_reset_internal_addressbook(void) { CTS_FN_CALL; int ret; - char query[CTS_SQL_MAX_LEN] = {0}; + char query[CTS_SQL_MIN_LEN]; ret = contacts_svc_begin_trans(); retvm_if(ret, ret, "contacts_svc_begin_trans() Failed(%d)", ret); diff --git a/src/cts-addressbook.h b/src/cts-addressbook.h index efd64ab..244433e 100755 --- a/src/cts-addressbook.h +++ b/src/cts-addressbook.h @@ -41,6 +41,10 @@ enum ADDRESSBOOK{ * @{ * * This interface provides methods to insert/update/delete the addressbook. + * Addressbook supports groups and contacts. Several addressbooks can be included in the same account_id. + * + * If the ID of an addressbook is 'zero', it means it is the internal addressbook of a phone. + * It needs additional management because it is not included in database(physical storage). * * - getting all addressbook (0 is logical value for internal addressbook) * @code diff --git a/src/cts-contact.c b/src/cts-contact.c index b090565..ed997fe 100755 --- a/src/cts-contact.c +++ b/src/cts-contact.c @@ -780,7 +780,8 @@ static inline void cts_contact_remove_dup_data_IM(GSList *IMs) if(NULL == im2 || im1 == im2) continue; if (!im2->deleted && im1->type == im2->type && - !cts_safe_strcmp(im1->im_id, im2->im_id)) { + !cts_safe_strcmp(im1->im_id, im2->im_id) && + !cts_safe_strcmp(im1->svc_name, im2->svc_name)) { im2->deleted = true; } } @@ -887,8 +888,8 @@ static void cts_contact_remove_dup_data(contact_t *contact) static inline int cts_insert_contact(int addressbook_id, contact_t *contact) { int ret; - char *img_path; char query[CTS_SQL_MAX_LEN] = {0}; + char normal_img[CTS_SQL_MAX_LEN], full_img[CTS_SQL_MAX_LEN]; retv_if(NULL == contact, CTS_ERR_ARG_NULL); @@ -932,24 +933,29 @@ static inline int cts_insert_contact(int addressbook_id, contact_t *contact) if (contact->base->note) cts_stmt_bind_text(stmt, 3, contact->base->note); + normal_img[0] = '\0'; if (contact->base->img_path) { - ret = cts_add_image_file(CTS_IMG_NORMAL, contact->base->id, contact->base->img_path, &img_path); + ret = cts_add_image_file(CTS_IMG_NORMAL, contact->base->id, contact->base->img_path, + normal_img, sizeof(normal_img)); if (CTS_SUCCESS != ret) { ERR("cts_add_image_file(NORMAL) Failed(%d)", ret); cts_stmt_finalize(stmt); return ret; } - cts_stmt_bind_text(stmt, 4, img_path); + cts_stmt_bind_text(stmt, 4, normal_img); } else if (contact->base->vcard_img_path) { - ret = cts_add_image_file(CTS_IMG_NORMAL, contact->base->id, contact->base->vcard_img_path, &img_path); + ret = cts_add_image_file(CTS_IMG_NORMAL, contact->base->id, contact->base->vcard_img_path, + normal_img, sizeof(normal_img)); if (CTS_SUCCESS == ret) - cts_stmt_bind_text(stmt, 4, img_path); + cts_stmt_bind_text(stmt, 4, normal_img); } - ret = cts_add_image_file(CTS_IMG_FULL, contact->base->id, contact->base->full_img_path, &img_path); + full_img[0] = '\0'; + ret = cts_add_image_file(CTS_IMG_FULL, contact->base->id, contact->base->full_img_path, + full_img, sizeof(full_img)); if (CTS_SUCCESS == ret) - cts_stmt_bind_text(stmt, 5, img_path); + cts_stmt_bind_text(stmt, 5, full_img); ret = cts_stmt_step(stmt); if (CTS_SUCCESS != ret) { @@ -966,7 +972,7 @@ static inline int cts_insert_contact(int addressbook_id, contact_t *contact) API int contacts_svc_insert_contact(int addressbook_id, CTSstruct* contact) { int ret; - contact_t *record; + contact_t *record = (contact_t *)contact;; CTS_FN_CALL; @@ -979,8 +985,6 @@ API int contacts_svc_insert_contact(int addressbook_id, CTSstruct* contact) ret = contacts_svc_begin_trans(); retvm_if(ret, ret, "contacts_svc_begin_trans() Failed(%d)", ret); - record = (contact_t *)contact; - ret = cts_db_get_next_id(CTS_TABLE_CONTACTS); if (ret < CTS_SUCCESS) { @@ -1933,7 +1937,8 @@ static inline int cts_update_contact(contact_t *contact) { int i, ret, len; char query[CTS_SQL_MAX_LEN] = {0}; - char *img_path; + char normal_img[CTS_SQL_MIN_LEN]; + char full_img[CTS_SQL_MIN_LEN]; snprintf(query, sizeof(query), "SELECT count(contact_id) FROM %s WHERE contact_id = %d", @@ -2029,22 +2034,25 @@ static inline int cts_update_contact(contact_t *contact) if (contact->base->img_changed || (NULL == contact->base->img_path && contact->base->vcard_img_path)) { + normal_img[0] = '\0'; if (contact->base->img_path) { - ret = cts_update_image_file(CTS_IMG_NORMAL, contact->base->id, contact->base->img_path, &img_path); + ret = cts_update_image_file(CTS_IMG_NORMAL, contact->base->id, contact->base->img_path, + normal_img, sizeof(normal_img)); if (CTS_SUCCESS != ret) { ERR("cts_update_image_file() Failed(%d)", ret); cts_stmt_finalize(stmt); contacts_svc_end_trans(false); return ret; } - if (img_path) - cts_stmt_bind_text(stmt, i, img_path); + if (*normal_img) + cts_stmt_bind_text(stmt, i, normal_img); i++; } else { if (contact->base->vcard_img_path) { - ret = cts_update_image_file(CTS_IMG_NORMAL, contact->base->id, contact->base->vcard_img_path, &img_path); - if (CTS_SUCCESS == ret && img_path) - cts_stmt_bind_text(stmt, i, img_path); + ret = cts_update_image_file(CTS_IMG_NORMAL, contact->base->id, contact->base->vcard_img_path, + normal_img, sizeof(normal_img)); + if (CTS_SUCCESS == ret && *normal_img) + cts_stmt_bind_text(stmt, i, normal_img); i++; } else { ret = cts_delete_image_file(CTS_IMG_NORMAL, contact->base->id); @@ -2059,9 +2067,11 @@ static inline int cts_update_contact(contact_t *contact) } if (contact->base->full_img_changed) { - ret = cts_update_image_file(CTS_IMG_FULL, contact->base->id, contact->base->full_img_path, &img_path); - if (CTS_SUCCESS == ret && img_path) - cts_stmt_bind_text(stmt, i, img_path); + full_img[0] = '\0'; + ret = cts_update_image_file(CTS_IMG_FULL, contact->base->id, contact->base->full_img_path, + full_img, sizeof(full_img)); + if (CTS_SUCCESS == ret && *full_img) + cts_stmt_bind_text(stmt, i, full_img); i++; } @@ -2086,8 +2096,8 @@ static inline int cts_update_contact(contact_t *contact) API int contacts_svc_update_contact(CTSstruct* contact) { - CTS_FN_CALL; int ret; + contact_t *record = (contact_t *)contact; retv_if(NULL == contact, CTS_ERR_ARG_NULL); retvm_if(CTS_STRUCT_CONTACT != contact->s_type, CTS_ERR_ARG_INVALID, @@ -2095,7 +2105,7 @@ API int contacts_svc_update_contact(CTSstruct* contact) CTS_START_TIME_CHECK; - ret = cts_update_contact((contact_t *)contact); + ret = cts_update_contact(record); CTS_END_TIME_CHECK(); return ret; @@ -2269,7 +2279,6 @@ API int contacts_svc_put_contact_value(cts_put_contact_val_op op_code, int contact_id, CTSvalue* value) { CTS_FN_CALL; - int ret; retv_if(NULL == value, CTS_ERR_ARG_NULL); @@ -2408,11 +2417,18 @@ static int cts_get_main_contacts_info(int op_code, int index, contact_t *contact contact->base->is_favorite = cts_stmt_get_int(stmt, count++); if (op_code & CTS_MAIN_CTS_GET_IMG) { + char tmp_path[CTS_IMG_PATH_SIZE_MAX]; contact->base->embedded = true; temp = cts_stmt_get_text(stmt, count++); - contact->base->img_path = SAFE_STRDUP(temp); + if (temp) { + snprintf(tmp_path, sizeof(tmp_path), "%s/%s", CTS_IMAGE_LOCATION, temp); + contact->base->img_path = strdup(tmp_path); + } temp = cts_stmt_get_text(stmt, count++); - contact->base->full_img_path = SAFE_STRDUP(temp); + if (temp) { + snprintf(tmp_path, sizeof(tmp_path), "%s/%s", CTS_IMAGE_LOCATION, temp); + contact->base->full_img_path = strdup(tmp_path); + } } cts_stmt_finalize(stmt); @@ -2498,7 +2514,12 @@ static inline int cts_get_data_info_messenger(cts_stmt stmt, contact_t *contact) result->type = cts_stmt_get_int(stmt, cnt++); temp = cts_stmt_get_text(stmt, cnt++); result->im_id = SAFE_STRDUP(temp); - + if (0 == result->type) { + temp = cts_stmt_get_text(stmt, cnt++); + result->svc_name = SAFE_STRDUP(temp); + temp = cts_stmt_get_text(stmt, cnt++); + result->svc_op = SAFE_STRDUP(temp); + } contact->messengers = g_slist_append(contact->messengers, result); } return CTS_SUCCESS; @@ -2651,12 +2672,8 @@ static inline int cts_get_data_info_extend(cts_stmt stmt, int type, return CTS_SUCCESS; } -enum{ - CTS_GET_DATA_BY_CONTACT_ID, - CTS_GET_DATA_BY_ID -}; -static int cts_get_data_info(int op_code, int field, int index, contact_t *contact) +int cts_get_data_info(int op_code, int field, int index, contact_t *contact) { int ret, datatype, len; cts_stmt stmt = NULL; @@ -3072,7 +3089,6 @@ API int contacts_svc_get_contact(int index, CTSstruct **contact) record = (contact_t *)contacts_svc_struct_new(CTS_STRUCT_CONTACT); ret = cts_get_main_contacts_info(CTS_MAIN_CTS_GET_ALL, index, record); - if (CTS_SUCCESS != ret) { ERR("cts_get_main_contacts_info(ALL) Failed(%d)", ret); goto CTS_RETURN_ERROR; diff --git a/src/cts-contact.h b/src/cts-contact.h index 85b1a2b..0fd1531 100755 --- a/src/cts-contact.h +++ b/src/cts-contact.h @@ -21,6 +21,13 @@ #ifndef __CTS_CONTACT_H__ #define __CTS_CONTACT_H__ +enum{ + CTS_GET_DATA_BY_CONTACT_ID, + CTS_GET_DATA_BY_ID +}; + +int cts_get_data_info(int op_code, int field, int index, contact_t *contact); + //<!-- /** * @defgroup CONTACTS_SVC_NAME Contact Naming Rule diff --git a/src/cts-group.c b/src/cts-group.c index 808144a..41d5de7 100755 --- a/src/cts-group.c +++ b/src/cts-group.c @@ -266,7 +266,6 @@ int cts_group_set_relation(int group_id, int contact_id, int contact_acc) cts_stmt stmt = NULL; char query[CTS_SQL_MIN_LEN]; -#ifdef CTS_CHECK_SAME_ADDRESSBOOK snprintf(query, sizeof(query), "SELECT addrbook_id FROM %s WHERE group_id = %d", CTS_TABLE_GROUPS, group_id); @@ -277,11 +276,10 @@ int cts_group_set_relation(int group_id, int contact_id, int contact_acc) retvm_if(contact_acc != grp_acc, CTS_ERR_ARG_INVALID, "addrbook_id(%d) of the contact and addrbook_id(%d) of the group is not same", contact_acc, grp_acc); -#endif + snprintf(query, sizeof(query), "INSERT OR IGNORE INTO %s VALUES(%d, %d)", CTS_TABLE_GROUPING_INFO, group_id, contact_id); - stmt = cts_query_prepare(query); retvm_if(NULL == stmt, CTS_ERR_DB_FAILED, "cts_query_prepare() Failed"); @@ -296,20 +294,15 @@ int cts_group_set_relation(int group_id, int contact_id, int contact_acc) API int contacts_svc_group_set_relation(int group_id, int contact_id) { int ret, ct_acc=0; - -#ifndef CTS_CHECK_SAME_ADDRESSBOOK - retvm_if(!group_id, CTS_ERR_ARG_INVALID, "group_id is 0"); - retvm_if(!contact_id, CTS_ERR_ARG_INVALID, "contact_id is 0"); -#else char query[CTS_SQL_MIN_LEN]; snprintf(query, sizeof(query), - "SELECT addrbook_id FROM %s WHERE contact_id = %d", + "SELECT addrbook_id FROM %s WHERE contact_id = %d LIMIT 1", CTS_TABLE_CONTACTS, contact_id); ct_acc = cts_query_get_first_int_result(query); retvm_if(CTS_ERR_DB_RECORD_NOT_FOUND == ct_acc, CTS_ERR_ARG_INVALID, "contact_id(%d) is Invalid", contact_id); -#endif + ret = contacts_svc_begin_trans(); retvm_if(ret, ret, "contacts_svc_begin_trans() Failed(%d)", ret); diff --git a/src/cts-list-info.c b/src/cts-list-info.c index 96e23b9..c9e0204 100755 --- a/src/cts-list-info.c +++ b/src/cts-list-info.c @@ -43,7 +43,11 @@ static inline CTSvalue* cts_iter_get_info_contact(cts_stmt stmt, int type) result->display = SAFE_STRDUP(temp); result->acc_id = cts_stmt_get_int(stmt, i++); temp = cts_stmt_get_text(stmt, i++); - result->img_path = SAFE_STRDUP(temp); + if (temp) { + char full_path[CTS_IMG_PATH_SIZE_MAX]; + snprintf(full_path, sizeof(full_path), "%s/%s", CTS_IMAGE_LOCATION, temp); + result->img_path = strdup(full_path); + } if (CTS_LANG_DEFAULT == lang) lang = cts_get_default_language(); @@ -93,7 +97,12 @@ static inline CTSvalue* cts_iter_get_info_number_email(cts_stmt stmt, int type) temp = cts_stmt_get_text(stmt, i++); result->connect = SAFE_STRDUP(temp); temp = cts_stmt_get_text(stmt, i++); - result->img_path = SAFE_STRDUP(temp); + if (temp) { + char full_path[CTS_IMG_PATH_SIZE_MAX]; + snprintf(full_path, sizeof(full_path), "%s/%s", CTS_IMAGE_LOCATION, temp); + result->img_path = strdup(full_path); + } + if (CTS_ITER_NUMBERS_EMAILS == type) { result->acc_id = cts_stmt_get_int(stmt, i++); temp = cts_stmt_get_text(stmt, i++); @@ -168,7 +177,11 @@ static inline CTSvalue* cts_iter_get_info_plog(int type, cts_stmt stmt) temp = cts_stmt_get_text(stmt, cnt++); result->display = SAFE_STRDUP(temp); temp = cts_stmt_get_text(stmt, cnt++); - result->img_path = SAFE_STRDUP(temp); + if (temp) { + char full_path[CTS_IMG_PATH_SIZE_MAX]; + snprintf(full_path, sizeof(full_path), "%s/%s", CTS_IMAGE_LOCATION, temp); + result->img_path = strdup(full_path); + } if (CTS_LANG_DEFAULT == lang) lang = cts_get_default_language(); @@ -268,7 +281,11 @@ static inline CTSvalue* cts_iter_get_info_shortcut(int type, cts_stmt stmt) temp = cts_stmt_get_text(stmt, i++); result->display = SAFE_STRDUP(temp); temp = cts_stmt_get_text(stmt, i++); - result->img_path = SAFE_STRDUP(temp); + if (temp) { + char full_path[CTS_IMG_PATH_SIZE_MAX]; + snprintf(full_path, sizeof(full_path), "%s/%s", CTS_IMAGE_LOCATION, temp); + result->img_path = strdup(full_path); + } result->id = cts_stmt_get_int(stmt, i++); if (CTS_LANG_DEFAULT == lang) lang = cts_get_default_language(); diff --git a/src/cts-list.c b/src/cts-list.c index cb289b0..31aa8b1 100755 --- a/src/cts-list.c +++ b/src/cts-list.c @@ -117,8 +117,8 @@ API int contacts_svc_iter_remove(CTSiter *iter) static inline int cts_get_list(cts_get_list_op op_code, CTSiter *iter) { cts_stmt stmt = NULL; - char query[CTS_SQL_MAX_LEN] = {0}; const char *display; + char query[CTS_SQL_MAX_LEN] = {0}; retv_if(NULL == iter, CTS_ERR_ARG_NULL); @@ -482,8 +482,8 @@ static inline int cts_get_list_with_str(cts_get_list_str_op op_code, { int ret; cts_stmt stmt = NULL; - char query[CTS_SQL_MAX_LEN] = {0}; const char *display; + char query[CTS_SQL_MAX_LEN] = {0}; char remake_val[CTS_SQL_MIN_LEN]; CTS_START_TIME_CHECK; @@ -661,8 +661,8 @@ static inline int cts_get_list_with_int(cts_get_list_int_op op_code, unsigned int search_value, CTSiter *iter) { cts_stmt stmt = NULL; - char query[CTS_SQL_MAX_LEN] = {0}; const char *display; + char query[CTS_SQL_MAX_LEN] = {0}; retv_if(NULL == iter, CTS_ERR_ARG_NULL); iter->i_type = CTS_ITER_NONE; @@ -1319,6 +1319,7 @@ API int contacts_svc_list_with_filter_foreach(CTSfilter *filter, return CTS_SUCCESS; } +// same with check_dirty_number() static inline bool cts_is_number(const char *str) { int i; @@ -1330,6 +1331,10 @@ static inline bool cts_is_number(const char *str) case '0' ... '9': case 'p': case 'w': + case 'P': + case 'W': + case '#': + case '*': case '+': break; default: @@ -1339,6 +1344,29 @@ static inline bool cts_is_number(const char *str) return true; } +static inline int cts_escape_like_patten(const char *src, char *dest, int dest_size) +{ + int s_pos=0, d_pos=0; + + if (NULL == src) { + ERR("The parameter(src) is NULL"); + dest[d_pos] = '\0'; + return 0; + } + + while (src[s_pos] != 0) { + if (dest_size == d_pos - 1) + break; + if ('%' == src[s_pos] || '_' == src[s_pos]) { + dest[d_pos++] = '\\'; + } + dest[d_pos++] = src[s_pos++]; + } + + dest[d_pos] = '\0'; + return d_pos; +} + API int contacts_svc_smartsearch_excl(const char *search_str, int limit, int offset, cts_foreach_fn cb, void *user_data) { @@ -1347,7 +1375,7 @@ API int contacts_svc_smartsearch_excl(const char *search_str, int limit, int off const char *display; cts_stmt stmt = NULL; char query[CTS_SQL_MAX_LEN]; - char remake_name[CTS_SQL_MIN_LEN]; + char remake_name[CTS_SQL_MIN_LEN], escape_name[CTS_SQL_MIN_LEN]; retv_if(NULL == search_str, CTS_ERR_ARG_NULL); retvm_if(CTS_SQL_MIN_LEN <= strlen(search_str), CTS_ERR_ARG_INVALID, @@ -1362,26 +1390,25 @@ API int contacts_svc_smartsearch_excl(const char *search_str, int limit, int off if (cts_is_number(search_str)) { len = snprintf(query, sizeof(query), - "SELECT A.contact_id, A.data1, A.data2, A.data3, A.data5, B.data2, C.image0 " - "FROM %s A, %s B, %s C " - "ON A.contact_id = B.contact_id AND A.contact_id = C.contact_id " - "WHERE A.datatype = %d AND B.datatype = %d " - "AND (B.data2 LIKE '%%%s%%' OR A.%s LIKE ('%%' || ? || '%%')) " + "SELECT A.contact_id, A.data1, A.data2, A.data3, A.data5, C.data2, B.image0 " + "FROM (%s A, %s B ON A.contact_id = B.contact_id AND A.datatype = %d) " + "LEFT JOIN %s C ON B.contact_id = C.contact_id AND C.datatype = %d " + "WHERE C.data2 LIKE '%%%s%%' OR A.%s LIKE ('%%' || ? || '%%') " "ORDER BY A.data1, A.%s", - CTS_TABLE_DATA, CTS_TABLE_DATA, CTS_TABLE_CONTACTS, - CTS_DATA_NAME, CTS_DATA_NUMBER, + CTS_TABLE_DATA, CTS_TABLE_CONTACTS, CTS_DATA_NAME, + CTS_TABLE_DATA, CTS_DATA_NUMBER, search_str, display, CTS_SCHEMA_DATA_NAME_SORTING_KEY); } else { len = snprintf(query, sizeof(query), - "SELECT A.contact_id, A.data1, A.data2, A.data3, A.data5, D.data2, D.image0 " - "FROM %s A " - "LEFT JOIN (%s B, %s C ON B.default_num = C.id AND C.datatype = %d ) D " - "ON A.contact_id = D.contact_id " - "WHERE A.datatype = %d AND A.%s LIKE ('%%' || ? || '%%') " + "SELECT A.contact_id, A.data1, A.data2, A.data3, A.data5, C.data2, B.image0 " + "FROM (%s A, %s B ON A.contact_id = B.contact_id AND A.datatype = %d) " + "LEFT JOIN %s C ON B.default_num = C.id AND C.datatype = %d " + "WHERE A.%s LIKE ('%%' || ? || '%%') ESCAPE '\\' " "ORDER BY A.data1, A.%s", - CTS_TABLE_DATA, CTS_TABLE_CONTACTS, CTS_TABLE_DATA, - CTS_DATA_NUMBER, CTS_DATA_NAME, display, CTS_SCHEMA_DATA_NAME_SORTING_KEY); + CTS_TABLE_DATA, CTS_TABLE_CONTACTS, CTS_DATA_NAME, + CTS_TABLE_DATA, CTS_DATA_NUMBER, + display, CTS_SCHEMA_DATA_NAME_SORTING_KEY); } if (limit) @@ -1393,7 +1420,8 @@ API int contacts_svc_smartsearch_excl(const char *search_str, int limit, int off stmt = cts_query_prepare(query); retvm_if(NULL == stmt, CTS_ERR_DB_FAILED, "cts_query_prepare() Failed"); - cts_stmt_bind_copy_text(stmt, 1, remake_name, strlen(remake_name)); + cts_escape_like_patten(remake_name, escape_name, sizeof(escape_name)); + cts_stmt_bind_copy_text(stmt, 1, escape_name, strlen(escape_name)); iter.stmt = stmt; cts_foreach_run(&iter, cb, user_data); diff --git a/src/cts-list.h b/src/cts-list.h index 93a3356..a46356d 100755 --- a/src/cts-list.h +++ b/src/cts-list.h @@ -126,15 +126,17 @@ enum PHONELOGLIST{ CTS_LIST_PLOG_NUMBER_STR,/**< . */ CTS_LIST_PLOG_IMG_PATH_STR,/**< . */ CTS_LIST_PLOG_LOG_TIME_INT,/**< The time since the Epoch (00:00:00 UTC, January 1, 1970), measured in seconds. */ - CTS_LIST_PLOG_LOG_TYPE_INT,/**< . */ + CTS_LIST_PLOG_LOG_TYPE_INT,/**< #PLOGTYPE */ CTS_LIST_PLOG_DURATION_INT,/**< seconds */ CTS_LIST_PLOG_MSGID_INT,/**< . */ CTS_LIST_PLOG_SHORTMSG_STR,/**< . */ CTS_LIST_PLOG_RELATED_ID_INT/**< contact id */ }; + /** * Contact List + * Usually, This is sorted by name related with #CTS_ORDER_OF_SORTING */ enum CONTACTLIST{ CTS_LIST_CONTACT_ID_INT,/**< . */ @@ -189,6 +191,7 @@ enum { /** * Addressbook List + * Usually, This is sorted by acc_id and addressbook id * Though it is same with ADDRESSBOOKVALUE, Use this for list */ enum ADDRESSBOOKLIST{ @@ -210,6 +213,7 @@ enum CUSTOMNUMTYPELIST{ /** * Group List + * Usually, This is sorted by addressbook_id and name. */ enum GROUPLIST{ CTS_LIST_GROUP_ID_INT,/**< . */ @@ -247,7 +251,7 @@ enum SDNLIST{ typedef enum{ CTS_LIST_ALL_CONTACT, /**< #CONTACTLIST */ CTS_LIST_ALL_GROUP,/**< #GROUPLIST */ - CTS_LIST_ALL_CUSTOM_NUM_TYPE,/**< #GROUPLIST */ + CTS_LIST_ALL_CUSTOM_NUM_TYPE,/**< #CUSTOMNUMTYPELIST */ CTS_LIST_ALL_CONTACT_FAVORITE,/**< #SHORTCUTLIST */ CTS_LIST_ALL_SPEEDDIAL,/**< #SHORTCUTLIST */ CTS_LIST_GROUPING_PLOG,/**< #PHONELOGLIST */ @@ -258,7 +262,7 @@ typedef enum{ CTS_LIST_ALL_CONTACT_HAD_EMAIL,/**< #CONTACTLIST */ CTS_LIST_ALL_EMAIL_NUMBER,/**< #CONTACTLIST */ CTS_LIST_ALL_NUMBER_FAVORITE,/**< #SHORTCUTLIST */ - CTS_LIST_OFTEN_USED_CONTACT, /**< #CONTACTLIST */ + CTS_LIST_OFTEN_USED_CONTACT, /**< #CONTACTLIST. sorted by count of using(using means outgoing call/video call)*/ CTS_LIST_ALL_ADDRESSBOOK, /**< #ADDRESSBOOKLIST */ CTS_LIST_ALL_PLOG, /**< #PHONELOGLIST */ CTS_LIST_ALL_MISSED_CALL, /**< #PHONELOGLIST */ @@ -588,7 +592,7 @@ int contacts_svc_list_with_filter_foreach(CTSfilter *filter, cts_foreach_fn cb, void *user_data); /** - * It is the smartsearch exclusive function. It is supported for only smartsearch. + * It is the smartsearch exclusive function. It is supported for only smartsearch(inhouse application). * It can be changed without announcement. * This function calls #cts_foreach_fn for each record of list. * diff --git a/src/cts-normalize.c b/src/cts-normalize.c index cd003ef..aa8a52c 100755 --- a/src/cts-normalize.c +++ b/src/cts-normalize.c @@ -31,7 +31,7 @@ static int (*extra_normalize_fn)(char dest[][CTS_SQL_MAX_LEN]); static inline int check_utf8(char c) { - if (c < 128) + if ((c & 0xff) < (128 & 0xff)) return 1; else if ((c & (char)0xe0) == (char)0xc0) return 2; @@ -56,6 +56,8 @@ static inline bool check_dirty_number(char digit) case 'w': case 'P': case 'W': + case '#': + case '*': return false; case '+': //only first position default: diff --git a/src/cts-phonelog.c b/src/cts-phonelog.c index 003c1ef..de0673d 100755 --- a/src/cts-phonelog.c +++ b/src/cts-phonelog.c @@ -351,12 +351,12 @@ API int contacts_svc_phonelog_set_seen(int index, int type) } /** - * This is the signature of a callback function added with contats_svc_phonelog_get_all_number(), + * This is the signature of a callback function added with contacts_svc_phonelog_get_all_number(), * \n This function is invoked in the above functions. * \n If this function doesn't return #CTS_SUCCESS, foreach function is terminated. * * @param[in] number number. - * @param[in] user_data The data which is set by contats_svc_phonelog_get_all_number(), + * @param[in] user_data The data which is set by contacts_svc_phonelog_get_all_number(), * @return #CTS_SUCCESS on success, other value on error */ typedef int (*cts_plog_foreach_fn)(const char *number, void *user_data); @@ -369,7 +369,7 @@ typedef int (*cts_plog_foreach_fn)(const char *number, void *user_data); * @param[in] user_data data which is passed to callback function * @return #CTS_SUCCESS on success, Negative value(#cts_error) on error */ -API int contats_svc_phonelog_get_all_number(cts_plog_foreach_fn cb, +API int contacts_svc_phonelog_get_all_number(cts_plog_foreach_fn cb, void *user_data) { cts_stmt stmt = NULL; diff --git a/src/cts-pthread.c b/src/cts-pthread.c index 14a073c..4111afd 100755 --- a/src/cts-pthread.c +++ b/src/cts-pthread.c @@ -36,6 +36,8 @@ static cts_thread_fns cts_thread_funtions = static pthread_mutex_t conn_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t sockfd_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t trans_mutex = PTHREAD_MUTEX_INITIALIZER; + static inline pthread_mutex_t* cts_pthread_get_mutex(int type) { @@ -48,6 +50,9 @@ static inline pthread_mutex_t* cts_pthread_get_mutex(int type) case CTS_MUTEX_SOCKET_FD: ret_val = &sockfd_mutex; break; + case CTS_MUTEX_TRANSACTION: + ret_val = &trans_mutex; + break; default: ERR("unknown type(%d)", type); ret_val = NULL; diff --git a/src/cts-pthread.h b/src/cts-pthread.h index 16a5132..f7eb0e5 100755 --- a/src/cts-pthread.h +++ b/src/cts-pthread.h @@ -25,6 +25,7 @@ enum { CTS_MUTEX_CONNECTION, CTS_MUTEX_UPDTATED_LIST_MEMPOOL, CTS_MUTEX_SOCKET_FD, + CTS_MUTEX_TRANSACTION, }; void cts_mutex_lock(int type); diff --git a/src/cts-service.c b/src/cts-service.c index 280716c..ae664a4 100755 --- a/src/cts-service.c +++ b/src/cts-service.c @@ -25,11 +25,11 @@ #include "cts-schema.h" #include "cts-sqlite.h" #include "cts-utils.h" -#include "cts-service.h" #include "cts-socket.h" #include "cts-normalize.h" #include "cts-list.h" #include "cts-pthread.h" +#include "cts-service.h" static int cts_conn_refcnt = 0; diff --git a/src/cts-service.h b/src/cts-service.h index 3c358e8..c2dc31d 100755 --- a/src/cts-service.h +++ b/src/cts-service.h @@ -26,7 +26,8 @@ * This function connect to contacts service. * \n Though the connection already exists, #CTS_SUCCESS is returned. * \n It has to disconnect as it connect. - * for example, if you connect 3 times you have to disconnect 3times. + * + * for example, if you connect 3 times you have to disconnect 3 times. * \n To disconnect early minimizes the runtime resource consumption. * On the other hand, a pair of connection and disconnection is expensive. * Don't call frequently. diff --git a/src/cts-sqlite.c b/src/cts-sqlite.c index 48eebbd..e5b0443 100755 --- a/src/cts-sqlite.c +++ b/src/cts-sqlite.c @@ -107,7 +107,7 @@ int cts_query_get_first_int_result(const char *query) return ret; } -int cts_query_exec(char *query) +int cts_query_exec(const char *query) { int ret; char *err_msg = NULL; @@ -252,10 +252,18 @@ int cts_stmt_bind_event(cts_stmt stmt, int start_cnt, cts_event *event_struct) int cts_stmt_bind_messenger(cts_stmt stmt, int start_cnt, cts_messenger *im_struct) { - sqlite3_bind_int(stmt, start_cnt++, im_struct->type); + sqlite3_bind_int(stmt, start_cnt, im_struct->type); if (im_struct->im_id) - sqlite3_bind_text(stmt, start_cnt++, im_struct->im_id, + sqlite3_bind_text(stmt, start_cnt+1, im_struct->im_id, strlen(im_struct->im_id), SQLITE_STATIC); + if (0 == im_struct->type) { + if (im_struct->svc_name) + sqlite3_bind_text(stmt, start_cnt+2, im_struct->svc_name, + strlen(im_struct->svc_name), SQLITE_STATIC); + if (im_struct->svc_op) + sqlite3_bind_text(stmt, start_cnt+3, im_struct->svc_op, + strlen(im_struct->svc_op), SQLITE_STATIC); + } return CTS_SUCCESS; } diff --git a/src/cts-sqlite.h b/src/cts-sqlite.h index 044a3d4..4a2f708 100755 --- a/src/cts-sqlite.h +++ b/src/cts-sqlite.h @@ -29,8 +29,6 @@ typedef sqlite3_stmt* cts_stmt; -//////////////////// iterator //////////////////// - int cts_db_open(void); int cts_db_close(void); int cts_db_change(); @@ -38,7 +36,7 @@ int cts_db_get_last_insert_id(void); int cts_db_get_next_id(const char *table); int cts_query_get_first_int_result(const char *query); -int cts_query_exec(char *query); +int cts_query_exec(const char *query); cts_stmt cts_query_prepare(char *query); int cts_stmt_step(cts_stmt stmt); diff --git a/src/cts-struct-ext.c b/src/cts-struct-ext.c index 79032cb..094e6bc 100755 --- a/src/cts-struct-ext.c +++ b/src/cts-struct-ext.c @@ -574,6 +574,10 @@ static inline cts_messenger* cts_struct_dup_messenger(const cts_messenger *src) if (src->im_id) result->im_id = strdup(src->im_id); + if (src->svc_name) + result->svc_name = strdup(src->svc_name); + if (src->svc_op) + result->svc_op = strdup(src->svc_op); } return result; diff --git a/src/cts-struct.c b/src/cts-struct.c index e701f2c..ff3140b 100755 --- a/src/cts-struct.c +++ b/src/cts-struct.c @@ -87,10 +87,14 @@ static void cts_event_free(gpointer data, gpointer user_data) } static void cts_messenger_free(gpointer data, gpointer user_data) { - if (NULL == data || !((cts_messenger*)data)->embedded) + cts_messenger *data0 = (cts_messenger *)data; + + if (NULL == data0 || !data0->embedded) return; - free(((cts_messenger*)data)->im_id); + free(data0->im_id); + free(data0->svc_name); + free(data0->svc_op); free(data); } static void cts_postal_free(gpointer data, gpointer user_data) @@ -609,10 +613,11 @@ static inline int cts_struct_store_messenger_list(contact_t *contact, GSList* li continue; } - if (!tmp_messenger->embedded) - { + if (!tmp_messenger->embedded) { tmp_messenger->embedded = true; tmp_messenger->im_id = SAFE_STRDUP(tmp_messenger->im_id); + tmp_messenger->svc_name = SAFE_STRDUP(tmp_messenger->svc_name); + tmp_messenger->svc_op = SAFE_STRDUP(tmp_messenger->svc_op); } } prev = tmp_gslist; @@ -632,6 +637,8 @@ static inline int cts_struct_store_messenger_list(contact_t *contact, GSList* li { tmp_messenger->embedded = true; tmp_messenger->im_id = SAFE_STRDUP(tmp_messenger->im_id); + tmp_messenger->svc_name = SAFE_STRDUP(tmp_messenger->svc_name); + tmp_messenger->svc_op = SAFE_STRDUP(tmp_messenger->svc_op); new_gslist = g_slist_append(new_gslist, tmp_messenger); } } @@ -1532,9 +1539,12 @@ API int contacts_svc_value_get_int(CTSvalue *value, int field) break; case CTS_VALUE_RDONLY_EMAIL: case CTS_VALUE_EMAIL: - retvm_if(CTS_EMAIL_VAL_TYPE_INT != field, 0, - "The field(%d) is not supported in value(Email)", field); - ret = ((cts_email*)value)->type; + if (CTS_EMAIL_VAL_ID_INT == field) + ret = ((cts_email*)value)->id; + else if (CTS_EMAIL_VAL_TYPE_INT == field) + ret = ((cts_email*)value)->type; + else + ERR("The field(%d) is not supported in value(Email)", field); break; case CTS_VALUE_LIST_PLOG: ret = cts_value_get_int_plog_list((plog_list *)value, field); @@ -1561,6 +1571,12 @@ API int contacts_svc_value_get_int(CTSvalue *value, int field) "The field(%d) is not supported in value(Number list)", field); ret = ((contact_list*)value)->id; break; + case CTS_VALUE_LIST_CUSTOM_NUM_TYPE: + if (CTS_LIST_CUSTOM_NUM_TYPE_ID_INT == field) + ret = ((numtype_list*)value)->id; + else + ERR("Not supported field(%d)", field); + break; case CTS_VALUE_LIST_GROUP: if (CTS_LIST_GROUP_ID_INT == field) ret = ((cts_group *)value)->id; @@ -1928,7 +1944,7 @@ static inline char* cts_value_get_str_contact_list(int op_code, } static inline char* cts_value_get_str_num_email_list(int op_code, - contact_list *value, int field, int type) + contact_list *value, int field) { char *ret_val; switch (field) @@ -2081,6 +2097,30 @@ static inline char* cts_value_get_str_company(int op_code, return ret_val; } + +static inline char* cts_value_get_str_im(int op_code, + cts_messenger *value, int field) +{ + char *ret_val; + switch (field) + { + case CTS_MESSENGER_VAL_IM_ID_STR: + HANDLE_STEAL_STRING(op_code, ret_val, value->im_id); + break; + case CTS_MESSENGER_VAL_SERVICE_NAME_STR: + HANDLE_STEAL_STRING(op_code, ret_val, value->svc_name); + break; + case CTS_MESSENGER_VAL_SERVICE_OP_STR: + HANDLE_STEAL_STRING(op_code, ret_val, value->svc_op); + break; + default: + ERR("The parameter(field:%d) is not interpreted", field); + ret_val = NULL; + break; + } + return ret_val; +} + static char* cts_value_handle_str(int op_code, CTSvalue *value, int field) { char *ret_val; @@ -2116,7 +2156,7 @@ static char* cts_value_handle_str(int op_code, CTSvalue *value, int field) break; case CTS_VALUE_LIST_NUMBERINFO: case CTS_VALUE_LIST_EMAILINFO: - ret_val = cts_value_get_str_num_email_list(op_code, (contact_list *)value, field, value->v_type); + ret_val = cts_value_get_str_num_email_list(op_code, (contact_list *)value, field); break; case CTS_VALUE_LIST_SHORTCUT: ret_val = cts_value_get_str_favorite_list(op_code, (shortcut_list *)value, field); @@ -2124,6 +2164,9 @@ static char* cts_value_handle_str(int op_code, CTSvalue *value, int field) case CTS_VALUE_LIST_PLOG: ret_val = cts_value_get_str_plog_list(op_code, (plog_list *)value, field); break; + case CTS_VALUE_MESSENGER: + ret_val = cts_value_get_str_im(op_code, (cts_messenger *)value, field); + break; case CTS_VALUE_RDONLY_PLOG: if (CTS_PLOG_VAL_NUMBER_STR == field) { HANDLE_STEAL_STRING(op_code, ret_val, ((cts_plog *)value)->number); @@ -2164,15 +2207,6 @@ static char* cts_value_handle_str(int op_code, CTSvalue *value, int field) ret_val = NULL; } break; - case CTS_VALUE_MESSENGER: - if (CTS_MESSENGER_VAL_IM_ID_STR == field) { - HANDLE_STEAL_STRING(op_code, ret_val, ((cts_messenger *)value)->im_id); - } - else { - ERR("Not supported field(%d)", field); - ret_val = NULL; - } - break; case CTS_VALUE_WEB: if (CTS_WEB_VAL_ADDR_STR == field) { HANDLE_STEAL_STRING(op_code, ret_val, ((cts_web *)value)->url); @@ -2212,6 +2246,14 @@ static char* cts_value_handle_str(int op_code, CTSvalue *value, int field) ret_val = NULL; } break; + case CTS_VALUE_LIST_CUSTOM_NUM_TYPE: + if (CTS_LIST_CUSTOM_NUM_TYPE_NAME_STR == field) { + HANDLE_STEAL_STRING(op_code, ret_val, ((numtype_list *)value)->name); + } else { + ERR("Not supported field(%d)", field); + ret_val = NULL; + } + break; case CTS_VALUE_LIST_SDN: if (CTS_LIST_SDN_NAME_STR == field) { HANDLE_STEAL_STRING(op_code, ret_val, ((sdn_list *)value)->name); @@ -2514,7 +2556,7 @@ API int contacts_svc_value_set_bool(CTSvalue *value, return CTS_SUCCESS; } -static inline int cts_base_set_str(cts_ct_base *base, int field, char *strval) +static inline int cts_value_set_str_base(cts_ct_base *base, int field, char *strval) { switch (field) { @@ -2560,7 +2602,7 @@ static inline int cts_base_set_str(cts_ct_base *base, int field, char *strval) return CTS_SUCCESS; } -static inline int cts_name_set_str(cts_name *name, int field, char *strval) +static inline int cts_value_set_str_name(cts_name *name, int field, char *strval) { switch (field) { @@ -2614,7 +2656,7 @@ static inline int cts_name_set_str(cts_name *name, int field, char *strval) return CTS_SUCCESS; } -static inline int cts_postal_set_str(cts_postal *postal, int field, char *strval) +static inline int cts_value_set_str_postal(cts_postal *postal, int field, char *strval) { switch (field) { @@ -2674,7 +2716,7 @@ static inline int cts_postal_set_str(cts_postal *postal, int field, char *strval return CTS_SUCCESS; } -static inline int cts_company_set_str( +static inline int cts_value_set_str_company( cts_company *com, int field, char *strval) { switch (field) @@ -2721,7 +2763,7 @@ static inline int cts_company_set_str( return CTS_SUCCESS; } -static inline int cts_group_set_str( +static inline int cts_value_set_str_group( cts_group *group, int field, char *strval) { switch (field) @@ -2747,7 +2789,7 @@ static inline int cts_group_set_str( return CTS_SUCCESS; } -static inline int cts_extend_set_str(cts_extend *extend, int field, char *strval) +static inline int cts_value_set_str_extend(cts_extend *extend, int field, char *strval) { switch (field) { @@ -2822,6 +2864,37 @@ static inline int cts_extend_set_str(cts_extend *extend, int field, char *strval return CTS_SUCCESS; } + +static inline int cts_value_set_str_im(cts_messenger *im, int field, char *strval) +{ + switch (field) + { + case CTS_MESSENGER_VAL_IM_ID_STR: + if (im->embedded) + FREEandSTRDUP(im->im_id, strval); + else + im->im_id = strval; + break; + case CTS_MESSENGER_VAL_SERVICE_NAME_STR: + if (im->embedded) + FREEandSTRDUP(im->svc_name, strval); + else + im->svc_name = strval; + break; + case CTS_MESSENGER_VAL_SERVICE_OP_STR: + if (im->embedded) + FREEandSTRDUP(im->svc_op, strval); + else + im->svc_op = strval; + break; + default: + ERR("Not supported field"); + return CTS_ERR_ARG_INVALID; + } + return CTS_SUCCESS; +} + + API int contacts_svc_value_set_str(CTSvalue *value, int field, const char *strval) { char *str; @@ -2843,17 +2916,19 @@ API int contacts_svc_value_set_str(CTSvalue *value, int field, const char *strva ((cts_basic*)value)->val.s = str; break; case CTS_VALUE_CONTACT_BASE_INFO: - return cts_base_set_str((cts_ct_base *)value, field, str); + return cts_value_set_str_base((cts_ct_base *)value, field, str); case CTS_VALUE_NAME: - return cts_name_set_str((cts_name *)value, field, str); + return cts_value_set_str_name((cts_name *)value, field, str); case CTS_VALUE_POSTAL: - return cts_postal_set_str((cts_postal *)value, field, str); + return cts_value_set_str_postal((cts_postal *)value, field, str); case CTS_VALUE_COMPANY: - return cts_company_set_str((cts_company *)value, field, str); + return cts_value_set_str_company((cts_company *)value, field, str); case CTS_VALUE_GROUP: - return cts_group_set_str((cts_group *)value, field, str); + return cts_value_set_str_group((cts_group *)value, field, str); case CTS_VALUE_EXTEND: - return cts_extend_set_str((cts_extend *)value, field, str); + return cts_value_set_str_extend((cts_extend *)value, field, str); + case CTS_VALUE_MESSENGER: + return cts_value_set_str_im((cts_messenger *)value, field, str); case CTS_VALUE_NUMBER: retvm_if(CTS_NUM_VAL_NUMBER_STR != field, CTS_ERR_ARG_INVALID, "Not supported field"); @@ -2887,13 +2962,6 @@ API int contacts_svc_value_set_str(CTSvalue *value, int field, const char *strva return CTS_ERR_ARG_INVALID; } break; - case CTS_VALUE_MESSENGER: - retvm_if(CTS_MESSENGER_VAL_IM_ID_STR != field, CTS_ERR_ARG_INVALID, "Not supported field"); - if (value->embedded) - FREEandSTRDUP(((cts_messenger *)value)->im_id, str); - else - ((cts_messenger *)value)->im_id = str; - break; case CTS_VALUE_WEB: retvm_if(CTS_WEB_VAL_ADDR_STR != field, CTS_ERR_ARG_INVALID, "Not supported field"); if (value->embedded) diff --git a/src/cts-struct.h b/src/cts-struct.h index bd5b1db..d39b6a8 100755 --- a/src/cts-struct.h +++ b/src/cts-struct.h @@ -185,6 +185,8 @@ typedef struct { int id; int type; char *im_id; + char *svc_name; + char *svc_op; }cts_messenger;//CTS_MESSENGER_VAL_ typedef struct { @@ -205,7 +207,7 @@ typedef struct { char *ringtone_path; char *vcard_group; // char *image_path; -}cts_group; //CTS_GROUP_VAL_ or CTS_GROUPREL_VAL_ +}cts_group; //CTS_GROUP_VAL_ or CTS_GROUPREL_VAL_ typedef struct { int v_type:16; @@ -554,6 +556,8 @@ enum MESSENGERVALUE { CTS_MESSENGER_VAL_TYPE_INT,/**< #cts_im_type */ CTS_MESSENGER_VAL_DELETE_BOOL,/**< request to delete in the list of #CTSstruct. */ CTS_MESSENGER_VAL_IM_ID_STR,/**< .*/ + CTS_MESSENGER_VAL_SERVICE_NAME_STR,/**< The name of unknown service. So, this is valid in CTS_IM_TYPE_NONE. */ + CTS_MESSENGER_VAL_SERVICE_OP_STR,/**< The service operation related to launch unknown application. So, this is valid in CTS_IM_TYPE_NONE. */ }; /** @@ -776,6 +780,7 @@ int contacts_svc_value_set_bool(CTSvalue* value, int field, bool boolval); * May only be used with fields of type string (_STR suffix in enum). * \n If it is in struct, free old string and copy strval to struct.(call by value) * \n empty string is handled as NULL and thus will result in NULL being stored + * * @param[in] value The contacts service value * @param[in] field The index of the string field in the contacts service value. * @param[in] strval The string value to be set. diff --git a/src/cts-types.h b/src/cts-types.h index 6e81b8f..9e50cf7 100755 --- a/src/cts-types.h +++ b/src/cts-types.h @@ -173,7 +173,7 @@ int contacts_svc_find_custom_type(cts_custom_type_class type_class, char *type_n /** * @defgroup CONTACTS_SVC_EXTEND Using the Extend Data for Contact - * @ingroup CONTACTS_SVC_STRUCT + * @ingroup CONTACTS_SVC * @addtogroup CONTACTS_SVC_EXTEND * @{ * diff --git a/src/cts-utils.c b/src/cts-utils.c index 8bec57c..9504310 100755 --- a/src/cts-utils.c +++ b/src/cts-utils.c @@ -19,6 +19,7 @@ * */ #include <sys/time.h> +#include <sys/stat.h> #include <vconf.h> #include <unistd.h> #include <fcntl.h> @@ -26,7 +27,6 @@ #include <dirent.h> #include "cts-internal.h" -#include "cts-utils.h" #include "cts-schema.h" #include "cts-sqlite.h" #include "cts-socket.h" @@ -35,6 +35,7 @@ #include "cts-vcard.h" #include "cts-pthread.h" #include "cts-types.h" +#include "cts-utils.h" static const char *CTS_NOTI_CONTACT_CHANGED=CTS_NOTI_CONTACT_CHANGED_DEF; static const char *CTS_NOTI_PLOG_CHANGED="/opt/data/contacts-svc/.CONTACTS_SVC_PLOG_CHANGED"; @@ -196,6 +197,7 @@ API int contacts_svc_begin_trans(void) { int ret = -1, progress; + cts_mutex_lock(CTS_MUTEX_TRANSACTION); if (transaction_count <= 0) { ret = cts_query_exec("BEGIN IMMEDIATE TRANSACTION"); //taken 600ms @@ -205,7 +207,11 @@ API int contacts_svc_begin_trans(void) ret = cts_query_exec("BEGIN IMMEDIATE TRANSACTION"); progress *= 2; } - retvm_if(CTS_SUCCESS != ret, ret, "cts_query_exec() Failed(%d)", ret); + if(CTS_SUCCESS != ret) { + ERR("cts_query_exec() Failed(%d)", ret); + cts_mutex_unlock(CTS_MUTEX_TRANSACTION); + return ret; + } transaction_count = 0; @@ -215,6 +221,7 @@ API int contacts_svc_begin_trans(void) } transaction_count++; CTS_DBG("transaction_count : %d.", transaction_count); + cts_mutex_unlock(CTS_MUTEX_TRANSACTION); return CTS_SUCCESS; } @@ -236,16 +243,20 @@ API int contacts_svc_end_trans(bool is_success) int ret = -1, progress; char query[CTS_SQL_MIN_LEN]; + cts_mutex_lock(CTS_MUTEX_TRANSACTION); + transaction_count--; if (0 != transaction_count) { CTS_DBG("contact transaction_count : %d.", transaction_count); + cts_mutex_unlock(CTS_MUTEX_TRANSACTION); return CTS_SUCCESS; } if (false == is_success) { cts_cancel_changes(); ret = cts_query_exec("ROLLBACK TRANSACTION"); + cts_mutex_unlock(CTS_MUTEX_TRANSACTION); return CTS_SUCCESS; } @@ -270,8 +281,11 @@ API int contacts_svc_end_trans(bool is_success) cts_cancel_changes(); tmp_ret = cts_query_exec("ROLLBACK TRANSACTION"); warn_if(CTS_SUCCESS != tmp_ret, "cts_query_exec(ROLLBACK) Failed(%d)", tmp_ret); + cts_mutex_unlock(CTS_MUTEX_TRANSACTION); return ret; } + cts_mutex_unlock(CTS_MUTEX_TRANSACTION); + if (contact_change) cts_noti_publish_contact_change(); if (plog_change) cts_noti_publish_plog_change(); if (missed_change) cts_noti_publish_missed_call_change(); @@ -499,7 +513,7 @@ API int contacts_svc_get_image(cts_img_t img_type, int index, char **img_path) { int ret; cts_stmt stmt; - char *tmp_path; + char *img; char query[CTS_SQL_MIN_LEN] = {0}; retvm_if(CTS_IMG_FULL != img_type && CTS_IMG_NORMAL != img_type, @@ -522,10 +536,12 @@ API int contacts_svc_get_image(cts_img_t img_type, int index, char **img_path) return CTS_ERR_DB_RECORD_NOT_FOUND; } - tmp_path = cts_stmt_get_text(stmt, 0); - if (tmp_path) { + img = cts_stmt_get_text(stmt, 0); + if (img) { + char tmp_path[CTS_IMG_PATH_SIZE_MAX]; + snprintf(tmp_path, sizeof(tmp_path), "%s/%s", CTS_IMAGE_LOCATION, img); ret = cts_exist_file(tmp_path); - retvm_if(ret, ret, "cts_exist_file() Failed(%d)", ret); + retvm_if(ret, ret, "cts_exist_file(%s) Failed(%d)", tmp_path, ret); *img_path = strdup(tmp_path); if (NULL == *img_path) { ERR("strdup() Failed"); @@ -562,14 +578,16 @@ int cts_delete_image_file(int img_type, int index) tmp_path = cts_stmt_get_text(stmt, 0); if (tmp_path) { - ret = unlink(tmp_path); - warn_if (ret < 0, "unlink(%s) Failed(%d)", tmp_path, errno); + char full_path[CTS_IMG_PATH_SIZE_MAX]; + snprintf(full_path, sizeof(full_path), "%s/%s", CTS_IMAGE_LOCATION, tmp_path); + ret = unlink(full_path); + warn_if (ret < 0, "unlink(%s) Failed(%d)", full_path, errno); } cts_stmt_finalize(stmt); return CTS_SUCCESS; } -int cts_add_image_file(int img_type, int index, char *src_img, char **dest_img) +int cts_add_image_file(int img_type, int index, char *src_img, char *dest_name, int dest_size) { int src_fd; int dest_fd; @@ -579,15 +597,15 @@ int cts_add_image_file(int img_type, int index, char *src_img, char **dest_img) char buf[CTS_COPY_SIZE_MAX]; char dest[CTS_IMG_PATH_SIZE_MAX]; - *dest_img = NULL; retvm_if(NULL == src_img, CTS_ERR_ARG_INVALID, "img_path is NULL"); ext = strrchr(src_img, '.'); - if (NULL == ext) ext = ""; + if (NULL == ext || strchr(ext, '/')) + ext = ""; size = snprintf(dest, sizeof(dest), "%s/%d-%d%s", CTS_IMAGE_LOCATION, index, img_type, ext); - retvm_if(size<=0, CTS_ERR_FAIL, "Destination file name was not created"); + retvm_if(size<=0, CTS_ERR_FAIL, "snprintf() Failed(%d)", errno); src_fd = open(src_img, O_RDONLY); retvm_if(src_fd < 0, CTS_ERR_IO_ERR, "Open(%s) Failed(%d)", src_img, errno); @@ -621,21 +639,20 @@ int cts_add_image_file(int img_type, int index, char *src_img, char **dest_img) fchmod(dest_fd, CTS_SECURITY_DEFAULT_PERMISSION); close(src_fd); close(dest_fd); - *dest_img = strdup(dest); + snprintf(dest_name, dest_size, "%d-%d%s", index, img_type, ext); return CTS_SUCCESS; } -int cts_update_image_file(int img_type, int index, char *src_img, char **dest_img) +int cts_update_image_file(int img_type, int index, char *src_img, char *dest_name, int dest_size) { int ret; - *dest_img = NULL; ret = cts_delete_image_file(img_type, index); retvm_if(CTS_SUCCESS != ret && CTS_ERR_DB_RECORD_NOT_FOUND != ret, ret, "cts_delete_image_file() Failed(%d)", ret); if (src_img) { - ret = cts_add_image_file(img_type, index, src_img, &(*dest_img)); + ret = cts_add_image_file(img_type, index, src_img, dest_name, dest_size); retvm_if(CTS_SUCCESS != ret, ret, "cts_add_image_file() Failed(%d)", ret); } @@ -662,14 +679,15 @@ int cts_update_contact_changed_time(int contact_id) API int contacts_svc_save_image(cts_img_t img_type, int index, char *src_img) { int ret; - char *dest_img; char query[CTS_SQL_MIN_LEN]; + char dest_img[CTS_SQL_MIN_LEN]; cts_stmt stmt; ret = contacts_svc_begin_trans(); retvm_if(ret, ret, "contacts_svc_begin_trans() Failed(%d)", ret); - ret = cts_update_image_file(img_type, index, src_img, &dest_img); + dest_img[0] = '\0'; + ret = cts_update_image_file(img_type, index, src_img, dest_img, sizeof(dest_img)); if (CTS_SUCCESS != ret) { ERR("cts_update_image_file() Failed(%d)", ret); contacts_svc_end_trans(false); @@ -686,7 +704,7 @@ API int contacts_svc_save_image(cts_img_t img_type, int index, char *src_img) return CTS_ERR_DB_FAILED; } - if(dest_img) + if(*dest_img) cts_stmt_bind_text(stmt, 1, dest_img); ret = cts_stmt_step(stmt); warn_if(CTS_SUCCESS != ret, "cts_stmt_step() Failed(%d)", ret); diff --git a/src/cts-utils.h b/src/cts-utils.h index 6350fc8..9842c22 100755 --- a/src/cts-utils.h +++ b/src/cts-utils.h @@ -47,8 +47,8 @@ int cts_increase_outgoing_count(int contact_id); int cts_get_next_ver(void); int cts_update_contact_changed_time(int contact_id); int cts_delete_image_file(int img_type, int index); -int cts_add_image_file(int img_type, int index, char *src_img, char **dest_img); -int cts_update_image_file(int img_type, int index, char *src_img, char **dest_img); +int cts_add_image_file(int img_type, int index, char *src_img, char *dest_name, int dest_size); +int cts_update_image_file(int img_type, int index, char *src_img, char *dest_name, int dest_size); #ifndef __CONTACTS_SVC_H__ //<!-- diff --git a/src/cts-vcard-file.c b/src/cts-vcard-file.c index cf8e6ce..516b974 100755 --- a/src/cts-vcard-file.c +++ b/src/cts-vcard-file.c @@ -60,7 +60,6 @@ enum { CTS_VCARD_VALUE_UID, CTS_VCARD_VALUE_URL, CTS_VCARD_VALUE_X_ANNIVERSARY, - CTS_VCARD_VALUE_X_IRMC_LUID, CTS_VCARD_VALUE_X_SLP_GROUP, CTS_VCARD_VALUE_END, CTS_VCARD_VALUE_MAX @@ -133,19 +132,24 @@ static int cts_vcard_check_content_type(char **vcard) } } -static inline int cts_vcard_check_quoted(char *src) +static inline int cts_vcard_check_quoted(char *src, int max, int *quoted) { int ret; + if (CTS_TRUE == *quoted) + return CTS_TRUE; - while (*src) { + while (*src && max) { if ('Q' == *src) { ret = strncmp(src, "QUOTED-PRINTABLE", sizeof("QUOTED-PRINTABLE") - 1); - if (!ret) + if (!ret) { + *quoted = CTS_TRUE; return CTS_TRUE; + } }else if (':' == *src) { break; } src++; + max--; } return CTS_FALSE; } @@ -160,12 +164,13 @@ static inline int cts_vcard_hex_to_dec(char hex) case 'A' ... 'F': return hex - 'A' + 10; default: - return 0; + return -1; } } static inline int cts_vcard_decode_quoted_val(char *val) { char *src, *dest; + int pre; src = strchr(val, ':'); if (NULL == src) @@ -174,12 +179,19 @@ static inline int cts_vcard_decode_quoted_val(char *val) dest = src; while (*src) { if ('=' == *src) { - *dest = (char)((cts_vcard_hex_to_dec(*(src+1)) << 4) + cts_vcard_hex_to_dec(*(src+2))); - if (*(src+1) && *(src+2)) + pre = cts_vcard_hex_to_dec(*(src+1)); + if (0 <= pre) { + *dest = (char)((pre << 4) + cts_vcard_hex_to_dec(*(src+2))); + dest++; src += 2; - }else + } else { + if ('\r' == *(src+1) && '\n' == *(src+2)) + src += 2; + } + } else { *dest = *src; - dest++; + dest++; + } src++; } @@ -259,9 +271,33 @@ static inline char* cts_vcard_translate_charset(char *src, int len) return NULL; } + +static inline int cts_vcard_remove_folding(char *folded_src) +{ + char *result = folded_src; + + retv_if(NULL == folded_src, CTS_ERR_ARG_NULL); + + while (*folded_src) { + if ('\r' == *folded_src && '\n' == *(folded_src+1) && ' ' == *(folded_src+2)) + folded_src += 3; + else if ('\n' == *folded_src && ' ' == *(folded_src+1)) + folded_src += 2; + + if ('\0' == *folded_src) + break; + + *result = *folded_src; + result++; + folded_src++; + } + *result = '\0'; + return CTS_SUCCESS; +} + static char* cts_vcard_get_val(int ver, char *src, char **dest) { - int len; + int len, quoted; bool start = false; char *cursor; @@ -284,17 +320,33 @@ static char* cts_vcard_get_val(int ver, char *src, char **dest) if (start) break; } + quoted = CTS_FALSE; cursor = src; len = 0; - while (*cursor) - { - if ('\r' == *cursor) cursor++; - if ('\n' == *cursor) { - if (' ' != *(cursor+1)) - break; + if(CTS_VCARD_VER_2_1 == ver) { + while (*cursor) { + if ('=' == *cursor && cts_vcard_check_quoted(src, cursor - src, "ed)) { + if ('\r' == *(cursor+1) && '\n' == *(cursor+2)) + cursor += 2; + } else { + if ('\r' == *cursor && '\n' == *(cursor+1) && ' ' != *(cursor+2)) + break; + if ('\n' == *cursor && ' ' != *(cursor+1)) + break; + } + + cursor++; } + } else { + while (*cursor) { + if ('\r' == *cursor && '\n' == *(cursor+1) && ' ' != *(cursor+2)) + break; + + if ('\n' == *cursor && ' ' != *(cursor+1)) + break; - cursor++; + cursor++; + } } if (src == cursor) { @@ -308,8 +360,10 @@ static char* cts_vcard_get_val(int ver, char *src, char **dest) *cursor = '\0'; *dest = strdup(src); - //if(CTS_VCARD_VER_2_1 == ver) - if (cts_vcard_check_quoted(*dest)) + if(CTS_VCARD_VER_2_1 != ver) + cts_vcard_remove_folding(*dest); + + if (cts_vcard_check_quoted(*dest, -1, "ed)) len = cts_vcard_decode_quoted_val(*dest); if (0 == len) len = strlen(*dest); @@ -349,29 +403,6 @@ static inline int cts_vcard_check_version(const char *src) return CTS_VCARD_VER_2_1; } -static inline int cts_vcard_remove_folding(char *folded_src) -{ - char *result = folded_src; - - retv_if(NULL == folded_src, CTS_ERR_ARG_NULL); - - while (*folded_src) { - if ('\r' == *folded_src) - folded_src++; - if ('\n' == *folded_src && ' ' == *(folded_src+1)) - folded_src += 2; - - if ('\0' == *folded_src) - break; - - *result = *folded_src; - result++; - folded_src++; - } - *result = '\0'; - return CTS_SUCCESS; -} - static inline char* cts_get_content_value(char *val) { @@ -1006,7 +1037,6 @@ static inline int cts_vcard_get_contact(int ver, int flags, cursor = new_start; continue; } - cts_vcard_remove_folding(val); switch (type) { case CTS_VCARD_VALUE_FN: @@ -1101,10 +1131,6 @@ static inline int cts_vcard_get_contact(int ver, int flags, CTS_EVENT_TYPE_ANNIVERSARY, val); free(val); break; - case CTS_VCARD_VALUE_X_IRMC_LUID: - contact->base->id = atoi(val); - free(val); - break; case CTS_VCARD_VALUE_X_SLP_GROUP: if (flags & CTS_VCARD_CONTENT_X_SLP_GROUP) contact->grouprelations = cts_vcard_get_group(contact->grouprelations, val); @@ -1160,7 +1186,6 @@ static void cts_vcard_initial(void) //content_name[CTS_VCARD_VALUE_KEY] = "KEY"; /* not supported */ content_name[CTS_VCARD_VALUE_X_ANNIVERSARY] = "X-ANNIVERSARY"; //content_name[CTS_VCARD_VALUE_X_CHILDREN] = "X-CHILDREN"; - content_name[CTS_VCARD_VALUE_X_IRMC_LUID] = "X-IRMC-LUID"; content_name[CTS_VCARD_VALUE_X_SLP_GROUP] = "X-SLP-GROUP"; content_name[CTS_VCARD_VALUE_END] = "END"; } diff --git a/src/cts-vcard.h b/src/cts-vcard.h index 1f73b42..82336fd 100755 --- a/src/cts-vcard.h +++ b/src/cts-vcard.h @@ -41,6 +41,16 @@ enum VCARDCONTENT { //<!-- /** + * @defgroup CONTACTS_SVC_VCARD vcard handling + * @ingroup CONTACTS_SVC + * @addtogroup CONTACTS_SVC_VCARD + * @{ + * + * This interface provides methods to handle the vcard. + * + */ + +/** * This function makes contact record by using vcard file stream. * * @param[in] vcard_stream start point of the stream of vcard. @@ -127,6 +137,9 @@ char* contacts_svc_vcard_put_content(const char *vcard_stream, int contacts_svc_vcard_get_content(const char *vcard_stream, const char *content_type, int (*fn)(const char *content_value, void *data), void *data); +/** + * @} + */ //--> #endif //__CTS_VCARD_H__ diff --git a/test/phonelog-test.c b/test/phonelog-test.c index 38a10f3..aeb49f1 100755 --- a/test/phonelog-test.c +++ b/test/phonelog-test.c @@ -148,9 +148,9 @@ void phonelog_get_number_list_test(void) { int ret; - ret = contats_svc_phonelog_get_all_number(plog_get_number_list_cb, NULL); + ret = contacts_svc_phonelog_get_all_number(plog_get_number_list_cb, NULL); if (CTS_SUCCESS != ret) - printf("contats_svc_phonelog_get_all_number() Failed(%d)\n", ret); + printf("contacts_svc_phonelog_get_all_number() Failed(%d)\n", ret); } diff --git a/test/vcard2contact-test.c b/test/vcard2contact-test.c index d3e9e4b..3339c8d 100755 --- a/test/vcard2contact-test.c +++ b/test/vcard2contact-test.c @@ -37,6 +37,7 @@ static void get_contact(CTSstruct *contact) contacts_svc_struct_get_value(contact, CTS_CF_BASE_INFO_VALUE, &value); printf("ID = %d\n", contacts_svc_value_get_int(value, CTS_BASE_VAL_ID_INT)); printf("changed time = %d\n", contacts_svc_value_get_int(value, CTS_BASE_VAL_CHANGED_TIME_INT)); + printf("note = %s\n", contacts_svc_value_get_str(value, CTS_BASE_VAL_NOTE_STR)); value = NULL; contacts_svc_struct_get_value(contact, CTS_CF_NAME_VALUE, &value); @@ -95,6 +96,8 @@ static void get_contact(CTSstruct *contact) printf("Pobox = %s\n", tmp_str); if ((tmp_str = contacts_svc_value_get_str(cursor->data, CTS_POSTAL_VAL_POSTALCODE_STR))) printf("POSTALCODE = %s\n", tmp_str); + if ((tmp_str = contacts_svc_value_get_str(cursor->data, CTS_POSTAL_VAL_REGION_STR))) + printf("REGION = %s\n", tmp_str); if ((tmp_str = contacts_svc_value_get_str(cursor->data, CTS_POSTAL_VAL_LOCALITY_STR))) printf("LOCALITY = %s\n", tmp_str); if ((tmp_str = contacts_svc_value_get_str(cursor->data, CTS_POSTAL_VAL_STREET_STR))) |