#include <glib.h>
-//#include <glib-oject.h>
+#include <pims-ipc-data.h>
+
#include "ctsvc_client_ipc.h"
#include "ctsvc_internal.h"
#include "ctsvc_ipc_define.h"
#include "ctsvc_ipc_marshal.h"
#include "ctsvc_view.h"
-#include <pims-ipc-data.h>
#include "ctsvc_mutex.h"
static __thread pims_ipc_h __contacts_ipc = NULL;
pims_ipc_data_h outdata = NULL;
// ipc create
- if (__contacts_ipc == NULL)
- {
+ if (__contacts_ipc == NULL) {
__contacts_ipc = pims_ipc_create(CTSVC_IPC_SOCKET_PATH);
- if (__contacts_ipc == NULL)
- {
+ if (__contacts_ipc == NULL) {
CTS_ERR("pims_ipc_create() Failed(%d)", CONTACTS_ERROR_IPC_NOT_AVALIABLE);
return CONTACTS_ERROR_IPC_NOT_AVALIABLE;
}
return ret;
}
-
-
int ctsvc_ipc_connect(void)
{
int ret = CONTACTS_ERROR_NONE;
pims_ipc_data_h outdata = NULL;
// ipc create
- if (__contacts_global_ipc == NULL)
- {
+ if (__contacts_global_ipc == NULL) {
__contacts_global_ipc = pims_ipc_create(CTSVC_IPC_SOCKET_PATH);
- if (__contacts_global_ipc == NULL)
- {
+ if (__contacts_global_ipc == NULL) {
CTS_ERR("[GLOBAL_IPC_CHANNEL] pims_ipc_create() Failed(%d)", CONTACTS_ERROR_IPC_NOT_AVALIABLE);
return CONTACTS_ERROR_IPC_NOT_AVALIABLE;
}
}
- else
- {
+ else {
CTS_DBG("[GLOBAL_IPC_CHANNEL] contacts already connected");
return CONTACTS_ERROR_NONE;
}
// ipc call
- if (pims_ipc_call(__contacts_global_ipc, CTSVC_IPC_MODULE, CTSVC_IPC_SERVER_CONNECT, indata, &outdata) != 0)
- {
+ if (pims_ipc_call(__contacts_global_ipc, CTSVC_IPC_MODULE, CTSVC_IPC_SERVER_CONNECT, indata, &outdata) != 0) {
CTS_ERR("[GLOBAL_IPC_CHANNEL] pims_ipc_call failed");
return CONTACTS_ERROR_IPC;
}
- if (outdata)
- {
+ if (outdata) {
// check outdata
unsigned int size = 0;
ret = *(int*) pims_ipc_data_get(outdata,&size);
-
pims_ipc_data_destroy(outdata);
if (ret == CONTACTS_ERROR_NONE)
CTSVC_VCARD_IMG_TIFF,
};
-static int __ctsvc_tmp_image_id = 0;
-static int __ctsvc_tmp_logo_id = 0;
-
static const char *content_name[CTSVC_VCARD_VALUE_MAX] = {0};
const char *CTSVC_CRLF = "\r\n";
type = __ctsvc_vcard_get_image_type(val);
ret = snprintf(dest, sizeof(dest), "%s/vcard-image-%d.%s",
- CTSVC_VCARD_IMAGE_LOCATION, __ctsvc_tmp_image_id++, __ctsvc_get_img_suffix(type));
+ CTSVC_VCARD_IMAGE_LOCATION, (int)time(NULL), __ctsvc_get_img_suffix(type));
RETVM_IF(ret<=0, CONTACTS_ERROR_INTERNAL, "Destination file name was not created");
fd = open(dest, O_WRONLY|O_CREAT|O_TRUNC, 0660);
contacts_record_set_int(company, _contacts_company.type, type);
}
+static contacts_record_h __ctsvc_vcard_get_company_empty_record(ctsvc_list_s *company_list, int property_id)
+{
+ contacts_record_h record_temp = NULL;
+ contacts_record_h record = NULL;
+ contacts_list_h list = (contacts_list_h)company_list;
+
+ contacts_list_last(list);
+ while (CONTACTS_ERROR_NONE == contacts_list_get_current_record_p(list, &record_temp)) {
+ char *value = NULL;
+ contacts_record_get_str_p(record_temp, property_id, &value);
+ if (NULL == value) {
+ record = record_temp;
+ break;
+ }
+ contacts_list_prev(list);
+ }
+
+ return record_temp;
+}
+
static inline int __ctsvc_vcard_get_company_value(ctsvc_list_s *company_list, int property_id, char *val)
{
- unsigned int count;
char *value;
contacts_record_h company;
- contacts_list_get_count((contacts_list_h)company_list, &count);
- RETVM_IF(count == 0, CONTACTS_ERROR_INVALID_PARAMETER, "list is empty");
-
- contacts_list_last((contacts_list_h)company_list);
- contacts_list_get_current_record_p((contacts_list_h)company_list, &company);
- RETVM_IF(NULL == company, CONTACTS_ERROR_INVALID_PARAMETER, "contacts_list_get_current_record_p() return NULL");
+ company = __ctsvc_vcard_get_company_empty_record(company_list, property_id);
+ if (NULL == company) {
+ int ret = contacts_record_create(_contacts_company._uri, &company);
+ RETVM_IF(ret < CONTACTS_ERROR_NONE, ret, "contacts_record_create is failed(%d)", ret);
+ contacts_list_add((contacts_list_h)company_list, company);
+ }
value = __ctsvc_get_content_value(val);
RETV_IF(NULL == value, CONTACTS_ERROR_NO_DATA);
return CONTACTS_ERROR_NONE;
}
-
static inline int __ctsvc_vcard_get_company(ctsvc_list_s *company_list, char *val)
{
- int ret;
- char *temp, *start;
+ char *temp, *start, *depart;
const char separator = ';';
contacts_record_h company;
- ret = contacts_record_create(_contacts_company._uri, &company);
- RETVM_IF(ret < CONTACTS_ERROR_NONE, ret, "contacts_record_create is failed(%d)", ret);
- contacts_list_add((contacts_list_h)company_list, company);
+ company = __ctsvc_vcard_get_company_empty_record(company_list, _contacts_company.name);
+ if (NULL == company) {
+ int ret = contacts_record_create(_contacts_company._uri, &company);
+ RETVM_IF(ret < CONTACTS_ERROR_NONE, ret, "contacts_record_create is failed(%d)", ret);
+ contacts_list_add((contacts_list_h)company_list, company);
+ }
start = __ctsvc_get_content_value(val);
RETV_IF(NULL == start, CONTACTS_ERROR_NO_DATA);
- temp = __ctsvc_strtok(start, separator);
+ depart = __ctsvc_strtok(start, separator);
contacts_record_set_str(company, _contacts_company.name, __ctsvc_vcard_remove_escape_char(start));
- temp = __ctsvc_strtok(temp, separator);
- if (temp)
- contacts_record_set_str(company, _contacts_company.department, __ctsvc_vcard_remove_escape_char(temp));
+ temp = __ctsvc_strtok(depart, separator);
+ if (depart)
+ contacts_record_set_str(company, _contacts_company.department, __ctsvc_vcard_remove_escape_char(depart));
if (val != temp) {
*(temp-1) = '\0';
static inline int __ctsvc_vcard_get_company_logo(ctsvc_list_s *company_list, char *val)
{
int ret, type, fd;
- unsigned int count;
gsize size;
guchar *buf;
char dest[CTSVC_IMG_FULL_PATH_SIZE_MAX] = {0};
char *temp;
contacts_record_h company;
- contacts_list_get_count((contacts_list_h)company_list, &count);
- RETVM_IF(count == 0, CONTACTS_ERROR_INVALID_PARAMETER, "list is empty");
-
- contacts_list_last((contacts_list_h)company_list);
- contacts_list_get_current_record_p((contacts_list_h)company_list, &company);
- RETVM_IF(NULL == company, CONTACTS_ERROR_INVALID_PARAMETER, "contacts_list_get_current_record_p() return NULL");
+ company = __ctsvc_vcard_get_company_empty_record(company_list, _contacts_company.logo);
+ if (NULL == company) {
+ ret = contacts_record_create(_contacts_company._uri, &company);
+ RETVM_IF(ret < CONTACTS_ERROR_NONE, ret, "contacts_record_create is failed(%d)", ret);
+ contacts_list_add((contacts_list_h)company_list, company);
+ }
temp = strchr(val , ':');
RETVM_IF(NULL == temp, CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : val is invalid(%s)", val);
type = __ctsvc_vcard_get_image_type(val);
ret = snprintf(dest, sizeof(dest), "%s/%d-%d-logo.%s", CTSVC_VCARD_IMAGE_LOCATION,
- getpid(), __ctsvc_tmp_logo_id++, __ctsvc_get_img_suffix(type));
+ getpid(), (int)time(NULL), __ctsvc_get_img_suffix(type));
RETVM_IF(ret<=0, CONTACTS_ERROR_SYSTEM, "Destination file name was not created");
fd = open(dest, O_WRONLY|O_CREAT|O_TRUNC, 0660);